之前因为误操作,通过root误删除系统重要文件,不得不重新安装系统搭服务,浪费了不少时间。这次将整个搭建过程记录下来,同时在腾讯云上建立个镜像,避免重蹈覆辙。
PS:幸亏之前提前备份的数据库,否则辛苦写的文章和站点的配置信息也全丢,损失更大。
LNMP搭建,参考:
whereis nginx:
nginx: /usr/sbin/nginx
/usr/lib64/nginx
/etc/nginx
/usr/share/nginx
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx.8.gz
执行:/usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
可以看到,nginx用的配置文件是 /etc/nginx/nginx.conf
nginx的配置文件所在目录:/etc/nginx
但经过试验发现,默认的nginx.conf无法使php的访问生效。
而改用的是nginx.conf.default里的内容,然后将server里关于php设置的内容替换成:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
}
另外,还需要把配置文件第一行的
#user anybody去掉,改成;
user root;
即用root启动的nginx,应该让root有访问权限
此时再重启nginx,可以访问php了。
安装完wordpress后,发现只能访问管理台,但好多页面返回403 forbidden错误,原因是在nginx.conf里:
location / {
root html;
index index.php index.html index.htm;
}
上述location /配置里,加上 index.php