您的位置:首页 > 运维架构 > Nginx

LAMP环境搭建系列之六:Nginx运行php-fpm

2017-11-21 00:47 441 查看
先安装php在说:

// 安装加密和转码依赖库
cd /data/ide
tar zxvf libmcrypt-2.5.8.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
tar zxvf libiconv-1.14.tar.gz

cd /data/ide/libmcrypt-2.5.8
./configure
make && make install

cd /data/ide/mhash-0.9.9.9
./configure
make && make install

cd /data/ide/mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/lib ./configure
make && make install

cd /data/ide/libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install

// 更新动态链接库,添加 /usr/local/lib
vi /etc/ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
:wq
ldconfig

// 创建php安装目录和配置文件目录
mkdir /data/server/php
mkdir /data/server/php/etc

cd /data/ide
tar zxvf php-5.6.32.tar.gz
cd php-5.6.32

./configure --prefix=/data/server/php \
--with-config-file-path=/data/server/php/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-sockets \
--enable-zip \
--enable-calendar \
--enable-intl \
--enable-soap \
--enable-xml \
--enable-ftp \
--enable-shmop \
--enable-sysvsem \
--enable-mbstring \
--enable-exif \
--enable-opcache \
--with-gettext \
--with-zlib \
--with-bz2 \
--with-iconv-dir=/usr/local/libiconv \
--with-gd \
--with-xmlrpc \
--with-curl \
--with-mhash \
--with-mcrypt \
--with-openssl \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-libxml-dir \
--disable-ipv6 \
--disable-debug \
--disable-rpath

make && make install
我们先把php配置文件设置一下,顺便修改时区!

cp /data/ide/php-5.6.32/php.ini-production /data/server/php/etc/php.ini
vi /data/server/php/etc/php.ini
date.timezone = PRC
:wq
rm -rf /etc/php.ini
ln -s /data/server/php/etc/php.ini /etc/php.ini
然后我们还需要设置php-fpm 配置文件,解注释pid即可!

cp /data/server/php/etc/php-fpm.conf.default /data/server/php/etc/php-fpm.conf
vi /data/server/php/etc/php-fpm.conf
user = nginx
group = nginx
pid = run/php-fpm.pid
:wq
我们提前设置web目录为/data/www,且下面放置一个phpinfo();的脚本文件index.php !

接下来我们配置Nginx:

chown -R nginx:nginx /data/www

vi /data/server/nginx/conf/nginx.conf

location / {
root   /data/www;								# 修改目录
index  index.html index.php;						# 修改引导文件
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root           /data/www;							# 修改目录
index 	   index.html index.php;					# 修改引导文件
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;		# 替换成 $document_root
include        fastcgi_params;
}


其实Nginx的配置文件里面已经有了php的配置,只是注释状态。

我们只需要解注释,并修改web目录和引导文件,最重要的修改时将 /scripts 替换成 $document_root

完成了,启动 php-fpm 和 nginx 就能访问了。

最后做一下随机启动设置:

vi /etc/rc.d/rc.local

/data/serve
4000
r/php/sbin/php-fpm
/data/server/nginx/sbin/nginx

:wq




点击下载用到的源码包:  http://download.csdn.net/download/konkon2012/10126484
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: