虽然centos6可以用yum安装nginx,但是我还是写个教程用源码包安装用于线上环境。
一:在nginx官网下载nginx,并安装
我下载的是nginx-1.6.0
#./configure --prefix=/usr/local/nginx make&& make install
卸载已存在的apache服务和php
[root@pangou Desktop]# yum remove httpd php*
安装development Tools
[root@pangou Desktop]# yum -y groupinstall "Development Tools"
就是用yum自行结局依赖关系
[root@pangou nginx-1.6.0]# yum install pcre pcre-devel
二:安装php
[root@pangou php]# wget http://cn2.php.net/get/php-5.4.14.tar.gz
解压,
安装依赖包
[root@pangou php]# yum install -y libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel
[root@pangou php-5.4.14]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/ --with-mysqli=/usr/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic
#make && make install
[root@pangou php-5.4.14]# cp /root/Downloads/php/php-5.4.14/php.ini-production /opt/php/etc/php.ini
[root@pangou php-5.4.14]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
[root@pangou php-5.4.14]# cd /opt/php/etc/
[root@pangou etc]# ls
php-fpm.conf php-fpm.conf.default php.ini
// 然后配置nginx的配置文件,让其可以运行php
[root@pangou etc]# cd /usr/local/nginx/conf/
[root@pangou conf]# ls
fastcgi.conf fastcgi_params koi-utf mime.types nginx.conf scgi_params uwsgi_params win-utf
fastcgi.conf.default fastcgi_params.default koi-win mime.types.default nginx.conf.default scgi_params.default uwsgi_params.default
[root@pangou conf]# vim nginx.conf
1、去掉 #user nobody; 的#号, 变成 user nobody;
2、去掉
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
之前的#号,
并修改
代码如下:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
代码如下:
[/cfastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
ode]
最终修改后的内容为:
[code]
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
重启nginx服务,并开启php-fpm
[root@pangou ~]# /opt/nginx/sbin/nginx
[root@pangou ~]# /opt/php/sbin/php-fpm
// 创建phpinfo文件
[root@pangou ~]# vim /usr/local/nginx/html/phpinfo.php
内容为
复制代码 代码如下:
<?php
phpinfo();
?>
访问http://127.0.0.1/phpinfo.php
安装成功。mysql,mysqli等扩展都有。
这边有一点偷懒,并没有编译安装mysql,而是使用yum安装的mysql。