前言
环境版本如下
- 系统:CentOS 7 x86_64
- Nginx:nginx-1.7.12
- PHP:php-5.5.23
安装Nginx
下载nginx
cd /usr/local/src/
wget http://nginx.org/download/nginx-1.7.12.tar.gz
tar zxvf nginx-1.7.12.tar.gz
cd nginx-1.7.12
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
如果中途报错了,安装相应的依赖包就可以了。如果相应的依赖包不存在,换一个镜像源试试
#换成阿里云的镜像源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup //备份
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yun makecache //生成缓存
如果还没找到相应的依赖包,试试以下的命令
yum install epel-release //扩展包更新包
yum update //更新yum源
如果还没有相应的依赖包,那就只能去官网找找问题
编译nginx
make
make install
网上找一个nginx的启动脚本
vim /etc/init.d/nginx //将找到的启动脚本复制进去
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
#如果想开机启动
chkconfig nginx on
修改nginx的配置文件,进入/usr/local/nginx/conf/下,编辑nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启nginx
安装PHP
前言
1.PHP-FPM是一个PHP FastCGI管理器。是只用于PHP的。PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)对于PHP 5.3.3之前的PHP来说,是一个补丁包,旨在将FastCGI进程管理整合进PHP包中。PHP 5.3.3已经集成php-fpm了,不再是第三方包了。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程,可以平滑重载PHP配置。在./configure的时候带-enable-fpm参数即可开启php-fpm
2.针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的
开始安装php
cd /usr/local/src
wget http://am1.php.net/distributions/php-5.5.23.tar.gz
tar zxf php-5.5.23.tar.gz
useradd -s /sbin/nologin php-fpm //创建相应账户
cd php-5.5.23.tar.gz
#配置编译参数
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--enable-bcmath \
--enable-mbstring \
--enable-sockets \
--with-gd \
--with-libxml-dir=/usr/local \
--with-gettext
中途出问题了安装相应的依赖包即可
编译php
make
make install
修改配置文件
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
加入以下的代码
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = 127.0.0.1:9000 ###/tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
检查配置文件以及启动php-fpm
#检查配置文件
/usr/local/php/sbin/php-fpm -t
#复制启动文件
cp /usr/local/src/php-5.5.23/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start
#开机启动设置
chkconfig php-fpm on