===============================================================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