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

<?php phpinfo(); ?>

重啓nginx訪問

cd /usr/local/nginx/sbin/ 

./nginx -t

./nginx -s reload

在瀏覽器訪問http:ip/info.php,看到php信息即成功。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章