首页> 运维> nginx> 正文

怎么编译NGINX并支持PHP

WBOY
发布: 2023-05-18 19:50:44
转载
1126 人浏览过

前提条件

在开始安装之前,请确保您的系统上已经安装了gcc、make和zlib-devel包。可以通过以下命令来安装这些软件包:

$ sudo yum install gcc make zlib-devel
登录后复制

下载与解压缩

首先,您需要下载NGINX源代码。您可以从官方网站上下载最新版本。

$ wget https://nginx.org/download/nginx-1.19.2.tar.gz
登录后复制

解压缩下载的文件:

$ tar -zxvf nginx-1.19.2.tar.gz
登录后复制

进入解压目录:

$ cd nginx-1.19.2
登录后复制

编译安装

要编译NGINX并支持PHP,您需要在编译NGINX时添加--with-http_stub_status_module--with-http_realip_module参数。

以下是编译命令:

$ ./configure --prefix=/usr/local/nginx \ --with-http_stub_status_module \ --with-http_realip_module \ --with-http_ssl_module \ --add-module=/usr/local/src/ngx_cache_purge \ --add-module=/usr/local/src/headers-more-nginx-module \ --add-module=/usr/local/src/ngx_http_upstream_session_sticky_module \ --add-module=/usr/local/src/encrypted-session-nginx-module \ --add-module=/usr/local/src/nginx-module-vts $ make && sudo make install
登录后复制

以上命令将导致NGINX与实时IP模块打包,并通过--with-http_ssl_module参数支持SSL。此外,还添加了一些第三方模块,例如ngx_cache_purge,headers-more-nginx-module,ngx_http_upstream_session_sticky_module,encrypted-session-nginx-module和nginx-module-vts等。

PHP支持

确保在安装FPM时启用了PHP,以在NGINX中支持PHP。FPM是FastCGI进程管理器的缩写,它促成了PHP和NGINX之间的协作。

接下来,在NGINX的配置文件中添加以下内容以启用PHP支持。

location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
登录后复制

SCRIPT_FILENAME参数指定PHP脚本的路径。

以上是怎么编译NGINX并支持PHP的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:yisu.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!