centos下搭建nginx+php

441人浏览 / 0人评论
nginx在目前的web服务器中,所占的比例越来越多了。而目前web站主要已php为主,所以本人发布了centos下nginx和php的搭建文章。 工具/原料 centos服务器。我是通过在virtualbox中搭建centos虚拟机进行测试的 本文,所有的安装和测试均在 /app下进行的 nginx的安装 1 #cd /app #mkdir -m 775 nginx #cd nginx 下载nginx安装包 #wget nginx官网/download/nginx-1.7.10.tar.gz 2 安装nginx前,首先检查gcc是否已经装好了。 输入命令:gcc -v;装好了则会告诉你版本信息,否则会找不到命令。 若没有安装,需要执行如下命令进行安装: #yum -y install gcc; centos下搭建nginx+php 3 其次安装nginx还需要PCRE library.,否则在安装nginx时候会提示: ./configure: error: the HTTP rewrite module requires the PCRE library; 同样也是在线安装, 输入命令:yum -y install pcre-devel openssl openssl-devel; 4 解压下载好的nginx压缩包 #tar -zxvf nginx-1.7.10.tar.gz #./configure --prefix=/app/soft/nginx #make #make install 此时nginx就安装完成了。 5 nginx的启动和重启 1、启动Nginx: #/app/soft/nginx/sbin/nginx -t 查看配置信息是否正确 #/app/soft/nginx/sbin/nginx 2、平滑启动nginx #/app/soft/nginx/sbin/nginx -s reload 3、查看nginx的进程: #ps -ef|grep nginx END php的安装 进入到php测试目录 #cd /app/php 下载php的安装包: #wget php官网/distributions/php-5.4.41.tar.gz 解压 #tar -zxvf php-5.4.41.tar.gz #cd php-5.4.41 编译和安装php #./configure --prefix=/app/soft/php --enable-fpm --with-mcrypt \--enable-mbstring --disable-pdo --with-curl --disable-debug --disable-rpath \--enable-inline-optimization --with-bz2 --with-zlib --enable-sockets \--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex \--with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli \--with-gd --with-jpeg-dir #make #make test #make install 在安装php的过程中,有如下报错:configure: error: xml2-config not found. Please check your libxml2 installation. 解决方法: 重新安装libxml2和libxml2-devel包 yum install libxml2 yum install libxml2-devel -y 配置php环境 将安装包下的php配置文件复制到php安装路径下: #cp /app/php/php-5.4.41/php.ini-development /app/soft/php/lib/php.ini 复制后,重启php,配置文件自动识别 php的启动 #/app/soft/php/sbin/php-fpm php进程的查看 #ps -ef|grep php-fpm END 整合php和nginx 1 让nginx能够识别php的文件 修改nginx的配置文件: #vi /app/soft/nginx/conf/nginx.conf location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /app/nginx/html/test$fastcgi_script_name; include fastcgi_params; } 保存配置文件,并重启nginx服务 #/app/soft/nginx/sbin/nginx -t //查看配置信息是否正确 #/app/soft/nginx/sbin/nginx -s reload