Home  >  Article  >  Backend Development  >  Detailed explanation of how to install two PHPs in Linux and configure environment variables

Detailed explanation of how to install two PHPs in Linux and configure environment variables

PHPz
PHPzOriginal
2023-04-04 14:34:221123browse

Linux system is an excellent operating system that is widely used in server-side applications, and PHP is one of the most commonly used programming languages ​​​​in Linux server-side. Using PHP can greatly improve the development efficiency of website applications. Sometimes, a server may need to install multiple PHP versions to support different applications or development environments. This article will detail how to install two PHP environment variable configurations in a Linux system.

First of all, we need to install two PHP versions in the server. For the convenience of demonstration, here we take CentOS 7 as an example.

Step 1: Install the first PHP version

First we need to install the first PHP version in the server, which can be achieved through the following command line operation:

yum -y install epel-release
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php72
yum -y install php php-devel php-gd php-xml php-mbstring php-pdo php-mysqlnd php-fpm

The above command line operation indicates that PHP 7.2 version is installed in CentOS 7, and PHP is installed using remi's yum source. php-fpm is the FastCGI version of PHP and is used for the connection between the web server and PHP.

Step 2: Configure the environment variables of the first PHP version

After the first PHP version is installed, we need to configure the environment variables and set the environment variables of this version of PHP Add the path to the environment variable so that the system can automatically identify this version of PHP and perform related operations. This can be achieved through the following command line:

echo 'export PATH=/usr/bin:/usr/sbin:/opt/remi/php72/root/usr/bin:/opt/remi/php72/root/usr/sbin:$PATH' >> /etc/profile

This command line operation adds PHP 7.2 to the environment variables.

Step 3: Install the second PHP version

After installing the first PHP version, we need to install another version of PHP again. Here we choose Installing PHP 7.4 version can be achieved through the following command line:

yum -y install epel-release
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum -y install php php-devel php-gd php-xml php-mbstring php-pdo php-mysqlnd php-fpm

The installation command is similar to the first step. This time we need to change the yum source to the one used by PHP 7.4 version, and install php and php-related Extension.

Step 4: Configure the environment variables of the second PHP version

After the second PHP version is installed, we need to also add it to the environment variable configuration , so that the system can automatically identify this version of PHP, which can be achieved through the following command line operations:

echo 'export PATH=/usr/bin:/usr/sbin:/opt/remi/php74/root/usr/bin:/opt/remi/php74/root/usr/sbin:$PATH' >> /etc/profile

At this point, the installation and environment variable configuration of the two PHP versions have been completed. We can perform the following operations to check whether they are installed. Success:

php -v

This command line operation will output the current system default PHP version information in the terminal. If the output matches the PHP version we installed, then congratulations, the installation is successful!

So far, we have completed the process of configuring two PHP environment variables for Linux installation. I believe readers already have a certain understanding of this. If you encounter any problems during the operation, please feel free to consult us.

The above is the detailed content of Detailed explanation of how to install two PHPs in Linux and configure environment variables. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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