NoesBlog Docs
搜索文档…
CentOS7 install Nginx+PHP7
安装编译组件
1
yum -y install gcc gcc-c++ autoconf automake libtool make cmake
Copied!
1
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
Copied!
下载Nginx编译包(此处使用我个人服务器的源,因为官方源偶尔需要token验证导致无法下载)
1
cd /opt
Copied!
1
wget http://file.noesblog.com/nginx-1.12.2.tar.gz
Copied!
解压nginx包
1
tar zxvf nginx-1.12.2.tar.gz
Copied!
添加用户
1
groupadd nginx
Copied!
1
useradd -g nginx -M nginx
Copied!
修改nginx用户为无法登陆
1
vi /etc/passwd
Copied!
修改此行
1
nginx:x:1000:1000::/home/nginx:/bin/bash
Copied!
变成如下内容:
1
nginx:x:1000:1000::/home/nginx:/sbin/nologin
Copied!
设置编译参数
1
cd /opt/nginx-1.12.2
Copied!
1
./configure --prefix=/opt/nginx \
2
--pid-path=/opt/nginx/run/nginx.pid \
3
--with-http_ssl_module \
4
--user=nginx \
5
--group=nginx \
6
--with-pcre \
7
--without-mail_pop3_module \
8
--without-mail_imap_module \
9
--without-mail_smtp_module
Copied!
开始编译(此处耗时较久,具体时间根据你的cpu性能决定)
1
make && make install
Copied!
查看版本信息
1
/opt/nginx/sbin/nginx -v
Copied!
nginx常用命令
1
启动Nginx
2
/opt/nginx/sbin/nginx
3
4
查看nginx服务
5
ps -ef | grep nginx
6
7
从容停止Nginx:
8
kill -QUIT 主进程号 # 如上一步中的 ps 命令输出的 29151,就是 Nginx的主进程号
9
10
快速停止Nginx:
11
kill -TERM 主进程号
12
13
强制停止Nginx:
14
pkill -9 nginx
15
16
平滑重启nginx
17
/opt/nginx/sbin/nginx -s reload
18
19
验证Nginx配置
20
/opt/nginx/sbin/nginx -t
Copied!

PHP7 install

1
cd /opt
Copied!
1
wget http://file.noesblog.com/php-7.2.1.tar.gz
Copied!
1
tar -xvzf php-7.2.1.tar.gz
Copied!
1
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
Copied!
1
yum install -y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-CPAN libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers png jpeg autoconf gcc cmake make gcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre-static openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2 ImageMagick-devel jpeg jpeg* pcre-dev* fontconfig libpng libxml2 zip unzip gzip
Copied!
1
cd /opt/php7
Copied!
1
./configure --prefix=/opt/php7 \
2
--with-config-file-path=/opt/php7/etc \
3
--with-config-file-scan-dir=/opt/php7/etc/php.d \
4
--with-mcrypt=/usr/include \
5
--enable-mysqlnd \
6
--with-mysqli \
7
--with-pdo-mysql \
8
--enable-fpm \
9
--with-fpm-user=nginx \
10
--with-fpm-group=nginx \
11
--with-gd \
12
--with-iconv \
13
--with-zlib \
14
--enable-xml \
15
--enable-shmop \
16
--enable-sysvsem \
17
--enable-inline-optimization \
18
--enable-mbregex \
19
--enable-mbstring \
20
--enable-ftp \
21
--enable-gd-native-ttf \
22
--with-openssl \
23
--enable-pcntl \
24
--enable-sockets \
25
--with-xmlrpc \
26
--enable-zip \
27
--enable-soap \
28
--without-pear \
29
--with-gettext \
30
--enable-session \
31
--with-curl \
32
--with-jpeg-dir \
33
--with-freetype-dir \
34
--enable-opcache
Copied!
1
make && make insatll
Copied!
1
cp /opt/php-7.2.1/php.ini-production /opt/php7/etc/php.ini
Copied!
1
cp /opt/php7/etc/php-fpm.conf.default /opt/php7/etc/php-fpm.conf
Copied!
1
cp /opt/php7/etc/php-fpm.d/www.conf.default /opt/php7/etc/php-fpm.d/www.conf
Copied!
1
cd /opt/php-7.2.1/sapi/fpm/
Copied!
1
cp init.d.php-fpm /etc/init.d/php-fpm
Copied!
1
chmod +x /etc/init.d/php-fpm
Copied!
1
chkconfig --add php-fpm
Copied!
1
chkconfig php-fpm on
Copied!
1
service php-fpm start
Copied!
1
vi /opt/nginx/conf/nginx.conf
Copied!
1
location ~ \.php$ {
2
root html;
3
fastcgi_pass 127.0.0.1:9000;
4
fastcgi_index index.php;
5
fastcgi_param SCRIPT_FILENAME /opt/nginx/html/$fastcgi_script_name;
6
include fastcgi_params;
7
}
Copied!
1
cd /opt/nginx/html/
Copied!
1
vi index.php
Copied!
1
<?php
2
phpinfo();
3
?>
Copied!
访问ip+/index.php查看结果
上传文件后执行
1
chown nginx:nginx -R html/
Copied!
赋予读写权限
最近更新 3yr ago
复制链接