Home>Article>Backend Development> How to install php yum to a specified directory
How to install php yum in the specified directory: 1. Execute the "yum install" command to install; 2. Modify "/usr/local/php/etc/php.ini"; 3. Run "php-fpm" ; 4. Configure alias; 5. Specify the path of PHP scanning extension.
The operating environment of this tutorial: Centos7 system, PHP version 8.1, Dell G3 computer.
How to install php yum to a specified directory?
Centos7 Yum Install PHP to the specified directory
Sometimes it is necessary to install multiple versions of PHP on the server, but compilation and installation cannot use yum to install dependencies and To maintain extensions, use this method to install and configure multiple PHP environments. The first PHP environment on the server can be installed directly using yum, and then the second, third or even more need to be installed using the following commands and configured
Installation command
yum install -c /etc/yum.conf --installroot=/usr/local/php/ --releasever=/ --enablerepo=remi-php71 php php-opcache php-mbstring php-mcrypt php-fpm php-cli php-xml php-redis php-mysqlnd php-pdo php-phalcon php-common php-json
Note:
installroot Select the directory to be installed
php and php extension by yourself
The remaining parameters are fixed
Configuration
Modify /usr/local/php/etc/php.ini
Modify /usr/local/php/etc/php-fpm.conf
Modify /usr/local /php/etc/php-fpm.d/*.conf
To run php-fpm
, you need to modify the ExecStart value of the php-fpm.service file first. For:
ExecStart=/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini --fpm-config /usr/local/php/etc/php-fpm.conf --nodaemonize
The path is the path for custom installation, please modify it yourself
php command line
You need to bring the configuration every time you run the php command The file path seems particularly troublesome, so it is recommended to configure alias
alias php7='PHP_INI_SCAN_DIR=/usr/local/php/etc/php.d /usr/local/php/bin/php -c /usr/local/php/etc/php.ini'
After configuring alias, you can directly use the alias to execute php commands on the command line, such as: php7 -v
The purpose of setting PHP_INI_SCAN_DIR=/usr/local/php/etc/php.d in alias is to specify the path of PHP scanning extension, which must be set
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to install php yum to a specified directory. For more information, please follow other related articles on the PHP Chinese website!