Nginx高端成长之路我用 Linux系统运维

NGINX+PHP源码安装

2017-09-12  本文已影响60人  四冶读史

1.安装Nginx

安装依赖

yum -y install gcc gcc-c++ libxml2-devel curl-devel pcre-devel zlib-devel openssl-devel make

下载nginx

wget http://nginx.org/download/nginx-1.11.7.tar.gz

编译安装nginx

tar -zxvf nginx-1.11.7.tar.gz
cd nginx-1.11.7
./configure --prefix=/usr/local/nginx
make && make insatll

nginx启动设置

vi /usr/lib/systemd/system/nginx.service

复制如下内容:

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

保存退出
授予754的权限

cd /usr/lib/systemd/system 
chmod -R 754 nginx.service

启动nginx服务

systemctl start nginx.service

设置开机启动

systemctl enable nginx.service

检查安装
在浏览器中输入IP,如果出现welcome to nginx字样,则安装成功!

2.PHP环境搭建

下载php

wget http://mirrors.aorise.org:8000/php/php-5.3.28.tar.gz
tar -zxvf php-5.3.28.tar.gz
cd php-5.3.28

编译安装php

./configure  --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pcre-regex --with-iconv --with-zlib --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/png --with-freetype-dir=/usr/local/freetype --enable-fastcgi
make && make install

php启动设置

vi /usr/lib/systemd/system/php-fpm.service

复制如下内容:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

保存退出
授予754的权限

cd /usr/lib/systemd/system 
chmod 754 php-fpm.service

拷贝php-fpm.conf文件

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

启动php-fpm服务

systemctl start php-fpm.service

设置开机启动

systemctl enable php-fpm.service

3.Nginx配置

修改配置文件

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#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;
#}

如下:

location ~ \.php$ {
   root           html;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME /mnt/www$fastcgi_script_name;
   include       fastcgi_params;
}

参考地址:
http://www.jianshu.com/p/78e3b024fb8e

上一篇 下一篇

猜你喜欢

热点阅读