CentOS6.x 下 LNMP環境搭建(1、安裝 MySQL)html
CentOS6.x 下 LNMP環境搭建(2、安裝 Nginx)mysql
CentOS6.x 下 LNMP環境搭建(3、安裝 PHP)sql
3.1. 檢查 MySQL、Nginx是否正常vim
# netstat -tlunp
3.2. 檢查安裝 PHP 所需的 lib 庫bash
# rpm -qa zlib-devel libxm2-devel libjpeg-turbo-devel libpng-devel gd-devel libcurl-devel libxslt-devel freetype-devel zlib-devel-1.2.3-29.el6.x86_64 # yum -y install zlib-devel libxm2-devel libjpeg-turbo-devel libpng-devel gd-devel libcurl-devel libxslt-devel freetype-devel
注:默認 yum 源沒有 libiconv-devel 這個包,須要按照下面的步驟單獨編譯安裝curl
# cd /root/src # wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz # tar -zxvf libiconv-1.14.tar.gz && cd libiconv-1.14 # ./configure --prefix=/usr/local/libiconv # make && make install 安裝其它額外庫 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo # yum -y install libmcrypt-devel mhash mcrypt
3.3. 安裝socket
# cd /root/src # tar zxvf php-5.5.36.tar.gz && cd php-5.5.36 # ./configure \ --prefix=/lnmp/server/php5.5.36 \ --with-config-file-path=/lnmp/server/php5.5.36/etc \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-exif \ --with-gd \ --enable-gd-native-ttf \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-gettext \ --with-iconv-dir=/usr/local/libiconv \ --enable-mbstring \ --with-mcrypt \ --with-mhash \ --with-openssl \ --enable-bcmath \ --enable-pcntl \ --enable-shmop \ --enable-sysvsem \ --enable-soap \ --with-libxml-dir \ --enable-sockets \ --with-curl \ --enable-ftp \ --with-zlib-dir \ --enable-zip \ --with-pear # ln -s /lnmp/server/php5.5.36/ /lnmp/server/php # ll php.ini* -rw-r--r-- 1 1001 1001 69236 5月 25 17:36 php.ini-development <------- 開發模式,更多開啓日誌、調試信息 -rw-r--r-- 1 1001 1001 69266 5月 25 17:36 php.ini-production <------- 生產模式 # cp php.ini-production /lnmp/server/php/etc/php.ini
3.4. 配置 PHP 服務(php-fpm 方式)php-fpm
# cd /lnmp/server/php/etc/ # ls pear.conf php-fpm.conf.default # cp php-fpm.conf.default php-fpm.conf # /lnmp/server/php/sbin/php-fpm <------- 啓動 php-fmp 服務 # ps -ef|grep php-fpm <------- 查看 php-fpm 啓動進程 root 2270 1 0 00:39 ? 00:00:00 php-fpm: master process (/lnmp/server/php5.5.36/etc/php-fpm.conf) www 2271 2270 0 00:39 ? 00:00:00 php-fpm: pool www www 2272 2270 0 00:39 ? 00:00:00 php-fpm: pool www root 2274 2227 0 00:39 pts/0 00:00:00 grep php-fpm # lsof -i :9000 <------- 查看 php-fpm 默認端口 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME php-fpm 2270 root 7u IPv4 12844 0t0 TCP localhost:cslistener (LISTEN) php-fpm 2271 www 0u IPv4 12844 0t0 TCP localhost:cslistener (LISTEN) php-fpm 2272 www 0u IPv4 12844 0t0 TCP localhost:cslistener (LISTEN) 設置 php-fpm 啓動腳本 # vim /etc/init.d/php-fpm 複製 php-fpm.sh 中的內容 進去 # chmod 755 /etc/init.d/php-fpm # service php-fpm start|stop|restart|reload|configtest
3.5. 配置 Nginx 支持 PHP 程序請求訪問url
server { listen 80; server_name localhost; root /lnmp/www/; index index.html index.htm index.php; location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } }