search
HomeBackend DevelopmentPHP7Detailed 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.

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

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

// 检测
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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.