How to Install httpd (apache) + Remi PHP and SSL on centos

In the global internet, there are several user tutorials on How to Install Apache2 and also PHP, but not all tutorial writers are using a specific PHP that is developed by at the moment RedHat employee Remi. In our experience, we find that Remi PHP is much better with stability and performance.

So we are creating a tutorial that is with REMI PHP, also this will not be only a tutorial but in the end, you will find another option our created shell script that is hosted on our public git that you can download or clone on to your server and by running it will automatically install on your server Apache2, Remi PHP,

Certbot (that will automatically install Let's Encrypt certificate) and newly created vhost (Virtual Host) so basically when you will run this shell script you will have a webserver ready to go.

For manual installation:

Now with the command below, we will install
httpd web server (Known as apache);
Enable SSL support;
And install Let's encrypt cert bot;
Enable HTTPD to start on boot and start it for 1 time;

yum -y install httpd certbot python2-certbot-apache mod_ssl ; systemctl start httpd ; systemctl enable httpd

After the above is installed, now we need to Enable and Install PHP ( Remi offers several PHP versions PHP 5.6, PHP 7.0, PHP 7.1, PHP 7.2, PHP 7.3 and at the moment latest PHP 7.4. So in this how-to, we will be installing the latest versions.

yum install epel-release -y ; yum install -y ; yum install yum-utils -y ; yum-config-manager --enable remi-php74 -y ;

With the above command, we have installed all needed for PHP installation and also enabled Remi PHP 7.4. Now let's install PHP

yum -y install php php-pecl-zip php-devel php-gd php-snmp php-xmlrpc php-xml php74-php-gd php$pvers-php-json php74-php-mbstring php74-mbstring php74-bcmath php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache php-mysql php-soap

Now, that we have installed PHP I personally like it when the website has its own vhost configuration file, you can multiple these vhost files for several websites on the same Linux machine.

Let's create needed folders

 mkdir /var/www/site1 ; mkdir /etc/httd/vhosts ; 

Now when we have folders we can create simple vhost configuration, Just replace with your domain name. And paste all this in your terminal.

echo "<VirtualHost *:80>
    DocumentRoot /var/www/
    RewriteEngine On
    DirectoryIndex index.html index.php
    ErrorLog /var/log/httpd/www.amberit.org_apache_error.log
    CustomLog /var/log/httpd/www.amberit.org_apache_access.log combined
<Directory "/var/www/">
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</VirtualHost>" > /etc/httpd/vhosts/ ;

Now let's allow HTTPD (Apache) to read vhosts file

echo "IncludeOptional vhosts/*.conf" >> /etc/httpd/conf/httpd.conf

Now, let's sign our website with Let's encrypt free SSL

certbot --apache -d --non-interactive --agree-tos -m

And we are done, now we have a website, that supports PHP and also is signed with a free SSL certificate.

Amber IT VPS hosting is a perfect solution for your project hosting, by using our VPS Hosting, you can host from simple WordPress websites to Internet shops or other small, medium and large websites/systems.

All this what we installed above can be done with a simple script, Click here to learn How to automatically install a web server with PHP and secure it with Let's encrypt by only typing one command. (DevOps automation)