centos7 yum安装nginx,php5

1、安装nginx

http://nginx.org/下载nginx-1.15.8.tar.gz

解压安装

tar -zxvf nginx-1.15.8.tar.gz
cd nginx-1.15.8/
./configure --prefix=/usr/local/nginx
make
make install

启动、停止nginx

cd /usr/local/nginx/sbin/ 

./nginx 

./nginx -s stop

./nginx -s quit

./nginx -s reload

./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。

./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

查询nginx进程:

ps aux|grep nginx

 

启动成功后,在浏览器http:ip即可看到nginx页面

 

2、安装php5

yum install -y php php-mysql

验证php安装

[root@localhost ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

3、安装php-fpm

yum install -y php-fpm

验证php-fpm安装

[root@localhost nginx]# php-fpm -v
PHP 5.4.16 (fpm-fcgi) (built: Oct 30 2018 19:32:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

启动并加入自启动

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

3、nginx配置文件支持php

修改/usr/local/nginx/conf/nginx.conf

location ~ \.php$段,去掉注释

/scripts替换成$document_root

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;
}

在location /增加index.php

location / {
            root   html;
            index  index.html index.htm index.php;
        }

在/usr/local/nginx/html的增加php测试文件info.php

重启nginx访问

cd /usr/local/nginx/sbin/ 

./nginx -t

./nginx -s reload

在浏览器访问http:ip/info.php,看到php信息即成功。

你可能感兴趣的:(PHP)