CentOS6.x 下 LNMP环境搭建(三、安装 PHP)

前端之家收集整理的这篇文章主要介绍了CentOS6.x 下 LNMP环境搭建(三、安装 PHP)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS6.x 下 LNMP环境搭建(准备篇)

CentOS6.x 下LNMP环境搭建(一、安装 MySQL)

CentOS6.x 下LNMP环境搭建(二、安装 Nginx)

CentOS6.x 下LNMP环境搭建(三、安装 PHP

3.1. 检查 @R_301_198@、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-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 这个包,需要按照下面的步骤单独编译安装

# 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-@R_301_198@=@R_301_198@nd \
--with-@R_301_198@i=@R_301_198@nd \
--with-pdo-@R_301_198@=@R_301_198@nd \
--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/
# 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 程序请求访问

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;
  }
}
原文链接:https://www.f2er.com/centos/380566.html

猜你在找的CentOS相关文章