安装PHP到CentOS(YUM)

运行环境

系统版本:CentOS Linux release 7.3.1611
软件版本:PHP-7.2
硬件要求:无

安装过程

1、配置YUM-REMI存储库

YUM-REMI存储库由REMI官方提供。

[root@localhost ~]# rpm -i http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[root@localhost ~]# rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2、安装PHP72+Nginx

[root@localhost ~]# yum -y install php72 php72-php-bcmath php72-php-fpm php72-php-gd php72-php-mbstring php72-php-mysqlnd php72-php-opcache php72-php-pecl-crypto php72-php-pecl-mcrypt php72-php-pecl-memcache php72-php-pecl-mysql php72-php-pecl-redis php72-php-pecl-swoole nginx

3、启动PHP-FPM服务

[root@localhost ~]# systemctl start php72-php-fpm.service 
[root@localhost ~]# systemctl enable php72-php-fpm.service

4、配置Nginx反代PHP

[root@localhost ~]# vim /etc/nginx/conf.d/php72
server {
        listen 8080;
        server_name  _php;
        root   "/usr/share/nginx/html";

        location / {
                index index.php index.html;
                if (!-e $request_filename){
                        rewrite  ^(.*)$  /index.php?s=$1  last;
                break;
                }
        }

        location ~ ^.*\.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            #连接到PHP-FPM,这里采用UNIX套接字的连接方式,设置由PHP-FPM提供的UNIX套接字文件路径。
            fastcgi_index  index.php;
            #设置PHP默认首页文件。
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            #设置FastCGI的一个环境变量"SCRIPT_FILENAME",设置FastCGI服务器读取的PHP入口文件完整路径。
            include        fastcgi_params;
            #包含当前配置目录下"fastcgi_param"文件中的所有配置,该文件中存储了一些默认配置FastCGI服务器的一些环境变量,这些变量都有特殊的作用,一般情况下无需修改。
        }
}

5、创建一个PHP测试页面

[root@localhost ~]# vi /usr/share/nginx/html/index.php
<?php
phpinfo()
?>

6、启动Nginx

[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx

7、访问到PHP页面

直接在浏览器输入地址+端口即可。

posted @ 2020-02-28 18:01  RidingWind  阅读(717)  评论(0)    收藏  举报