Home>Article>Backend Development> Detailed explanation of how to build two PHP versions in CentOS 7
During development, sometimes we encounter situations where we need to use different PHP versions. How to build two PHP versions on a CentOS 7 system? Below we will introduce the construction method in detail.
1. Preparation
Before starting to build, prepare the following tools and environment:
1. CentOS 7 server and root permissions
2. Two different versions of PHP, here we will use PHP 5.6 and PHP 7.2
3. Web server, here we will use the Apache server
4, EPEL and REMI warehouse , these two repositories provide the latest PHP packages and related dependency packages. If it is not installed, you can install it through the following command:
sudo yum install epel-release sudo rpm -Uvh https://rpms.remirepo.net/enterprise/remi-release-7.rpm
5. To install the necessary dependencies, you can use the following command to install
sudo yum install httpd mysql php php-mysql php-devel php-gd php-pspell php-snmp php-xmlrpc php-xml
2. Install PHP 5.6
1. Install php56 and related extension packages
sudo yum install php56 php56-php php56-php-common php56-php-fpm php56-php-gd php56-php-json php56-php-mbstring php56-php-mcrypt php56-php-mysqlnd php56-php-opcache php56-php-pdo php56-php-pecl-apcu php56-php-pecl-imagick php56-php-pecl-memcached php56-php-pecl-redis php56-php-pecl-xdebug php56-php-soap php56-php-xml php56-php-zip
2. Create the php.ini file used
sudo cp /opt/remi/php56/root/etc/php.ini /etc/php56.ini sudo cp /opt/remi/php56/root/etc/php-fpm.d/www.conf /etc/php56-fpm.d/www.conf
3. Modify the www.conf file
sudo vi /etc/php56-fpm.d/www.conf
Modify the following Parameters:
user = apache group = apache listen = 127.0.0.1:9000
4. Start the php56-fpm service
sudo systemctl enable php56-php-fpm.service sudo systemctl start php56-php-fpm.service
5. Test whether PHP 5.6 is working properly
echo "" > /var/www/html/php56info.php curl http://localhost/php56info.php
If PHP 5.6 information is returned, the installation is successful.
3. Install PHP 7.2
1. Install php72 and related extension packages
sudo yum install php72 php72-php php72-php-common php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mcrypt php72-php-mysqlnd php72-php-opcache php72-php-pdo php72-php-pecl-apcu php72-php-pecl-imagick php72-php-pecl-memcached php72-php-pecl-redis php72-php-pecl-xdebug php72-php-soap php72-php-xml php72-php-zip
2. Create the php.ini file used
sudo cp /opt/remi/php72/root/etc/php.ini /etc/php72.ini sudo cp /opt/remi/php72/root/etc/php-fpm.d/www.conf /etc/php72-fpm.d/www.conf
3. Modify the www.conf file
sudo vi /etc/php72-fpm.d/www.conf
Modify the following parameters:
user = apache group = apache listen = 127.0.0.1:9001
4. Start the php72-fpm service
sudo systemctl enable php72-php-fpm.service sudo systemctl start php72-php-fpm.service
5. Test whether PHP 7.2 is normal Working
echo "" > /var/www/html/php72info.php curl http://localhost/php72info.php
If PHP 7.2 information is returned, the installation is successful.
4. Configure the Apache server
1. Modify the httpd.conf file
sudo vi /etc/httpd/conf/httpd.conf
Add the following content:
AddHandler php56 .php Action php56 /usr/bin/php56-cgi AddHandler php72 .php Action php72 /usr/bin/php72-cgi
2. Modify the virtual host configuration file
sudo vi /etc/httpd/conf.d/virtualhost.conf
Add the following content:
ServerName www.mysite.com DocumentRoot /var/www/html/mysite Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all Require all granted SetHandler php72
3. Restart the Apache server
sudo systemctl restart httpd.service
Now, you can run two PHP versions at the same time.
Summary
In this article, we introduced how to build two PHP versions on CentOS 7. With this knowledge, you can develop and manage your PHP applications with more flexibility.
The above is the detailed content of Detailed explanation of how to build two PHP versions in CentOS 7. For more information, please follow other related articles on the PHP Chinese website!