一、.安装nginx请参考:?http://qingwei201314.iteye.com/blog/1729174
二、安装php:
-
获取并解压 PHP 源代码:
tar zxf php-x.x.x
Copy after login配置并构建 PHP。在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure --help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。
cd ../php-x.x.x./configure --enable-fpm --with-mysqlmakesudo make install
Copy after login创建配置文件,并将其复制到正确的位置。
cp php.ini-development /usr/local/php/php.inicp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.confcp sapi/fpm/php-fpm /usr/local/bin
Copy after login需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。
将 php.ini 文件中的配置项?cgi.fix_pathinfo?设置为?0?。
打开 php.ini:
vim /usr/local/php/php.ini
Copy after login定位到?cgi.fix_pathinfo=?并将其修改为如下所示:
cgi.fix_pathinfo=0
Copy after login在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。
vim /usr/local/etc/php-fpm.conf
Copy after login找到以下内容并修改:
; Unix user/group of processes; Note: The user is mandatory. If the group is not set, the default user's group; will be used.user = www-datagroup = www-data
Copy after login然后启动 php-fpm 服务:
/usr/local/bin/php-fpm
Copy after login本文档未涵盖对 php-fpm 进行进一步配置的信息,如果您需要更多信息,请查阅相关文档。
配置 Nginx 使其支持 PHP 应用:
vim /usr/local/nginx/conf/nginx.conf
Copy after login修改默认的 location 块,使其支持 .php 文件:
location / { root html; index index.php index.html index.htm;}
Copy after login下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:
location ~* \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name;}
Copy after login重启 Nginx。
- 如果使用thinkphp,配置pathinfo:
- 修改第6步中的部分内容如下:
location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; include fastcgi_params; }
Copy after loginStatement of this WebsiteThe 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.cnLatest Articles by Author-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Latest IssuesGroup MySQL results by ID for looping over I have a table with flight data in mysql. I'm writing a php code that will group and displ...From 2024-04-06 17:27:5601406