安装nginx和php

安装nginx

1、安装依赖包

yum - y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel perl perl-devel perl-ExtUtils-Embe

2、检查系统中是否已经安装nginx,如果安装过需先卸载nginx

find / -name nginx
yum remove nginx

3、上传nginx包和解压文件(不要更改解压之后的文件名否则会产生conf/koi-win’ and `/usr/local/nginx/conf/koi-win’ are the same file错误

nginx下载链接

tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3

4、安装nginx默认安装在/usr/local/nginx

./configure –prefix=/usr/local/nginx 
–with-openssl=/usr/include (启用ssl) 
–with-pcre=/usr/include/pcre/ (启用正规表达式) 
–with-http_stub_status_module (安装可以查看nginx状态的程序) 
–with-http_memcached_module (启用memcache缓存) 
–with-http_rewrite_module (启用支持url重写)

./configure -- with-http_perl_module --with-ld-opt="-Wl,-E" --with-http_ssl_module

5、安装完成nginx的信息如下所示

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file:"/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

6、 安装 nginx

make && make install

7、启动、停止、重载nginx并且检查端口和检查配置

/usr/local/nginx/sbin/nginx
netstat -ntlp | grep 80
ps -ef | grep nginx
/usr/local/nginx/sbin/nginx –t
/usr/local/nginx/sbin/nginx –s stop
/usr/local/nginx/sbin/nginx –t reload

8、配置开机自启动* /etc/rc.d/rc.local文件后面加上/usr/local/nginx/sbin/nginx*

vim /etc/rc.d/rc. local

9、安装完成

安装php

1、下载依赖包

yum -y install libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg-devel

其他的依赖可以参考此url

wget ftp: //mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt- 2.5.7.tar.gz
./configure
make && make install

2、需要修改本地的配置文件

vim /etc/ld.so.conf.d/local.conf # 编辑库文件
/usr/local/ lib # 添加该行
ldconfig -v # 使之生效

3、上传php的包,解压,进入文件夹

tar -zxvf php-5.6.27.tar.gz

4、编译和安装

./configure --prefix=/usr/local/php --enable-fpm --with-mcrypt --enable-mbstring --enable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-gd --with-libdir=lib64 --with-jpeg-dir --with-freetype-dir --enable-calendar
make && make install

5、为php-fpm提供配置文件

cp /usr/local/phetc/php-fpm.conf.default /usr/local/phetc/php-fpm.conf
vim etc /php-fpm.conf

pid = /usr/local/php/var/run/php-fpm.pid 
pm.max_children = 300 
pm.start_servers = 10 
pm.min_spare_servers = 10 
pm.max_spare_servers = 50 
user = www 
group = www

6、创建登录用户

groupadd www
useradd -g www www

7、启动php-fpm

/usr/local/php/sbin/php-fpm
ps aux | grep php-fpm

8、nginx整合php

vim /usr/local/nginx/nginx.conf

下列内容取消注释

log_format main
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
#添加index.php
location / {
root html;
index index.php index.html index.htm;
}

下列内容更新

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}

9、重新载入配置文件

/usr/loca/nginx/sbin/nginx -s reload
 
vim /usr/local/nginx/html/index.php
 
<?php
phpinfo();
?>

10、浏览器里面访问测试成功

猜你喜欢

转载自www.cnblogs.com/haitao-liu/p/9057212.html