The OneinStackPHP multi-version coexistence tutorial is based on the lnmp mode in the one-click PHP/JAVA installation tool of OneinStack. users want one website to run in php5.4 and the other website to run in php7, multiple PHP versions are supported on one server. The steps are as follows:
1. install OneinStack
Select lnmp mode, php5.4 installed by default, installation steps refer to: http://oneinstack.com/install/
The options are as follows:
-
Install Nginx
-
Do not install Apache
-
Do not install Tomcat
-
Install MySQL-5.6
-
Install php-5.4
-
....
2. install php7
-
Service php-fpm stop # install php later and stop php
-
Mv/etc/init. d/php-fpm {, _ bk} # install php later to overwrite and back up the startup script
The default php5.4 installation path is/usr/local/php. if you install php again, the system prompts that php has been installed. Therefore, you must modify options. in the php installation directory of conf, set the php7 installation path to/usr/local/php7 and modify/root/oneinstack/options. conf:
-
Php_install_dir =/usr/local/php7
Run again./install. sh, select Install php-7, and select n for others, Waiting for ing
3. modify the php configuration file
-
Service php-fpm stop # stop the php7 startup script
-
Mv/etc/init. d/php-fpm/etc/init. d/php7-fpm # Rename php7 startup script
-
Mv/etc/init. d/php-fpm_bk/etc/init. d/php-fpm # restore php5.4 startup script
Set php5.4 and php7 to start automatically:
-
# CentOS:
-
Chkconfig -- add php7-fpm
-
Chkconfig -- add php-fpm
-
Chkconfig php7-fpm on
-
Chkconfig php-fpm on
-
-
# Ubuntu/Debian:
-
Update-rc.d php7-fpm ULTS
-
Update-rc.d php-fpm defaults
To prevent sock conflicts in php5.4 and php7 listening, modify the listen of php7 and change the configuration file/usr/local/php7/etc/php-fpm.conf:
-
Listen =/dev/shm/php-cgi.sock
-
# Change
-
Listen =/dev/shm/php7-cgi.sock
Start php5.4 and php7 manually:
-
Service php-fpm start # start php5.4
-
Service php7-fpm start # start php7
For example:
4. modify the nginx virtual host configuration file
. /Vhost. sh: bind the domain name. The default value is php5.4. to run the website in php7, modify/usr/local/nginx/conf/vhost/www.oneinstack.com. conf (www.oneinstack.com changed to bind your own domain name ):
-
Fastcgi_pass unix:/dev/shm/php-cgi.sock;
-
# Change
-
Fastcgi_pass unix:/dev/shm/php7-cgi.sock;
Reload nginx to make the configuration take effect:
-
Service nginx reload
Reprinted: