安装PHP到Ubuntu(APT)

运行环境

系统版本:Ubuntu 16.04.2 LTS
软件版本:PHP-5.6
硬件要求:无

安装过程

1、安装APT存储库

APT存储库由PPA提供。

root@localhost:~# apt-get install python-software-properties
root@localhost:~# add-apt-repository ppa:ondrej/php
root@localhost:~# apt-get update

2、安装PHP5.6和常用扩展库

root@localhost:~# apt-get -y install php5.6 php5.6-bcmach php5.6-fpm php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip php5.6-soap  php5.6-xml 

3、启动PHP-FPM服务

root@localhost:~# systemctl start php5.6-fpm

4、配置Nginx反代PHP

root@localhost:~# vim /etc/nginx/conf.d/php56
server {
        listen 80;
        server_name  _php;
        root   "/var/www/html/";

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

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

猜你喜欢

转载自www.cnblogs.com/network-ren/p/12378268.html
今日推荐