Home > Article > Backend Development > Detailed explanation of how to install php7 on centos yum
How to install php7 on centos yum: first upgrade the yum warehouse package to the rpm package of PHP7; then use the yum command to install basic PHP components; then install "PHP-fpm" and start "php-fpm"; Finally check the version to check whether the installation is successful.
1. Installation preparation
Use the following command to upgrade the yum warehouse package to the rpm package of PHP7
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmrpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2. Start the installation
1. First use the yum command to install the basic PHP components, and then install whatever you need in the future
yum -y install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64
2. Then install PHP-fpm (process manager, which provides PHP process management methods, can effectively control memory and processes, and smoothly reload PHP configuration)
yum -y install php70w-fpm php70w-opcache
3. After installation, start php-fpm
systemctl start php-fpm
4. Check the version to check whether the installation is successful
php -v
3. Check whether PHP can communicate with Nginx
1. Create a new index in Nginx’s default HTML folder (/usr/local/webserver/nginx/html/) .php, the content is as follows:
<?php phpinfo();?>
2. Modify the Nginx configuration file (you can use find /|grep nginx.conf to search for the configuration file location) Nginx.conf, modify and add the following:
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
You need to change the original attributes into the blue font part, otherwise the following situation will occur when accessing index.php (php-fpm cannot find the php file executed in the original SCRIPT_FILENAME)
3. Restart Nginx
/usr/local/webserver/nginx/sbin/nginx -s reload
4. Access the domain name (IP)/index.php and the following content appears, which means the configuration is successful
4. Check whether PHP can communicate with mysql
Modify the content of the previous index.PHP as follows
<?php // 创建连接 $test = mysqli_connect('localhost','root','qq1234');//数据库服务器地址,账号名,密码 // 检测 if (!$test) echo "连接失败,请检查mysql服务以及账户密码"; echo "数据库连接成功!"; ?>
Access directly after modification index.php, no need to restart Nginx
The above is the detailed content of Detailed explanation of how to install php7 on centos yum. For more information, please follow other related articles on the PHP Chinese website!