===============================================================php
nginxhtml
===============================================================mysql
wget http://nginx.org/download/nginx-1.6.2.tar.gz nginx
一、默认安装
解压源码,运行命令:
代码示例:web
#./configure
#make
#make installsql
Nginx默认被安装到/usr/local/nginx,固然也能够经过设置编译选项来定制安装。centos
二、定制安装
一般在安装Nginx前须要先安装以下依赖包:
浏览器
代码示例:服务器
#yum install openssl-devel pcre-devel zlib-devel
app
在编译前设置编译选项:
代码示例:
#./configure
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
编译并安装:
代码示例:
#make && make install
启动nginx:
#/usr/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed
提示须要建立nginx用户和组:
代码示例:
#groupadd -r nginx
#useradd -r -g nginx -s /bin/false -M nginx
再次运行就行了,若是出现下面错误,手工建立相应目录就好:
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
nginx默认监听80端口,在浏览器中敲http://localhost便可出现:Welcome to nginx,恭喜你,You are OK!
===============================================================
php
===============================================================
wget http://museum.php.net/php5/php-5.5.7.tar.gz
tar zxvf php-5.5.7.tar.gz
cd php-5.5.7
./configure --prefix=/app/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 --disable-fileinfo
make all install
===============================================================
php
===============================================================
出现以下错误php安装出错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.,意思是,没有查找到mcrytp.h,须要安装libcrytp,在下面的地址下载libmarypt:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
安装:
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
mkdir -p /usr/local/libmcrytp
./configure prefix=/usr/local/libmcrytp/
make
make install
而后再安装PHP
=================================================================
若是以上方法仍然不能安装,请参考:
rpm -ivh "http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"
yum install -y libmcrypt-devel
由于centos6.x 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源。
==================================================================
编译PHP5.5 make 时出现错误
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
解决办法
这是因为内存小于1G所致使.
在./configure加上选项:
--disable-fileinfo
Disable fileinfo support 禁用 fileinfo
===============================================================
php config
===============================================================
1.下面是对php-fpm运行用户进行设置
cd /app/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf
user = www
group = www
若是www用户不存在,那么先添加www用户
groupadd www
useradd -g www www
=============================================================
2.修改nginx配置文件以支持php-fpm
修改nginx配置文件/etc/nginx/nginx.conf
其中server段增长以下配置:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /data/www; #项目根目录
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3.建立测试php文件
建立php文件
在/data/www下建立index.php文件,输入以下内容:
<?php
echo phpinfo();
?>
4.启动php-fpm服务
/app/php/sbin/php-fpm
重启nginx服务器:
nginx -s reload
5.php-fpm关闭与重启
php-fpm 关闭:
ps -ef |grep php
kill pid
php-fpm 重启:
/app/php/sbin/php-fpm
6.php-fpm开机启动
echo "/app/php/sbin/php-fpm" >> /etc/rc.local