nginx+php+mysql
linux環(huán)境:centos 7.0 64位
nginx:nginx-1.8.0.tar.gz
php: php-7.1.1.tar.gz
mysql: mysql-5.6.39.tar.gz
libxml2:libxml2-2.9.1.tar.gz
openssl:openssl-1.0.1f.tar.gz
zlib:zlib-1.2.3.tar.gz
pcre:pcre-8.36.tar.gz
安裝工具
這里用yum安裝一下在編譯過程中所需要的編譯工具和小程序,如:gcc、gd庫、cmake等等。這么多小軟件,我們不需要編譯安裝,因?yàn)檫@些軟件安裝后,以后并不會修改操作,只是一個工具而已。
yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel gd-devel \
freetype-devel libxml2-devel libjpeg-devel libpng-devel \
openssl-devel curl-devel patch libmcrypt-devel \
libmhash-devel ncurses-devel bzip2 \
libcap-devel ntp sysklogd diffutils sendmail iptables unzip cmake
注意:這里可能會出現(xiàn)以下錯誤
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 71 M RSS (370 MB VSZ)
Started: Sat Feb 11 18:45:08 2017 - 00:34 ago
State : Running, pid: 3033
這是因?yàn)閥um正在運(yùn)行著,我們需要停止yum,停止yum的命令如下:
[root@localhost ~]# kill /var/run/yum.pid
停止yum之后,再進(jìn)行上面的yum安裝。
創(chuàng)建用戶
我們需要創(chuàng)建2個用戶,一個用來啟動mysql,一個用來啟動nginx
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r mysql -g mysql
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -r www -g www
這里我們成功創(chuàng)建了兩個用戶組 mysql 和 www ,也創(chuàng)建了兩個用戶 mysql 和 www。
安裝nginx
安裝nginx前,我們需要安裝3個依賴包:
pcre:在使用 nginx 的 rewrite 模塊的時候,需要有pcre庫的支持
openssl:在使用ssl功能時,需要有 openssl庫的支持
zlib:在使用gzip模塊時,需要有zlib庫的支持。
而這三個模塊都是我們常用的,所以這3個依賴包還是要安裝的。
安裝 pcre
[root@localhost lnmp]# cd /www/lnmp/pcre-8.36
[root@localhost pcre-8.36]# ./configure
[root@localhost pcre-8.36]# make
[root@localhost pcre-8.36]# make install
在上面的 ./configure 之后是按一下“回車”,然后等待配置,配置之后,再輸入 make,然后“回車”,等待編譯,編譯好后,輸入 make install 就可以了。
安裝 openssl
[root@localhost pcre-8.36]# cd /www/lnmp/openssl-1.0.1e
[root@localhost openssl-1.0.1e]# ./config
[root@localhost openssl-1.0.1e]# make
[root@localhost openssl-1.0.1e]# make install
安裝 zlib
[root@localhost openssl-1.0.1e]# cd /www/lnmp/zlib-1.2.3
[root@localhost zlib-1.2.3]# CFLAGS="-O3 -fPIC" ./configure
[root@localhost zlib-1.2.3]# make && make install
安裝 nginx
安 裝nginx的時候,參數(shù)可能會多一些。nginx有很多模塊,如果哪個模塊用不到,盡量不要安裝,我們進(jìn)入 nginx 源碼目錄可以使用 ./configure --help 查看有哪些編譯參數(shù)。參數(shù)太多,這里不一一介紹,如果您想了解可以自行查看help或百度。不過,常用的有以下幾個:
--prefix=PATH 要安裝到的目錄
--sbin-path=PATH 指定nginx二進(jìn)制文件的路徑,沒指定的話這個路徑依賴 --prefix 選項(xiàng)
--conf-path=PATH 如果在命令行未指定配置文件,那么將會通過 --prefix 指定的路徑去查找配置文件
--error-log-path=PATH 錯誤文件路徑,nginx寫入錯誤日志文件地址
--pid-path=<path> nginx master進(jìn)程pid寫入的文件位置,通常在var/run下
--user=<user> worker進(jìn)程運(yùn)行的用戶
--group=<group> worker進(jìn)程運(yùn)行的組
--with-http_ssl_module 開啟 ssl 模塊
--with-zlib=DIR 設(shè)置 zlib 的源碼目錄
--with-openssl=DIR 設(shè)置 openssl 的源碼目錄
--with-pcre=DIR設(shè)置 pcre 的源碼目錄
了解完編譯參數(shù)之后,我們進(jìn)行編譯安裝
[root@localhost zlib-1.2.3]# cd /www/lnmp/nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --help // 這是查看幫助的命令
[root@localhost nginx-1.8.0]# ./configure --user=www --group=www --prefix=/www/source/nginx --with-pcre=/www/lnmp/pcre-8.36 --with-zlib=/www/lnmp/zlib-1.2.3 --with-openssl=/www/lnmp/openssl-1.0.1e
[root@localhost nginx-1.8.0]# make && make install
安裝好之后,我們可以用 ls 查看 /www/source,發(fā)現(xiàn)有一個 nginx,說明已經(jīng)安裝成功了。
[root@localhost nginx-1.8.0]# cd /www/source/nginx
[root@localhost nginx-1.8.0]#ls
mysql安裝
詳情看以前筆記
安裝php
安裝 libxml2
[root@localhost mysql]# cd /www/lnmp/libxml2-2.9.1
[root@localhost libxml2-2.9.1]# ./configure --with-python=no
[root@localhost libxml2-2.9.1]# make && make install
特別注意:如果出現(xiàn)這個錯誤,可以用下面這個方法 ,其它軟件,如果在安裝的時候,也是同理
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `.ro
data' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [libxml2.la] 錯誤 1
make[2]: Leaving directory `/lnmp/libxml2-2.9.1'
make[1]: *** [all-recursive] 錯誤 1
make[1]: Leaving directory `/lnmp/libxml2-2.9.1'
make: *** [all] 錯誤 2
解決方法:
./configure --with-python=no --enable-shared=no --with-pic=PIC
安裝 php7.1
php的編譯參數(shù)也是很多的,這里了不能一一介紹,可以使用 ./configure --help 查看,這里使用的參數(shù)如下:
--prefix 安裝到的目錄
--enable-fpm 開始 fpm 模式,nginx 下必需開啟
--enable-fpm-user fpm 的啟動賬戶
--enable-fpm-group fpm 的啟動賬戶組
--with-openssl開啟 openssl
--with-libxml-dir 開啟 libxml
--with-zlib 開啟 zlib
--enable-mbstring開啟 mbstring
--with-mysqli=mysqlnd 開啟 mysqli
--with-pdo-mysql 開啟 pdo mysql
--with-gd 開啟gd庫
--enable-sockets 開啟 sockets
--with-curl 開啟 curl
--enable-maintainer-zts 開啟 maintainer zts,以后安裝多線程的話,這個必須開啟
[root@localhost libxml2-2.9.1]# cd /www/lnmp/php-7.1.1
[root@localhost php-7.1.1]# ./configure --prefix=/www/source/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysqli=mysqlnd --enable-mysqlnd --with-pdo-mysql=/www/source/mysql/ --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-sockets --with-curl --enable-maintainer-zts
[root@localhost php-7.1.1]# make
[root@localhost php-7.1.1]# make test // 測試完之后,輸入 n 不用創(chuàng)建
[root@localhost php-7.1.1]# make install
環(huán)境配置
php 配置
[root@localhost php-7.1.1]# cd /www/source/php/
[root@localhost php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@localhost php]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@localhost php]# cp /www/lnmp/php-7.1.1/php.ini-production lib/php.ini
啟動 php-fpm
[root@localhost php]# /www/source/php/sbin/php-fpm
nginx 配置
[root@localhost php]# cd /www/source/nginx/conf/
[root@localhost conf]# vi nginx.conf
將 nginx.conf 中的 server 保存成如下
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root /www/web;
index index.html index.php;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME /www/web$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
啟動 nginx
[root@localhost conf]# /www/source/nginx/sbin/nginx