CentOS6.x 下 LNMP环境搭建(准备篇) CentOS6.x 下LNMP环境搭建(一、安装 MySQL) CentOS6.x 下LNMP环境搭建(二、安装 Nginx) CentOS6
.
CentOS6.x 下 LNMP环境搭建(准备篇)
CentOS6.x 下 LNMP环境搭建(一、安装 MySQL)
CentOS6.x 下 LNMP环境搭建(二、安装 Nginx)
CentOS6.x 下 LNMP环境搭建(三、安装 PHP)
.3.1. 检查 MySQL、Nginx是否正常
# netstat -tlunp
3.2. 检查安装 PHP 所需的 lib 库
# rpm -qa zlib-devel libxm2-devel libjpeg-turbo-devel libpng-devel gd-devel libcurl-devel libxslt-devel freetype-develzlib-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 这个包,需要按照下面的步骤单独编译安装
.# 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. 安装
# 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 方式)
# cd /lnmp/server/php/etc/# lspear.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 wwwwww 2272 2270 0 00:39 ? 00:00:00 php-fpm: pool wwwroot 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 NAMEphp-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 程序请求访问
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; }}