Home > Backend Development > PHP7 > body text

Detailed explanation of how to install php7 on centos yum

藏色散人
Release: 2023-02-17 16:56:02
Original
3720 people have browsed it

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.

Detailed explanation of how to install php7 on centos yum

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

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

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

3. After installation, start php-fpm

systemctl start php-fpm
Copy after login

4. Check the version to check whether the installation is successful

php -v
Copy after login

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();?>
Copy after login

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

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

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(&#39;localhost&#39;,&#39;root&#39;,&#39;qq1234&#39;);//数据库服务器地址,账号名,密码

// 检测
if (!$test) echo "连接失败,请检查mysql服务以及账户密码";
echo "数据库连接成功!";
?>
Copy after login

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!

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