Home>Article>Backend Development> Detailed steps for configuring PHP with Nginx

Detailed steps for configuring PHP with Nginx

不言
不言 Original
2018-08-06 14:45:22 14512browse

本篇文章给大家带来的内容是关于Nginx配置PHP的详细步骤,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1. 安装PHP大礼包LNMP:

wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp

包含了PHP,Nginx,Mysql等等,会默认增加www用户。

2. 启动php-fpm:

cd /usr/local/php/sbin sudo service php-fpm restart

3.修改nginx配置:

server { listen 80; server_name _; index index.html index.htm index.php; root /www/phptest; location ~ \.php { set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.*)") { set $real_script_name $1; set $path_info $2; } fastcgi_pass unix:/tmp/php-cgi.sock; # 这里查看/usr/local/php/etc/php-fpm.conf的listen,保持一致 fastcgi_index index.php; include fastcgi.conf; include pathinfo.conf; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } ...

4.重启nginx:

cd /usr/local/nginx/sbin sudo service nginx restart

5. php中mysql配置(略),关键是要配置好数据库名,用户名,密码

6. 如果遇到翻页跳转失败的问题,在thinkphp的入口页index.php第一行加入:

define('_PHP_FILE_',$_SERVER['SCRIPT_NAME']);

7. 在本机使用ip/index.php访问吧

相关文章推荐:

什么是Nginx代理服务?nginx正向代理和反向代理的实例

Nginx如何实现跨域访问?Nginx跨域访问的实现

The above is the detailed content of Detailed steps for configuring PHP with Nginx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn