- 安裝nginx
yum install nginx
- 設置nginx開啟起動
systemctl start nginx
- 測試
訪問http://你的域名或IP/
- 查看nginx安裝位置
whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz
- 安裝php
yum install php php-mysql php-fpm
安裝過程中經常會見到如下問題:
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
解決方法:
把php-mysql換成php-mysqlnd
即執行
yum install php php-mysqlnd php-fpm
- 配置php處理器
vim /etc/php.ini
查找cgi.fix_pathinfo
將 ;cgi.fix_pathinfo=1改為cgi.fix_pathinfo=0
7. 配置www.conf
vim /etc/php-fpm.d/www.conf
將
user = nobody
group = nobody
改為
user = nginx
group = nginx
前提是已經創建了nginx用戶和nginx組。
8. 起動php-fpm
systemctl start php-fpm
- 設置php-fpm開機啟動
systemctl enable php-fpm
-
配置nginx
打開/etc/nginx/conf.d/default.conf,如果不存在則創建
粘貼
server {
listen 80;
server_name server_domain_name_or_IP;note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}location ~ .php$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
} -
重起nginx
systemctl restart nginx
- 測試php
創建/usr/share/nginx/html/index.php
/usr/share/nginx/html/info.php
輸入以下內容:
訪問http://你的IP/index.php,正常情況下會出現