您的位置:首页 > 运维架构 > Nginx

centOS7下编译安装nginx-1.12.2+php-7.1.9

2017-10-25 22:48 701 查看
nginx环境编译安装

zlib: 为nginx提供gzip模块,需要zlib库支持
openssl: 为nginx提供ssl功能
yum -y install gcc gcc-c++ autoconf automake libtool make cmakeyum -y install zlib zlib-devel openssl openssl-devel pcre-devel

pcre: 为支持地址重写rewrite功能
wget http://pcre/xxx/xxx/xxx最新版xxx.tar.gztar zxvf xxxx.tar.gzcd xxxx./configuremake install

创建用来运行nginx的用户及组:
groupadd nginxuseradd -g nginx -M nginx
-g参数为nginx用户指定了一个组。-M参数保证其不自动生成home目录。

禁用ssh登陆权限:
vim /etc/passwd
找到nginx,将后面的/bin/bash改为/sbin/nologin即可。

编译安装Nginx:
wget http://xxxxxxxxxx/nginx1.7.x.tar.gztar zxvf nginx1.7.x.tar.gzcd nginx1.7.x

执行./configure:
./configure --prefix=/opt/nginx \--pid-path=/opt/nginx/run/nginx.pid \--with-http_ssl_module \--user=nginx \ --group=nginx \--with-pcre \--without-mail_pop3_module
\--without-mail_imap_module \--without-mail_smtp_module
末尾三个是禁用nginx作为邮件代理服务器,我一般只用服务器作为网站或数据库的服务器,所以这里把它们禁用掉,你如果想搭建的是邮件服务器,那么就应该去阅读nginx搭建邮件服务器的教程。

你可以认真阅读一下./configure的结果,如果感觉不对,可以用./configure --help认真阅读一下
makemake install
make的地方有一个小技巧,如果服务器是双核,可以通过-j2来指定用双核进行编译,-j4代表4核编译。
安装到这里就结束了

运行nginx服务器:
cd /opt/nginxsbin/nginx

nginx服务的载入,如果一定要重启整个服务,那只能通过杀死nginx进程,然后在运行程序了
/opt/nginx/sbin/nginx -s reload

如果找不到pid文件
nginx -c /opt/nginx/conf/nginx.conf

使用service操作,nginx启动service.note
中文件放到/etc/ini.d/目录下,并执行:
ubnutu命令:
chmod +x nginx
update-rc.d nginx defaults

centerOS命令:
chmod +x nginx
chkconfig add nginx
chkconfig nginx on

现在可以使用下面的命令了,重新启动nginx会自动启动
service nginx reload

PHP7的编译安装

依赖环境:
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libXpm-devel

编译安装php7:
wget http://am1.php.net/get/php-7.0.0.tar.gz/from/this/mirrortar zvxf php-7.0.0.tar.gzcd php-7.0.0

mcrypt.h not found:
CentOS源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包
yum install -y epel-release
yum install -y libmcrypt-devel

centerOS可以直接用下面的安装(路径不同需自己修改):
./configure --prefix=/opt/php7 --with-config-file-path=/opt/php7/etc --with-config-file-scan-dir=/opt/php7/etc/php.d --with-libxml-dir= --with-png-dir --with-mcrypt
--with-xpm-dir--with-jpeg-dir --with-freetype-dir --with-gd --with-iconv --with-zlib --with-openssl --with-mysql --with-mysqli --enable-mysqlnd --with-curl --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-pdo --with-pdo-mysql --with-xmlrpc
--without-pear --with-gettext --enable-soap --enable-mbstring --enable-sockets --enable-inline-optimization --enable-mbregex --enable-xml --enable-sysvsem --enable-shmop --enable-pcntl --enable-zip --enable-soap --enable-session --enable-opcache --enable-ftp
--enable-gd-native-ttf

配置无误后执行:
make
make install
同样可以使用-j2

调整php配置:
cd /data/soft/php-7.0.0/
cp php.ini-production /opt/php7/etc/php.ini

编译LDAP:
cd /data/soft/php7/ext/ldap
/opt/php7/bin/phpize
./configure -with-ldap -with-php-config=/opt/php7/bin/php-config
make
make install

ldap报错:
cp -frp /usr/lib64/libldap* /usr/lib/

启用php-fpm服务

搞定配置文件:
cd /opt/php7/etcmv php-fpm.conf.default php-fpm.confmv php-fpm.d/www.conf.default php-fpm.d/www.conf

搞定php-fpm的服务载入:
cd /data/soft/php-7.0.0/sapi/fpmcp init.d.php-fpm /etc/init.d/php-fpmchmod +x /etc/init.d/php-fpmchkconfig --add php-fpmchkconfig php-fpm on

service php-fpm start来启用php-fpm
ps -ef | grep php-fpm看进程

nginx代理php实现访问
php-fpm走的是127.0.0.1:9000,外网是无法访问的,我们用nginx去代理9000端口执行php。

对nginx进行配置:
vim /opt/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配置:
service nginx reload

然后到/opt/nginx/html去写一个php文档,进行测试。
如果你的程序能够正常运行起来,用ip作为外网访问地址访问成功,那么恭喜你。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx ldap php centos