Linux Tutorials

How to run multiple version PHP with Apache (use Sentora panel) on Centos

Pinterest LinkedIn Tumblr

In cPanel you can swith to anther PHP version easily but in Sentora or any free panel web management, they doesn’t support this feature. You’ll must install every PHP version by your demand and config them manually . In this tutorial I will instruct you how to run a website with a specific PHP version beside default PHP version.

You can use this tutorial with LAMP (Linux Apache MySQL PHP) or use with Sentora panel on Centos, RedHat Enterprise Linux.

1. Install Sentora. Default PHP versiokn on Sentora is 5.4

# bash <(curl -L -Ss http://sentora.org/install)

2. Install php-fpm

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

To run another PHP version you need install PHP FPM for that version.  Apache httpd to delegate PHP scripts execution to a backend using the FastCGI protocol. php-fpm package is available in the optional channel, to launch PHP FPM when reboot, you’ll need enable service PHP FPM

# systemctl enable php56-php-fpm
# systemctl enable php72-php-fpm

then make sure both versions are stopped:

# systemctl stop php56-php-fpm
# systemctl stop php72-php-fpm

3 . Configure for PHP FPM run on different port

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. We will run 5.6 version on port 9056 and 7.2 version on 9072

# semanage port -a -t http_port_t -p tcp 9072
# semanage port -a -t http_port_t -p tcp 9056
# 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

4. Config php multiple version by web folder

# nano /etc/httpd/conf.d/php.conf

In php.conf we modify it as follows:

<Files ".user.ini">
    Require all denied
  </Files>


<FilesMatch \.php$>
    #SetHandler application/x-httpd-php
    SetHandler "proxy:fcgi://127.0.0.1:9056"
</FilesMatch>


<Directory /var/sentora/hostdata/zadmin/public_html/your_website_folder>
    <FilesMatch \.php$>
      SetHandler "proxy:fcgi://127.0.0.1:9072"
    </FilesMatch>
</Directory>

We use 5.6 version for all websites (default is 5.4) and all PHP scripts in folder your_website_folder will run with 7.2 version.

5. Start PHP FPM

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

# service httpd restart

For testing PHP version you can put a file with content like this in your website folder:

<?php phpinfo();?>

Tips: On PHP 7.2 you’ll need install PHP MySQLlnd for using MySQL

# yum install php72-php-mysqlnd

I'm a full stack developer. I have experiences with Java, Android, PHP, Python, C#, Web development...I hope website https://learncode24h.com will help everyone can learn code within 24h and apply it in working easily.

Write A Comment