I had the PHP, MySQL, and Apache stack installed for development. That installation is using configuration files from:
/etc/apache2/
/etc/php5/
Later I installed multiple PHP version using phpbrew. All versions are accessible and switchable from CLI. But Apache always stays on the default version that was not installed using phpbrew.
Here is a list of my installed PHP versions.
$ phpbrew list
Installed versions:
php-5.4.13 (/home/admin1/.phpbrew/php/php-5.4.13)
+default -- --with-bz2=/usr
php-5.5.5 (/home/admin1/.phpbrew/php/php-5.5.5)
php-5.3.27 (/home/admin1/.phpbrew/php/php-5.3.27)
I have tried changing configuration file paths so they point to phpbrew's PHP. But nothing seems to be working.
How can I tell Apache to use phpbrew's PHP version?
You need to build a PHP with apxs2:
1) Ensure your have installed sudo apt-get install apache2-dev.
2) Run phpbrew install 5.4.22 +apxs2=/usr/bin/apxs2
Then you should see the built module file in your Apache configuration file.
I scripted this, because it was annoying me.
By default phpbrew switch will change the CLI version. To update Apache, you will have to tell it to use the newly generated .so file. On Ubuntu this file will be created like /usr/lib/apache2/modules/libphp$VERSION.so.
For this .so file to be generated, you have to install PHP like:
phpbrew install php-5.6.16 +default +apxs2
Anyway, here's the shell script I use to switch PHP versions. The switch will fail if the .so file cannot be found, and it will request sudo privileges to restart Apache.
/home/luker/bin/phpbrewswitch
#!/usr/bin/env bash
VERSION=$1
SOFILE=/usr/lib/apache2/modules/libphp$VERSION.so
CONFFILE5=/etc/apache2/mods-available/php5.load
CONFFILE7=/etc/apache2/mods-available/php7.load
source ~/.phpbrew/bashrc
if [ -f $SOFILE ]; then
phpbrew switch $VERSION
phpbrew list
if [[ $VERSION == 7* ]]; then
FILECONTENTS="LoadModule php7_module $SOFILE"
CONFFILE=$CONFFILE7
sudo a2enmod php7
sudo a2dismod php5
else
FILECONTENTS="LoadModule php5_module $SOFILE"
CONFFILE=$CONFFILE5
sudo a2enmod php5
sudo a2dismod php7
fi;
echo $FILECONTENTS > $CONFFILE
echo "AddType application/x-httpd-php .php" >> $CONFFILE
echo "Updated $CONFFILE"
sudo service apache2 restart
else
echo $VERSION "is not configured for apache"
phpbrew list
fi
Usage
Attempting to switch to a PHP version that wasn't built for Apache:
[21:02:55] luker [~]$ phpbrewswitch 5.4.45
5.4.45 is not configured for apache
php-5.6.16
php-5.6.10
* php-5.5.30
php-5.4.45
Successfully changing to a PHP version that has an existing .so file:
[21:03:55] luker [~]$ phpbrewswitch 5.6.16
* php-5.6.16
php-5.6.10
php-5.5.30
php-5.4.45
Updated /etc/apache2/mods-available/php5.load
Do look into Server Fault post How do I tell Apache which PHP to use?.
You need to specify the PHP version in Apache.
The solution I found for managing multiple PHP versions with an Apache server is to run PHP-FPM and FastCGI instead of mod_php. This way I can have multiple versions of PHP running, and select which sites on my development machine I want to run which version of PHP.
You will need to recompile your PHP versions with the +fpm phpbrew flag instead of +apxs2, start them with the phpbrew fpm start command, install the Apache libapache2-mod-fastcgi package, and probably disable apache mod_php - but it's pretty slick once it's working. I can test the same site with multiple versions of PHP just by configuring a different Virtual host pointing to the same code, but different PHP-FPM sockets.
Here's an example of an Apache 2.4 /etc/apache2/mods-enables/fastcgi.conf configuration file with 2 versions of PHP installed via phpbrew:
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
FastCgiIpcDir /var/lib/apache2/fastcgi
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5-fcgi
# This is for php 5.6.28
FastCgiExternalServer /usr/lib/cgi-bin/php56-cgi -socket /home/{USERNAME}/.phpbrew/php/php-5.6.28/var/run/php-fpm.sock -pass-header Authorization
# This is for php 7.0.13
FastCgiExternalServer /usr/lib/cgi-bin/php70-cgi -socket /home/{USERNAME}/.phpbrew/php/php-7.0.13/var/run/php-fpm.sock -pass-header Authorization
# this seems to be required by Apache 2.4.10
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
Then in your apache "site" Virtualhost configuration you can specify which PHP version to run with an Alias like so:
<VirtualHost *:80>
# ServerName, ServerAdmin, etc
DocumentRoot /var/www/my-site-code
# Then point the php5-fcgi handler to a specific version of PHP
# Here is PHP7, as defined in the fastcgi.conf file
Alias /php5-fcgi /usr/lib/cgi-bin/php70-cgi
</VirtualHost>
If phpbrew successfully installs php version with +apxs2 ext, you should have a new ".so" file it inside apache2's module library (usr/lib/apache2/modules, which is seen in /etc/apache2/mods-available/php*.load).
The .so file listed in those php*.load (either php5.load or php7.load) files is the version that gets loaded. To switch between a php5 and php7 version use a2enmod/a2dismod php5 php7.
You need to reload apache2 after changing the config : systemctl restart apache2. If php files are rendering as plain text, you need to either add this to the php*.load file:
AddType application/x-httpd-php .php
OR to avoid having to edit the php load files everytime you install a new version, you can set this globally in your apache2 config file:
<FilesMatch \.php?>
SetHandler application/x-httpd-php
</FilesMatch>
These instructions are intended for a development server. My personal script for this:
#!/bin/bash
i=1
c=1
options=()
while [ $c -gt 0 ]
do
v=$(phpbrew list | sed -n "${i}p")
if [ -z "$v" ]; then
c=0
elif [ -n "$v" ]; then
options+=("$v")
fi
i=$[$i+1]
done
count=0
printf "\n"
echo 'Available versions:'
for i in "${options[#]}"
do
echo "$i $[$count+1]"
count=$[$count+1]
done
printf "\n"
echo 'Which version should be enabled?'
read selected
chosen="${options[$selected - 1]}"
chosen="$(echo -e "${chosen}" | tr -d '[:space:]')"
chosen="$(echo -e "${chosen}" | sed 's/\*//g')"
chosen="$(echo -e "${chosen}" | sed 's/php-//g')"
echo -e "php-${chosen} to be enabled."
source $HOME/.phpbrew/bashrc
phpbrew switch php-${chosen}
if [[ $chosen =~ ^5 ]]; then
sudo a2dismod php7
sudo a2enmod php5
sudo service apache2 reload
elif [[ $chosen =~ ^7 ]]; then
sudo a2dismod php5
sudo a2enmod php7
sudo service apache2 reload
else echo 'This script only works on php 5 and 7';
fi
The script runs phpbrew list on your behalf and let's you select the version using number keys. It then runs phpbrew switch and also switches the apache2 modules on or off and restarts the server.
Related
On my mac I've got php installed and working fine. I recently wanted to install mcrypt, so I did so using brew. Although it seemed to install fine, it doesn't show up in my phpinfo(). So I think that the php that brew installed mcrypt in, isn't the php that apache uses.
Does anybody know how I can:
check whether there is a difference between the php installed by brew and the php which Apache uses?
make apache use the php that brew installed?
All tips are welcome!
According to the contributors of the Homebrew php formula...
The contributors of the Homebrew php formula give the following instructions. The exact instructions reproduced here install php7.4. Substitute the php version you need.
(Avoid "special" ways of accomplishing your objective; they are often problematic. "Official" approaches are more likely to give you a predictable, maintainable setup.)
$ brew search php // since php can be installed by homebrew but be missing from your PATH, review the list of php versions available through homebrew; a checkmark next to a version indicates one is installed
$ brew install php#7.4
$ echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc // add the alias to your path (issues you are using zsh, the default now for macOS); see comments output during installation
$ source ~/.zshrc // reload . zshrc to use the new settings immediately
The contributors of the formula also provide the following instructions for enabling PHP in Apache:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>`
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.4/
These instructions for enabling PHP in Apache appear in stdout when you install php. Alternatively in Terminal use brew info php or visit the Homebrew PHP formula page
You have to make your Apache use the PHP that you just downloaded.
Open your httpd.conf (mine is at /etc/apache2/httpd.conf) and look for the line that loads the PHP module, something like:
LoadModule php5_module path/to/php
Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.
/usr/local/Cellar/php54/5.4.21/libexec/apache2/libphp5.so
Finally you will need to restart your Apache server to load the new configuration:
sudo apachectl restart
Can't comment on stackoverflow yet due to my lack of experience but to add to the above answer is correct. Just an additional comment to find the correct path:
run:
brew info php54
or which ever version u have installed and it will show you the path:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so
brew install php installs php 7.3 at the moment, versions below are keg-only
You can make aliases for versions below by adding this to:
~/.profile
alias php#5.6='$(brew --prefix php#5.6)/bin/php'
alias php#7.0='$(brew --prefix php#7.0)/bin/php'
alias php#7.1='$(brew --prefix php#7.1)/bin/php'
alias php#7.2='$(brew --prefix php#7.2)/bin/php'
~/.bashrc
source ~/.profile
~/.zshrc
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
Then you can:
php#5.6 -v
php#7.0 -v
php#7.1 -v
php#7.2 -v
If you use composer and the platform php is not set in your project then this can be handy:
~/.profile
alias composer#5.6='php#5.6 $(which composer)'
alias composer#7.0='php#7.0 $(which composer)'
alias composer#7.1='php#7.1 $(which composer)'
alias composer#7.2='php#7.2 $(which composer)'
If you use artisan a lot (artisan maps to php which is 7.3) then this can be handy:
~/.profile
alias artisan#5.6='php#5.6 artisan'
alias artisan#7.0='php#7.0 artisan'
alias artisan#7.1='php#7.1 artisan'
alias artisan#7.2='php#7.2 artisan'
I would create an alias to it so you don't disturb the system PHP install.
brew info php71
Brew installs into /usr/local/Cellar so you can add the following to your ~/.bash_alias or ~/.profile.
alias php7='/usr/local/Cellar/php71/7.1.10_21/bin/php'
Try: brew link php71 --force to use brew specific php version.
It worked for me.
As of 2021, all you need is
brew install php
then
brew link php
This will give you php 8.0 and setup your symlinks.
when I run the command php -v
I have version 8.0
I would like to change the version to 7.4
despite I have installed php7.4
but I don't know how to switch between the two versions
thank you
Let's assume that the location of php7.4 is /usr/bin/php7.4, in which case
/usr/bin/php7.4 -v
will yield something like this:
hence, you can use this method for whatever command that you would like to execute:
/usr/bin/php7.4 <yourcommand>
You can disable PHP 8 via
sudo a2dismod php8.0
if it bothers you. You can do so temporarily as well.
As your question is about the Arch Linux and it doesn't have the a2enmod & a2dismod. I am gonna providing working answer in the arch:
I assume you have installed php7 & php8 and just want to make apache to use the version 7.
first uninstall apache-php module and install the right one.
sudo pacman -R php-apache
sudo pacman -S php7-apache
then in the /etc/httpd/conf/httpd.conf change the module name:
from :
LoadModule php_module modules/libphp.so
Include conf/extra/php_module.conf
AddHandler php-script php
to:
LoadModule php7_module modules/libphp7.so
Include conf/extra/php7_module.conf
AddHandler php7-script php
after that you can reload the server:
sudo systemctl reload httpd
Can anyone here instruct me way to install and configure Multi PhP with one apache instance on CentOS 7, and the proper way to test it..
install all the necessary repos and packages
big thanks to https://rpms.remirepo.net/wizard/
the following commands assume you already sudo su - or you will have to add sudo to each of the commands:
yum install httpd -y
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils -y
yum install php56 -y
yum install php72 -y
yum install php56-php-fpm -y
yum install php72-php-fpm -y
stop both fpm servers
systemctl stop php56-php-fpm
systemctl stop php72-php-fpm
by default it listens on 127.0.0.1 port 9000, make them listen on different ports
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
now two different version of fpm can be started on different ports
systemctl start php72-php-fpm
systemctl start php56-php-fpm
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
make them executable by apache
sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php72.fcgi
create php configuration for apache. by default it runs php56-fcgi handler
cat > /etc/httpd/conf.d/php.conf << EOF
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/html/php56>
DirectoryIndex index.php
AllowOverride all
Require all granted
</Directory>
<Directory /var/www/html/php72>
DirectoryIndex index.php
AllowOverride all
Require all granted
</Directory>
EOF
make test pages, create .htaccess to use php72-fcgi
mkdir -p /var/www/html/php56
mkdir -p /var/www/html/php72
echo "<?php phpinfo(); ?>" > /var/www/html/php56/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php72/index.php
echo "AddHandler php72-fcgi .php" > /var/www/html/php72/.htaccess
Now you should be able to test it
(http://127.0.0.1/php56)
(http://127.0.0.1/php72)
If you want to startup these instance automatically after server reboot
sudo systemctl enable httpd
sudo systemctl enable php56-php-fpm
sudo systemctl enable php72-php-fpm
As explained by #runwuf, this is possible using the sofware collections available in centos-scl repository or in remi repository.
But using SetHandler to fastcgi proxy seems a better and more modern way, thanks to httpd 2.4:
SetHandler "proxy:fcgi://127.0.0.1:9000"
This is explained in some blog posts:
My PHP Workstation on Remi's blog
PHP Configuration Tips on RH developpers' blog
I had to add the following to my php.conf inside the directory statement to make the Apache Server API change to FPM/FastCGI instead of CGI/FastCGI - your solution was almost perfect though! Now if I could just figure out how to make it use a socket instead of TCP, I'd be one happy coder.
# mod_proxy_fcgi options
<IfModule mod_proxy_fcgi.c>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9072"
</FilesMatch>
</IfModule>
It looks like what you are trying to do is similar to this:
running-two-php-versions-on-the-same-server
I personally would not want to attempt two php version on the same apache instance... I would install different version of php by tarball and run them on separate instance of apache that is also installed by tarball and point each httpd.conf to the different version of php.
replying to runwuf
Hello,
there is one problem with your approach regarding SELinux
either you disable SELinux (if you are not concerned with security) or you manage the SELinux Port Policy
In case you don't handle the SELinux, the php56-php-fpm won't start if SELinux is set to 'Enforcing' mode
Run the following commands for making SELinux allow the ports
semanage port -a -t http_port_t -p tcp 9072
semanage port -a -t http_port_t -p tcp 9056
and then finally try to start the fpm modules
I wandered here looking for a solution. CentOS now has a PHP Select which let's you run different version of PHP on the server.
More information can be found here: http://forum.centos-webpanel.com/php/php-selector/
right now I'm installing or new apache2 webserver with PHP-FPM, because the old one is running with mod_php.
I found different Tutorials at the internet, unlikely most of them 1-2 years old. Most of them use:
libapache2-mod-fastcgi in combination with Apache and PHP-FPM.
At the Ubuntu 18.04 Repository this package is not available, just the package:
libapache2-mod-fcgid
Which of them can I use now ? Or what is the difference between both of them ? Unfortunately I cant really find a good explanation at the internet.
Furthermore I often read about
mod_proxy_fcgi
does that mean I dont need the libaapche2-mod-f... packages anymore ? ?
Right now I installed everything like this and it works, but I'm not sure If this is the right way:
a2enmod actions fastcgi alias proxy_fcgi
apt install php-7.2 php7.2-fpm php7.2-gd php7.2-mysql php7.2-curl php7.2-xml php7.2-zip php7.2-intl php7.2-mbstring php7.2-bz2 php7.2-json php7.2-apcu php7.2-imagick
a2enmod actions fastcgi alias proxy_fcgi
vHost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.2-fpm.sock|fcgi://localhost/"
</FilesMatch>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
PHP-FPM is running (see picture of info.php):
PHP-FPM Working
And what is the difference between:
SetHandler and FastCgiExternalServer and ProxyPassMatch ^/(..php(/.)?)$ fcgi://127.0.0.1:9000/path/to/your/documentroot/$1
?
I've got the feeling, that every tutorial is telling me something different and I cant really figure out what the best practice is in 2018 with Ubuntu2018.
I know this is an old question but I wanted to give an updated response.
As of the release of php5.3.3 (in 2010) a lot has changed.
Some great info can be found on the Apache HTTP Server Wiki
The short answer (Note: replace php7.2 with the version you have installed) as to how to install only PHP-FPM on an Ubuntu apache2 server is:
# Install php-fpm:
apt install php-fpm
# Disable mod_php (Apache Handler API):
a2dismod php*
# Enable Apache Modules/Configs required by fpm:
a2enmod proxy_fcgi setenvif
a2enconf php7.2-fpm.conf
# Restart the services:
systemctl restart php7.2-fpm.service systemctl restart apache2.service
You are also going to need to change from using Pre-fork as your Multi-Processing Module (MPM) if you are going to run PHP-FPM. Here are some instructions.
Detailed Explanation:
There are basically 3 different Server API's that can be installed with PHP: Apache Handler, FPM, or CGI.
Looking at the different config files can help to understand what you may have installed on your system.
Currently on Ubuntu 18.x with php7.x the following php.ini files get created depending on what you have installed:
/etc/php/7.2/cli/php.ini
This is the PHP-CLI program for running php on the command line.
This is included whenever you install FPM, CGI, or the Apache Handler.
You could install it directly with:
apt install php-cli
To find all the config files being used for PHP-CLI you can run:
php --ini
/etc/php/7.2/apache2/php.ini
This is the PHP plugin used by Apache. It will be found in /etc/apache2/mods-available/php7.2
If you have not installed PHP-FPM or PHP-CGI then this is the file that contains your webserver settings.
To find all the config files you need to create a phpinfo() file in the website root directory.
To install you must also enable mod_php from within Apache.
apt install libapache2-mod-php
a2enmod php7.2
/etc/php/7.2/fpm/php.ini
This is the FastCGI Process Manager. It is a wrapper for PHP processing and runs as a standalone process on the system (unlike the Apache PHP plugin).
You will only have this directory if you have installed PHP-FPM.
In this case it will be the place to make config changes for your webserver and takes the place of the apache2/php.ini file.
To find all the config files you need to create a phpinfo() file in the website root directory.
Running PHP as a fastCGI process server with PHP-FPM requires using the apache module mods-enabled/mod_proxy_fcgi it is enabled along with php-fpm.
Installing php-fpm will also configure apache with with conf-enabled/php7.2-fpm.conf that sets up FPM to run as a unix domain socket.
apt install php-fpm
a2enmod mod_proxy_fcgi
/etc/php/7.2/cgi/php.ini
This is a third way PHP could be installed. It is the legacy way of running PHP based applications as opposed to the newer PHP-FPM.
mod_fcgid is a high performance alternative to mod_cgi or mod_cgid
It would also be taking the place of the php.ini in either the Apache Plugin or PHP-FPM.
To find all the config files you need to create a phpinfo() file in the website root directory.
Again, it comes with it's own apache module and configuration: mods-enabled/fcgid.conf mods-enabled/fcgid
apt install libapache2-mod-fcgid
a2enmod fcgid
Here's my vhost for Apache connecting to FPM using mod_proxy_fcgi (apparently the recommended setup, although don't ask me for specifics!):
<VirtualHost *:80>
ServerName awesome.scot
ServerAlias localhost
DocumentRoot /var/www/html/public
<Directory "/var/www/html">
DirectoryIndex index.php
FallbackResource /index.php
Options -Indexes +FollowSymLinks
AllowOverride FileInfo All
Require all granted
</Directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://php:9000/var/www/html/public/$1
</VirtualHost>
in the conf, I also have these on:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
If you use XDebug, you'll need to change it's port to 9001 since 9000 is now taken.
If you need to see more config, check out my Docker LAMP stack config here https://github.com/delboy1978uk/lamp
Can anyone here instruct me way to install and configure Multi PhP with one apache instance on CentOS 7, and the proper way to test it..
install all the necessary repos and packages
big thanks to https://rpms.remirepo.net/wizard/
the following commands assume you already sudo su - or you will have to add sudo to each of the commands:
yum install httpd -y
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils -y
yum install php56 -y
yum install php72 -y
yum install php56-php-fpm -y
yum install php72-php-fpm -y
stop both fpm servers
systemctl stop php56-php-fpm
systemctl stop php72-php-fpm
by default it listens on 127.0.0.1 port 9000, make them listen on different ports
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
now two different version of fpm can be started on different ports
systemctl start php72-php-fpm
systemctl start php56-php-fpm
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
make them executable by apache
sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php72.fcgi
create php configuration for apache. by default it runs php56-fcgi handler
cat > /etc/httpd/conf.d/php.conf << EOF
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/html/php56>
DirectoryIndex index.php
AllowOverride all
Require all granted
</Directory>
<Directory /var/www/html/php72>
DirectoryIndex index.php
AllowOverride all
Require all granted
</Directory>
EOF
make test pages, create .htaccess to use php72-fcgi
mkdir -p /var/www/html/php56
mkdir -p /var/www/html/php72
echo "<?php phpinfo(); ?>" > /var/www/html/php56/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php72/index.php
echo "AddHandler php72-fcgi .php" > /var/www/html/php72/.htaccess
Now you should be able to test it
(http://127.0.0.1/php56)
(http://127.0.0.1/php72)
If you want to startup these instance automatically after server reboot
sudo systemctl enable httpd
sudo systemctl enable php56-php-fpm
sudo systemctl enable php72-php-fpm
As explained by #runwuf, this is possible using the sofware collections available in centos-scl repository or in remi repository.
But using SetHandler to fastcgi proxy seems a better and more modern way, thanks to httpd 2.4:
SetHandler "proxy:fcgi://127.0.0.1:9000"
This is explained in some blog posts:
My PHP Workstation on Remi's blog
PHP Configuration Tips on RH developpers' blog
I had to add the following to my php.conf inside the directory statement to make the Apache Server API change to FPM/FastCGI instead of CGI/FastCGI - your solution was almost perfect though! Now if I could just figure out how to make it use a socket instead of TCP, I'd be one happy coder.
# mod_proxy_fcgi options
<IfModule mod_proxy_fcgi.c>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9072"
</FilesMatch>
</IfModule>
It looks like what you are trying to do is similar to this:
running-two-php-versions-on-the-same-server
I personally would not want to attempt two php version on the same apache instance... I would install different version of php by tarball and run them on separate instance of apache that is also installed by tarball and point each httpd.conf to the different version of php.
replying to runwuf
Hello,
there is one problem with your approach regarding SELinux
either you disable SELinux (if you are not concerned with security) or you manage the SELinux Port Policy
In case you don't handle the SELinux, the php56-php-fpm won't start if SELinux is set to 'Enforcing' mode
Run the following commands for making SELinux allow the ports
semanage port -a -t http_port_t -p tcp 9072
semanage port -a -t http_port_t -p tcp 9056
and then finally try to start the fpm modules
I wandered here looking for a solution. CentOS now has a PHP Select which let's you run different version of PHP on the server.
More information can be found here: http://forum.centos-webpanel.com/php/php-selector/