zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Nginx + PHP(FastCGI)安装配置笔记

2023-02-18 16:39:13 时间

这是站长在2011年时一次安装服务器时所记录的Nginx和PHP的安装笔记。安装过程记录的比较简略,仅仅是一个大致的流程,一些细节描述的不够详细,请多多谅解,我会在日后重新整理一份详细的安装过程,本文仅供参考!

软件环境:CentOS 5.7 + PHP 5.2.17 + Nginx 0.8.55

1. 编译安装 PHP 和 PHP-FPM

提示:

  • 安装PHP前应先安装MySQL,具体方法请自行baidu或google;
  • PHP所需支持库的安装这里不做过多介绍,可上网搜索参照相关教程进行安装。
  • http://php-fpm.org/downloads/下载与当前PHP版本对应的PHP-FPM源码包,例如:php-5.2.17-fpm-0.5.14.diff.gz

tar zxvf php-5.2.17.tar.gz gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1 cd php-5.2.17 ./configure –prefix=/usr/local/php/ –with-config-file-path=/usr/local/php/etc –with-mysql=/usr/local/mysql/ –with-pdo-mysql=/usr/local/mysql/ –with-gd –with-zlib –with-curl –with-jpeg-dir –with-png-dir –with-libxml-dir –with-freetype-dir –with-iconv=/usr/local –with-mcrypt –enable-fastcgi –enable-fpm –enable-xml –enable-mbstring make make install cp php.ini-dist /usr/local/php/etc/php.ini

注意:上面配置PHP编译参数中的–enable-fastcgi是必须开启的。

2. 创建 Nginx 使用的用户和用户组

groupadd www useradd -g www www

3. 创建站点目录并设置权限

mkdir -p /htdocs/www chmod +w /htdocs/www chown -R www:www /htdocs/www

4. 安装 Nginx 所需的 PCRE 库

tar zxvf pcre-8.13.tar.gz cd pcre-8.13 ./configure make make install

5. 安装 Nginx

tar zxvf nginx-0.8.55.tar.gz cd nginx-0.8.55 ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –user=www –group=www make make install

6. 配置 Nginx,创建虚拟主机

在 nginx.conf 文件的 http{…} 段中,增加一个 server{…} 段,例如下面的代码:

server { listen 80; server_name www.youdomain.com; #你的域名 root /htdocs/www; access_log logs/www.access.log; location / { index index.html index.php; } error_page 500 502 503 504  /50x.html; location = /50x.html { root html; } location ~ .*\.php?$ { fastcgi_pass   127.0.0.1:9000; fastcgi_index  index.php; include        fastcgi.conf; } location ~ /nginx_info { access_log off; stub_status on; } }

注意:上面的配置中,增加了location ~ /nginx_info {…},这样就可以通过http://www.youdomain.com/nginx_info/来查询Nginx的状态信息了。

启动 PHP-FPM

/usr/local/php/sbin/php-fpm start

启动 Nginx

/usr/local/nginx/sbin/nginx

转载请注明:阳光部落原创,更多内容请访问http://www.sunbloger.com/