Detailed steps for configuring PHP with Nginx

不言
Release: 2023-04-03 16:32:02
Original
14477 people have browsed it

本篇文章给大家带来的内容是关于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
Copy after login

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

2. 启动php-fpm:

cd /usr/local/php/sbin sudo service php-fpm restart
Copy after login

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; } ...
Copy after login

4.重启nginx:

cd /usr/local/nginx/sbin sudo service nginx restart
Copy after login

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

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

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!