本文使用源码编译安装,首先下载nginx和php压缩包
nginx:wget http://nginx.org/download/nginx-1.10.1.tar.gz
php:wget http://bg2.php.net/distributions/php-5.6.29.tar.gz
网上还有一种叫成需要下载缓存模块ngx_cache_purge
下载地址:wget http://labs.frickle.com/files/ngx_cache_purge-2.2.tar.gz
这里我没有使用缓存模块
执行命令
tar zxvf nginx-1.10.1.tar.gz #解压
cd nginx-1.10.1 #进入解压文件夹
./configure #这里我是用的是默认编译不建议使用,有条件的可以找找大神的配置方法
make
make install #安装
找到nginx配置文件,我这里路径是是/usr/local/nginx/conf/nginx.conf,配置nginx.conf文件
server {
listen 80;
server_name localhost;
charset utf-8;
root html;
index index.html index.htm index.php;
location / {
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
}
启动nginx命令(这段实在网上大神文章中找到的)
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:
ps aux|grep nginx
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx
2.重新加载配置文件:
当 nginx的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
如果你能看见nginx的欢迎页面证明nginx安装成功,我这里没有截图当时忘记了
安装PHP
执行命令
tar zxvf php-5.6.29.tar.gz
cd php-5.6.29
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql=/usr/bin/mysql --with-mysqli=/usr/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/bin/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-zlib-dir=/usr/local/zlib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype
make
make install
这里需要特殊说明一下,我安装的时候编译总是过不去报错:Please reinstall the mysql distribution网上找了很多文章没有解决自私研究编译代码发现
--with-pdo-mysql=/usr/bin/mysql #这里要配你系统中的实际路径
--with-mysqli=/usr/bin/mysql_config #这里要配你系统中的实际路径
--with-mysql-sock=/tmp/mysql.sock
PHP停止启动代码
killall php-fpm #停止php-fpm(没有killall命令可以用yum安装)
/usr/local/php/sbin/php-fpm #启动php-fpm
至此安装完成,哪位大神有更好的办法欢迎留言