Apache Install and Running PHP 5.6 / PHP 7.2 on the Centos 7 x64

Apache Install and Running PHP 5.6 / PHP 7.2 on the Centos 7 x64

In this tutorial we will set up multiple PHP Versions which is 5.6 & 7.2 on the Apache same machine.

it’s very practical and common to have multiple php versions and run it simultaneously with apache on a single server. Maybe you have a php script and want to test it with multiple php version. in such case this article is for you.

 

1- Install prerequisites

before installing and running two php versions, we need to install apache and some repository. so execute these commands:

yum install httpd
yum install epel-release
yum install yum-utils

2- Install multiple php versions

php-fpm is available in remi repository. so we install this repo and then after multiple php versions:

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install php56 
yum install php72
yum install php56-php-fpm
yum install php72-php-fpm

3- Configure SELinux

Install Selinux Policy Targeted

yum install selinux-policy-targeted

to allow selinux run php-fpms scripts, run these commands:

semanage port -a -t http_port_t -p tcp 9072
semanage port -a -t http_port_t -p tcp 9056

4- Configure php-fpm

by default, each php-fpm version is listening on port 9000. because we want to run multiple php versions, we need to change default port:

sed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf
sed -i 's/:9000/:9072/' /etc/opt/remi/php72/php-fpm.d/www.conf

Start the php-fpm

systemctl start php72-php-fpm
systemctl start php56-php-fpm

now we need to make script wrapper to call php56-cgi and php72-cgi:

cat > /var/www/cgi-bin/php56.fcgi << EOF
#!/bin/bash
exec /bin/php56-cgi
EOF

cat > /var/www/cgi-bin/php72.fcgi << EOF
#!/bin/bash
exec /bin/php72-cgi
EOF

Then we set executable bit on both scripts:

sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php72.fcgi

5- Configure apache

Here we create two path. one for php-fpm56 and another for php-fpm72. you can change these paths with your own:

Php7.2 /var/www/html

Php5.6 /var/www/html56

Edit conf file /etc/httpd/conf.d/php.conf

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler php56-fcgi .php
Action php56-fcgi /cgi-bin/php56.fcgi
Action php72-fcgi /cgi-bin/php72.fcgi

<Directory /var/www/html56>
  DirectoryIndex index.php
  AllowOverride all
  Require all granted
  AddHandler php56-fcgi .php
  Action php56-fcgi /cgi-bin/php56.fcgi
</Directory>
<Directory /var/www/html>
  DirectoryIndex index.php
  AllowOverride all
  Require all granted
  AddHandler php72-fcgi .php
  Action php56-fcgi /cgi-bin/php72.fcgi
</Directory>
#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>
</Files>

#
# Allow php to handle Multiviews
#
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
##DirectoryIndex index.php

<FilesMatch \.php



























gt;
SetHandler "proxy:fcgi://127.0.0.1:9072"
</FilesMatch>
# Some legacy application use PHP 5.5
<Directory /var/www/html56>
<FilesMatch \.php

gt;
SetHandler "proxy:fcgi://127.0.0.1:9056"
</FilesMatch>
</Directory>

6- Start services

Now we enable and start apache and php-fpm services:

systemctl enable httpd
systemctl enable php56-php-fpm
systemctl enable php72-php-fpm

systemctl start httpd
systemctl start php56-php-fpm
systemctl start php72-php-fpm

7- Check for result

 

Good luck! All Done

Centos7 Monit configure to monitor disk space usage detail report

Centos7 Monit configure to monitor disk space usage detail report

These steps will guide how to add Disk Storage monitor report into the Monit web access

First, you need to know which drive you want to be included into the Monit  report by following command

df

 

For example here I have one partition /dev/vda1 and I want to monitor it with the usage detail.

Update the Monit configuration file

Now open the monit config file by the path: /etc/monit.d/storagespace 

Create that file if it is not existed. Paste the following content

check filesystem Ubuntu with path /dev/vda1
    if space usage > 90% then alert

If you have multiple volumes, easy that clone those 2 lines in multiple breakdown. Note that Ubuntu is the optional name you want to be showed as alias name in report.

Done, save it.

Check and Restart Monit process

Check the configuration file is ok by command

sudo monit -t

It will output *Control file syntax OK* means fine, otherwise try to review again your config file.

Restart monit service

systemctl restart monit

Check for status of service

systemctl status monit

 

So everything is fine, now point to web browser to access monit report, by default port is 2812 and your url will look like http://<host>:2812

 

The monit monitoring my disk right now, so click on it will go to details

 

Finished!