Detailed explanation of how to build two PHP versions in CentOS 7

PHPz
Release: 2023-03-23 16:38:01
Original
2405 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

3. Modify the www.conf file

sudo vi /etc/php56-fpm.d/www.conf
Copy after login

Modify the following Parameters:

user = apache
group = apache
listen = 127.0.0.1:9000
Copy after login

4. Start the php56-fpm service

sudo systemctl enable php56-php-fpm.service
sudo systemctl start php56-php-fpm.service
Copy after login

5. Test whether PHP 5.6 is working properly

echo "<?php phpinfo(); ?>" > /var/www/html/php56info.php
curl http://localhost/php56info.php
Copy after login

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
Copy after login

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
Copy after login

3. Modify the www.conf file

sudo vi /etc/php72-fpm.d/www.conf
Copy after login

Modify the following parameters:

user = apache
group = apache
listen = 127.0.0.1:9001
Copy after login

4. Start the php72-fpm service

sudo systemctl enable php72-php-fpm.service
sudo systemctl start php72-php-fpm.service
Copy after login

5. Test whether PHP 7.2 is normal Working

echo "<?php phpinfo(); ?>" > /var/www/html/php72info.php
curl http://localhost/php72info.php
Copy after login

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
Copy after login

Add the following content:

AddHandler php56 .php
Action php56 /usr/bin/php56-cgi
AddHandler php72 .php
Action php72 /usr/bin/php72-cgi
Copy after login

2. Modify the virtual host configuration file

sudo vi /etc/httpd/conf.d/virtualhost.conf
Copy after login

Add the following content:

<VirtualHost *:80>
  ServerName www.mysite.com
  DocumentRoot /var/www/html/mysite
  <Directory /var/www/html/mysite>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
  </Directory>
  <FilesMatch "\.php$">
    SetHandler php72
  </FilesMatch>
</VirtualHost>
Copy after login

3. Restart the Apache server

sudo systemctl restart httpd.service
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!