安裝編譯環(huán)境
yum install -y gcc gcc-c++ ncurses-devel perl
安裝pcre開發(fā)包(nginx依賴)
yum install -y pcre-devel
安裝zlib
yum install -y zlib-devel
安裝Nginx
wget http://nginx.org/download/nginx-1.7.9.tar.gz
tar xzvf nginx-1.7.9.tar.gz
cd nginx-1.7.9
./configure --prefix=/usr/local/nginx --user=nobody --group=nobody && make && make install
wget:下載工具命令tar:解壓縮包命令 參數(shù):-x 解壓 -z 判斷是否使用gzip壓縮 -v 解壓過程顯示文件 -f 使用文檔名
啟動nginx
/usr/local/nginx/sbin/nginx
設(shè)置nginx開機(jī)啟動
寫入文件
vim /etc/init.d/nginx```
**設(shè)置成可執(zhí)行**
chmod +x /etc/init.d/nginx```
設(shè)置成開機(jī)啟動
chkconfig nginx on```
----
###安裝PHP依賴包
```yum -y install autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libmcrypt libmcrypt-devel mysql-devel```
----
###生成libmysqlclient軟鏈
```ln -s /usr/lib64/mysql/libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so```
>通過查找libmysqlclient,發(fā)現(xiàn)是在/usr/lib64/mysql/目錄內(nèi)的libmysqlclient.so.18.0.0做的軟連接,PHP默認(rèn)是去的 /usr/lib/搜索,所以沒有找到鄙煤,所以要在php默認(rèn)的/usr/lib/目錄下生成鏈接到libmysqlclient的軟鏈东跪。
>**注意圃庭,這里的libmysqlclient.so.18.0.0可能更新而修改版本號(之前我參考的教程就是libmysqlclient.so.16.0.0),所以我們要先進(jìn)入/usr/lib64/mysql/目錄搔体,確定這個(gè)文件(libmysqlclient.so.18.0.0)的具體名稱,再生成軟鏈半醉。**
----
###安裝libmcrypt
>centos源不能安裝libmcrypt-devel疚俱,由于版權(quán)的原因沒有自帶mcrypt的包。所以這里我們使用自己在網(wǎng)上下載的包缩多,然后上傳到服務(wù)器的目錄上呆奕。
```cd /usr/local```
```wget http://softlayer.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz (使用附件的包或者自己下載的包)```
```tar -zxvf libmcrypt-2.5.8.tar.gz```
```cd libmcrypt-2.5.8```
```./configure --prefix=/usr/local && make && make install```
----
###安裝PHP
```wget http://cn2.php.net/distributions/php-5.3.29.tar.gz ```
```tar xzvf php-5.3.29.tar.gz```
```cd php-5.3.29```
**內(nèi)存大于等于1G時(shí)**
```./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-mcrypt --enable-mbstring --with-curl --disable-debug -with-bz2 --with-zlib --enable-sockets --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir && make && make install```
**內(nèi)存小于1G時(shí)**
```./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-mcrypt --enable-mbstring --with-curl --disable-debug -with-bz2 --with-zlib --enable-sockets --enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir --disable-fileinfo && make && make install```
```cp php.ini-production /usr/local/php/etc/php.ini```
```ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar```
```cd /usr/local/php/etc/```
```mv php-fpm.conf.default php-fpm.conf```
```mkdir /usr/local/php/log```
```chmod 777 /usr/local/php/log```
----
###修改php-fpm.conf文件
```vim /usr/local/php/etc/php-fpm.conf```
>設(shè)置錯(cuò)誤日志路徑 **error_log = /usr/local/php/log/php_errors.log**
----
###修改php.ini文件
```vim /usr/local/php/etc/php.ini```
>設(shè)置時(shí)區(qū)中國 **date.timezone = PRC**
>隱藏php版本號 **expose_php=Off**
----
###啟動php-fpm
```cd /usr/local/php-5.3.29```
```cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm```
```chmod +x /etc/init.d/php-fpm```
```chkconfig php-fpm on```
```/etc/init.d/php-fpm start```
----
###配置一個(gè)虛擬主機(jī)
```mkdir /usr/local/nginx/conf/vhosts```
```vim /usr/local/nginx/conf/nginx.conf```
>去掉log_format main前的注釋,在最后一個(gè)“}”前加入一行 **include vhosts/*.config;**
----
###檢查一下配置文件是否有問題
```/usr/local/nginx/sbin/nginx -t```
>**正確響應(yīng):**
>nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
>nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
----
###重新加載配置文件
```/usr/local/nginx/sbin/nginx -s reload```
>每次新寫入一個(gè)/usr/local/nginx/conf/vhosts/*.conf 文件都要運(yùn)行這個(gè)命令哦