1. 编译安装openresty
准备相关软件包
1 | wget https://openresty.org/download/openresty-1.11.2.1.tar.gz |
解决依赖关系
1 | yum install -y gcc gcc-c++ perl-devel perl-ExtUtils-Embed openssl-devel postgresql-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel |
如果启用了–with-http_drizzle_module参数,则需要如下配置
1 | tar xzvf drizzle7-2011.07.21.tar.gz |
创建openresty运行用户
1 | groupadd www |
编译前配置
1 | ./configure --user=www --group=www --with-http_iconv_module --with-http_drizzle_module --with-http_postgres_module --with-threads --with-file-aio --with-ipv6 --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_perl_module --with-http_ssl_module --with-zlib=/root/soft/zlib-1.2.8 --with-pcre=/root/soft/pcre-8.38 --with-openssl=/root/soft/openssl-1.0.2j |
编译配置过程中如果出现如下错误
src/event/ngx_event_openssl.c: In function ‘ngx_ssl_connection_error’:
src/event/ngx_event_openssl.c:2048: error: ‘SSL_R_NO_CIPHERS_PASSED’ undeclared (first use in this function)
src/event/ngx_event_openssl.c:2048: error: (Each undeclared identifier is reported only once
src/event/ngx_event_openssl.c:2048: error: for each function it appears in.)
gmake[2]: *** [objs/src/event/ngx_event_openssl.o] Error 1
gmake[2]: Leaving directory `/root/soft/openresty-1.11.2.1/build/nginx-1.11.2’
gmake[1]: *** [build] Error 2
gmake[1]: Leaving directory `/root/soft/openresty-1.11.2.1/build/nginx-1.11.2’
gmake: *** [all] Error 2
主要原因是因为
The OpenSSL API has changed quite a bit in 1.1.0… this means that nginx needs some work to adapt.
openssl 1.1.0改变了太多,nginx暂时还不支持,版本换回1.0.x就行了。
编译安装
1 | gmake && gmake install |
为openresty提供启动脚本
1 | vim /etc/init.d/nginx |
启动服务
1 | service nginx start |
如果启动时报错:
1 | /usr/local/openresty/nginx/sbin/nginx |
检查是否库文件不存在
1 | ldd $(which /usr/local/openresty/nginx/sbin/nginx) |
结果发现确实
1 | libdrizzle.so.1 => not found |
检查/usr/local/{lib|lib64}目录下是否存在库文件,如果存在,则说明系统并没有加载库文件,我们需要手动指定系统加载。
在/etc/ld.so.conf.d/目录下新建任何以.conf为后缀的文件,在该文件中加入库文件所在的目录。
1 | vim /etc/ld.so.conf.d/openresty.conf |
然后执行ldconfig更新/etc/ld.so.cache文件,解决问题。
如果需要隐藏openresty/nginx版本,只需要编辑nginx.conf,在http配置中添加以下配置即可解决。
1 | server_tokens off; |
2. 编译安装php
解决依赖关系
1 | yum install -y libxml2-devel bzip2-devel libcurl-devel gd-devel gmp-devel libmcrypt-devel |
创建php安装位置
1 | mkdir /usr/local/php |
创建php-fpm运行用户
1 | groupadd www |
编译前配置
1 | ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-ftp --enable-zip --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --with-libxml-dir --with-xmlrpc --with-zlib-dir --with-gd --enable-gd-native-ttf --with-curl --enable-mbstring --enable-bcmath --enable-sockets --enable-exif --enable-fpm --with-mcrypt --with-mhash --with-gmp --enable-inline-optimization --with-openssl --with-pcre-dir --enable-soap --with-gettext |
编译安装
1 | make && make install |
为php提供配置文件
1 | cp php.ini-production /usr/local/php/etc/php.ini |
为php-fpm提供Sysv脚本并添加至服务列表设置开机启动
1 | cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm |
为php-fpm提供配置文件
1 | cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf |
编辑php-fpm配置文件,按需修改配置
1 | vim /usr/local/php/etc/php-fpm.conf |
启动php-fpm
1 | service php-fpm start |
3. 配置openresty支持php
修改nginx配置文件,启用php支持
1 | vim /usr/local/openresty/nginx/conf/nginx.conf |