1 安装依赖

1
2
3
4
5
# 添加epel
yum install epel-release
yum update
# 添加依赖包
yum -y install systemtap-sdt-devel libxml2 libxml2-devel openssl-devel libcurl-devel enchant-devel libpng-devel libicu-devel libmcrypt-devel recode-devel net-snmp-devel libtidy-devel autoconf readline-devel libtidy-devel aspell-devel unixODBC-devel libicu-devel libc-client-devel freetype-devel libXpm-devel libpng-devel install libvpx-devel enchant-devel libcurl-devel libc-client-devel openldap-devel openldap postgresql-devel curl-devel libxslt-devel bzip2-devel db4-devel libjpeg-devel gmp-devel sqlite-devel pcre-devel mysql-devel pspell-devel gcc gcc-c++ make autoconf cmake wget oniguruma oniguruma-devel

2 配置及安装

2.1 下载php源码

1
2
3
wget https://www.php.net/distributions/php-7.4.28.tar.gz
tar -zxf php-7.4.28.tar.gz
cd php-7.4.28

2.2 配置扩展

1
'./configure' '--prefix=/usr/local/php' '--sharedstatedir=/data/php' '--localstatedir=/data/php' '--enable-fpm' '--enable-phpdbg' '--enable-phpdbg-webhelper' '--enable-phpdbg-debug' '--disable-debug' '--with-layout=GNU' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--disable-ipv6' '--enable-dtrace' '--enable-libxml' '--with-openssl' '--with-pcre-regex' '--with-sqlite3' '--with-zlib' '--enable-bcmath' '--with-bz2' '--enable-calendar' '--enable-ctype' '--with-openssl=shared,/usr/local/openssl' '--with-curl=shared,/usr/local/curl' '--with-curl' '--enable-dom' '--with-enchant' '--enable-exif' '--enable-fileinfo' '--enable-filter' '--enable-ftp' '--with-gd' '--with-webp-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib-dir' '--with-xpm-dir' '--with-freetype-dir' '--enable-gd-native-ttf' '--with-gettext' '--with-gmp' '--with-mhash' '--enable-hash' '--with-iconv' '--enable-json' '--enable-mbstring' '--with-mcrypt' '--with-mysqli=mysqlnd' '--enable-opcache' '--enable-opcache-file' '--enable-huge-code-pages' '--enable-pcntl' '--enable-pdo' '--with-pdo-mysql=mysqlnd' '--with-pdo-pgsql' '--with-pdo-sqlite' '--with-pgsql' '--enable-phar' '--enable-posix' '--with-readline' '--with-recode' '--enable-session' '--enable-shmop' '--enable-simplexml' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-tidy' '--enable-tokenizer' '--enable-xml' '--enable-xmlreader' '--with-xmlrpc' '--enable-xmlwriter' '--with-xsl' '--enable-zip' '--enable-mysqlnd' '--enable-mysqlnd-compression-support' '--with-pear'

2.3 编译安装

1
2
3
make && make install
## 完成安装之后可以通过以下命令查看安装的PHP扩展
php -m

2.4 nginx添加模块

(1)LuaJIT(lua-nginx-module)

首先在Linux本地安装LuaJIT:

1
2
3
4
5
6
git clone https://github.com/openresty/luajit2 /tmp/luajit2
cd /tmp/luajit2
make && make install PREFIX=/usr/local/luajit
echo "export LUAJIT_LIB=/usr/local/luajit/lib" >> /etc/profile
echo "export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1" >> /etc/profile
source /etc/profile

然后下载对应的压缩包:

1
git clone https://github.com/openresty/luajit2

在编译nginx的时候,添加如下配置:

1
./configure ...  --add-module=/usr/local/nginx/modules/lua-nginx-module

(2)ngx_devel_kit

下对应的压缩包:

1
git clone https://github.com/vision5/ngx_devel_kit.git /usr/local/nginx/modules/ngx_devel_kit

在编译nginx的时候,添加如下配置:

1
./configure ... --add-module=/usr/local/nginx/modules/ngx_devel_kit

(3)nginx_upstream_check_module

1
git clone https://github.com/xiaokai-wang/nginx_upstream_check_module.git /usr/local/nginx/modules/nginx_upstream_check_module

在编译nginx的时候,添加如下配置:

1
./configure ... --add-module=/usr/local/nginx/modules/nginx_upstream_check_module-master

3 编译安装FAQ

1
2
3
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
复制代码 代码如下:
yum -y install libxslt-devel
1
2
3
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
复制代码 代码如下:
yum -y install net-snmp-devel
1
2
3
configure: error: Please reinstall readline - I cannot find readline.h
复制代码 代码如下:
yum -y install readline-devel
1
2
3
configure: error: Cannot find pspell
复制代码 代码如下:
yum -y install aspell-devel
1
2
3
checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!
复制代码 代码如下:
yum -y install unixODBC-devel
1
2
3
configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.
复制代码 代码如下:
yum -y install libicu-devel
1
2
3
configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.
复制代码 代码如下:
yum -y install libc-client-devel
1
2
3
configure: error: freetype.h not found.
复制代码 代码如下:
yum -y install freetype-devel
1
2
3
configure: error: xpm.h not found.
复制代码 代码如下:
yum -y install libXpm-devel
1
2
3
configure: error: png.h not found.
复制代码 代码如下:
yum -y install libpng-devel
1
2
3
configure: error: vpx_codec.h not found.
复制代码 代码如下:
yum -y install libvpx-devel
1
2
3
configure: error: Cannot find enchant
复制代码 代码如下:
yum -y install enchant-devel
1
2
3
configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/
复制代码 代码如下:
yum -y install libcurl-devel
1
2
3
4
5
6
7
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
复制代码 代码如下:
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
1
2
3
Cannot find imap
复制代码 代码如下:
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
1
2
3
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.
复制代码 代码如下:
yum -y install libc-client-devel
1
2
3
4
Cannot find ldap.h
复制代码 代码如下:
yum -y install openldap
yum -y install openldap-devel
1
2
3
configure: error: Cannot find ldap libraries in /usr/lib
复制代码 代码如下:
cp -frp /usr/lib64/libldap* /usr/lib/
1
2
3
configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
复制代码 代码如下:
yum -y install postgresql-devel
1
2
3
configure: error: Please reinstall the lib curl distribution
复制代码 代码如下:
yum -y install curl-devel
1
2
3
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
复制代码 代码如下:
yum -y install net-snmp-devel
1
2
3
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
复制代码 代码如下:
yum -y install libxslt-devel
1
2
3
4
5
checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution

Fix:
复制代码 代码如下:
yum -y install bzip2-devel
1
2
3
4
5
checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/

Fix:
复制代码 代码如下:
yum -y install curl-devel
1
2
3
4
5
checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).

Fix:
复制代码 代码如下:
yum -y install db4-devel
1
2
3
4
5
checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.

Fix:
复制代码 代码如下:
yum -y install libjpeg-devel
1
2
3
4
5
checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.

Fix:
复制代码 代码如下:
yum -y install libpng-devel
1
2
3
4
5
6
checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=

configure: error: freetype.h not found.
Fix:
复制代码 代码如下:
Reconfigure your PHP with the following option. --with-xpm-dir=/usr
1
2
3
4
5
checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.

Fix:
复制代码 代码如下:
yum -y install libXpm-devel
1
2
3
4
5
checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h

Fix:
复制代码 代码如下:
yum -y install gmp-devel
1
2
3
4
5
checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Fix:
复制代码 代码如下:
yum -y install libc-client-devel
1
2
3
4
5
checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h

Fix:
复制代码 代码如下:
yum -y install openldap-devel
1
2
3
4
5
checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!

Fix:
复制代码 代码如下:
yum -y install unixODBC-devel
1
2
3
4
5
checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:
复制代码 代码如下:
yum -y install postgresql-devel
1
2
3
4
5
checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution

Fix:
复制代码 代码如下:
yum -y install sqlite-devel
1
2
3
4
5
checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell

Fix:
复制代码 代码如下:
yum -y install aspell-devel
1
2
3
4
5
6
7
checking whether to enable UCD SNMP hack… yes checking for default_store.h… no

checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.

Fix:
复制代码 代码如下:
yum -y install net-snmp-devel
1
2
3
4
5
checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:
复制代码 代码如下:
yum -y install libxslt-devel
1
2
3
4
5
configure: error: xml2-config not found. Please check your libxml2 installation.

Fix:
复制代码 代码如下:
yum -y install libxml2-devel
1
2
3
4
5
checking for PCRE headers location… configure: error: Could not find pcre.h in /usr

Fix:
复制代码 代码如下:
yum -y install pcre-devel
1
2
3
4
5
configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!

Fix:
复制代码 代码如下:
yum -y install mysql-devel
1
2
3
4
5
checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h' not found!

Fix:
复制代码 代码如下:
yum -y install unixODBC-devel
1
2
3
4
5
checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:
复制代码 代码如下:
yum -y install postgresql-devel
1
2
3
4
5
configure: error: Cannot find pspell

Fix:
复制代码 代码如下:
yum -y install pspell-devel
1
2
3
4
5
configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

Fix:
复制代码 代码如下:
yum -y install net-snmp-devel
1
2
3
4
5
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:
复制代码 代码如下:
yum -y install libxslt-devel
1
2
3
4
5
./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

Fix:
复制代码 代码如下:
yum install gd gd-devel
1
2
3
4
5
./configure: error: the GeoIP module requires the GeoIP library.

Fix:
复制代码 代码如下:
yum install geoip-devel
1
2
3
4
5
6
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.

Fix:
复制代码 代码如下:
yum install gperftools
1
2
3
4
5
6
编译nginx时出现了下面的告警:
nginx "--with-ipv6" option is deprecated

Fix:
查阅相关文档,原来最新版的nginx编译不需要添加--with-ipv6命令
最新版的nginx默认已经自带ipv6模块
1
2
3
4
5
6
7
8
nginx /bin/sh: line 0: cd: /usr/local/pcre-8.35: No such file or directory

用make编译nginx的时候提示如下错误:
/bin/sh: line 0: cd: /usr/local/pcre-8.35: No such file or directory
objs/Makefile:1133: recipe for target ‘/usr/local/pcre-8.35/Makefile’ failed
make[1]: *** [/usr/local/pcre-8.35/Makefile] Error 1
make[1]: Leaving directory ‘/root/Downloads/nginx-1.6.2’
Makefile:8: recipe for target ‘build’ failed
  • 使用执行查看相关参数如何填写:./configure --help | grep pcre
  • 其中:--wite-pcre = DIR set path to pcre library sources(设置pcre库的源路径),这是因为我们刚装的pcre库未帮它设置我们当前的文件路径.你需要看下pcre-8.35的目录,
  • 然后执行:
    ./configure --prefix=/home/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/pcre-8.35
    /home/nginx
    • 不是你解压包后的目录,是你新增的目录,用来安装nginx
    • /home/pcre-8.35是你的pcre目录
    • 成功后就可以执行nginx安装指令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
编译安装nginx时pcre模块报错的解决

CentOS 6.4 x86_64系统,编译安装nginx 1.4.5。

./configure时先是提示需要pcre的lib文件。用rpm -qa | grep pcre看了一下,pcre-7.8-6.el6.x86_64是已经安装过的。

于是用--with-pcre=/lib64指定了pcre的.so文件路径。但是在make的时候提示如下错误

make -f objs/Makefile
make[1]: Entering directory `/usr/local/src/nginx-1.4.5′
cd /usr/local/pcre /
       && if [ -f Makefile ]; then make distclean; fi /
       && CC="gcc" CFLAGS="-O2 -fomit-frame-pointer -pipe " /
       ./configure –disable-shared
/bin/sh: line 2: ./configure: No such file or directory
make[1]: *** [/usr/local/pcre/Makefile] Error 127
make[1]: Leaving directory `/usr/local/src/nginx-1.4.5′
make: *** [build] Error 2

用./configure --help看了一下,原来“--with-pcre=”参数要指定的是源码文件。百度了一下也有说是要下个pcre的源码包指定路径过去。

我觉得既然已经安装过一个pcre了,还要在编译安装一个实在有点儿蛋疼。。所以自己倒腾了一下,发现其实并不用再找源码包编译,只要把pcre-devel装上就OK。安装完成后,./configure参数改成--with-pcre,不要=和后面的路径。

还有SSL的支持也是需要openssl-devel的。(这个yum装把,用rpm会被依赖关系搞到蛋疼)

总结一下,nginx编译安装基本上需要以下几个东东:

1.gcc-----------------必不可少的
2.zlib-----------------gzip需要
3.openssl(包括openssl-devel)-----SSL支持需要
4.pcre(包括pcre-devel)--------让nginx支持正则表达式
1
2
3
4
checking for BZip2 in default path... not found configure: error: Please reinstall

Fix:
yum install bzip2-devel.x86_64 -y
1
2
3
4
No package 'sqlite3' found

Fix:
sudo yum install sqlite-devel
1
2
3
4
5
6
7
8
9
10
checking for LuaJIT 2.x ... not found

Fix:
安装luajit2:
git clone https://github.com/openresty/luajit2.git /tmp/luajit2
cd /tmp/luajit2
make && make install PREFIX=/usr/local/luajit
echo "export LUAJIT_LIB=/usr/local/luajit/lib" >> /etc/profile
echo "export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1" >> /etc/profile
source /etc/profile
1
2
3
4
5
./configure: error: no /usr/local/nginx/modules/naxsi/config was found

Fix:
地址写错了,应该是naxsi里面的naxsi_Src目录
./configure ... --add-module=/usr/local/nginx/modules/naxsi/naxsi_src

Hi,
It seems you provided a wrong path to nginx, you have to provide the path of the naxsi_src directory (which would be /home/ubuntu/nginxmodule/naxsi-0.54/naxsi_src/ in your case).

3.1 nginx服务器启动找不到libluajit-5.1.so解决方法

解决过程
查找本地libluajit-5.1.so.2共享库文件

1
find / -name libluajit-5.1.so.2

如果找到此文件

1
2
3
cp /文件路径/libluajit-5.1.so.2 /usr/local/lib/
echo "/usr/local/lib" >>/etc/ld.so.conf
/sbin/ldconfig

找不到此文件
安装luajit

1
2
3
4
5
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar xf LuaJIT-2.0.4
cd LuaJIT-2.0.4
make && make install
/sbin/ldconfig

启动nginx即可

3.2 CentOS安装Nginx,及编译常见错误

step1:

1
cd nginx-1.17.5/

step2:

如果编译成功,则显示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library

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"

step3:

1
make

如果编译成功,则显示:

1
make[1]: Leaving directory `/data/nginx-1.17.5'

step4:

1
make install

3.3 nginx使用openresty时failed to load the resty.core module

报错信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from openresty.org/en/download.html (reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file './resty/core.lua'
no file '/usr/local/share/luajit-2.1.0-beta3/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /usr/local/nginx/conf/nginx.conf:222

原因分析:

1
2
3
4
5
找不到lualib库和resty模块,默认到/usr/local/lib/ 去找lualib,然而在编译安装OpenResty时lualib库默认放到/usr/local/openresty/lualib
$ ln -s /usr/local/openresty/lualib /usr/local/lib/lua
$ ln -s /usr/local/openresty/lualib/resty /usr/local/lib

如果是之前已配置“ln -s /usr/local/openresty/lualib/resty /usr/local/lib”,本次执行“/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf”仍报上述错误,则删除已有的软连接,重新执行“ln -s /usr/local/openresty/lualib/resty /usr/local/lib”

解决:

1
2
3
4
5
6
 # cd /usr/local/lib
# ls
libluajit-5.1.a libluajit-5.1.so libluajit-5.1.so.2 libluajit-5.1.so.2.1.0 lua pkgconfig resty
# rm -rf ./resty
# ln -s /usr/local/openresty/lualib/resty /usr/local/lib
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

nginx: [alert] detected a LuaJIT version which is not OpenResty’s; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty’s LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)

nginx添加lua模块,需要准备两个模块:

  • ngx_devel_kit: NDK(nginx development kit)模块是一个拓展nginx服务器核心功能的模块,第三方模块开发可以基于它来快速实现。NDK提供函数和宏处理一些基本任务,减轻第三方模块开发的代码量。
  • lua-nginx-module: 将Lua的功能嵌入到Nginx HTTP服务器中。
1
2
3
4
5
6
$ mkdir ngx_module
$ wget https://github.com/vision5/ngx_devel_kit/archive/v0.3.1.tar.gz
$ tar -xvf v0.3.1.tar.gz

$ wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz
$ tar -xvf v0.10.14.tar.gz

目前lua-nginx-module的最新release版本是v0.10.19,使用该版本在测试过程中遇到报错如下:

1
2
3
4
5
6
7
8
9
10
11
12
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file './resty/core.lua'
no file '/usr/local/share/luajit-2.1.0-beta3/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /usr/local/src/nginx/conf/nginx.conf:117

以下链接给出了答案,用lua-nginx-module-0.10.14,不要用lua-nginx-module-0.10.19

测试是否安装成功

nginx.conf配置文件添加以下代码:

1
2
3
location /hello_lua {
content_by_lua 'ngx.say("hello, lua!")';
}

通过curl进行测试:

1
2
$ curl http://127.0.0.1/hello_lua
hello, lua!

3.4 Nginx启动报错[emerg] getpwnam(“nginx”) failed

1
2
3
4
[root@jdev03v conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] getpwnam("nginx") failed
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

原因:Nginx编译的时候指定了用户组和用户,但是系统中并没有这个用户导致的问题

解决方法:新建相应的用户组和用户名,或者不指定用户组和用户名重新编译一次Nginx

1
2
groupadd nginx
useradd -g nginx -s /sbin/nologin nginx

3.5 安装nginx+lua时提示:./configure: error: ngx_http_lua_module requires the Lua library.

上回在安装nginx+lua时过程中,在执行./configure命令时提示错误: error: ngx_http_lua_module requires the Lua library,而我确实已经安装luajit(LuaJIT:LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language. lua的高效率版本)。在执行.configure时也导入了export LUAJIT_LIB和export LUAJIT_INC的目录路径。如下:

1
2
export LUAJIT_LIB=/opt/modules/luajit/lib
export LUAJIT_INC=/opt/modules/luajit/include/luajit-2.0
1
2
Fix:
yum install -y lua-devel

lua-devel:Development files for lua,即是lua的开发包,在centos里很多时候都需要安装这么一个开发包的东西:*-devel,记得之前安装过一个python-devel。与此有类似。

如果make的时候出现ngx_http_lua_socket_udp.h:34: 错误:expected specifier-qualifi。可尝试换个lua-nginx-module版本进行编译。

3.6 安装nginx环境(含lua)时遇到报错ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory的解决

下面是安装nginx+lua环境时使用的相关模块及版本,ngx_devel_kit和lua-nginx-module模块用的都是github上最新的模块.并进行了LuaJIT的安装。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Install nginx by 2019-12-12
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
useradd -s /sbin/nologin -M nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.14.2.tar.gz
wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz
wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz\
git clone git://github.com/yzprofile/ngx_http_dyups_module.git
tar zxf v0.3.0.tar.gz
tar zxf LuaJIT-2.1.0-beta3.tar.gz
tar zxf v0.10.14.tar.gz
tar zxf nginx-1.14.2.tar.gz
yum -y install lua-devel
cd LuaJIT-2.1.0-beta3
make && make install
cd ..
cd nginx-1.14.2

./configure --prefix=/usr/local/nginx --sbin-path=/usr/bin/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-pcre --with-http_stub_status_module --with-http_addition_module --with-http_gzip_static_module --with-file-aio --with-http_dav_module --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.14 --add-module=../ngx_http_dyups_module
make
make install
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@lua src]# ll
total 3520
-rw-r--r-- 1 root root 1213 Dec 12 17:12 install-nginx.sh
drwxr-xr-x 6 nginx nginx 100 May 2 2017 LuaJIT-2.1.0-beta3
-rw-r--r-- 1 root root 1025180 May 2 2017 LuaJIT-2.1.0-beta3.tar.gz
drwxrwxr-x 10 root root 225 Feb 24 2019 lua-nginx-module-0.10.14
-rw-r--r-- 1 root root 829900 Dec 12 17:23 lua-nginx-module-master.zip
drwxr-xr-x 9 1001 1001 186 Dec 12 16:57 nginx-1.14.2
-rw-r--r-- 1 root root 1015384 Dec 4 2018 nginx-1.14.2.tar.gz
drwxrwxr-x 9 root root 221 May 10 2016 ngx_devel_kit-0.3.0
drwxr-xr-x 4 root root 187 Dec 12 17:04 ngx_http_dyups_module
-rw-r--r-- 1 root root 654097 Dec 12 16:56 v0.10.14.tar.gz
-rw-r--r-- 1 root root 66455 Dec 12 16:56 v0.3.0.tar.gz

  .configure执行是成功的,但是在进行make的时候遇到报错:ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory,详细报错内容如下:

1
2
3
4
5
6
7
8
9
In file included from ../lua-nginx-module-0.10.15/src/ngx_http_lua_script.h:11:0,
from ../lua-nginx-module-0.10.15/src/ngx_http_lua_script.c:13:
../lua-nginx-module-0.10.14/src/ngx_http_lua_common.h:20:20: fatal error: luajit.h: No such file or directory
#include <luajit.h>
^
compilation terminated.
make[1]: *** [objs/addon/src/ngx_http_lua_script.o] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.14.2'
make: *** [build] Error 2

解决方法:把lib的路径写入/etc/profile中

1
2
3
4
# vim /etc/profile
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/user/local/include/luajit-2.1
# source /etc/profile

 重新编译即可成功! 

1
2
3
4
5
6
7
8
9
10
11
[root@lua src]# nginx
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
[root@lua src]# find / -name libluajit-5.1.so.2
/usr/local/lib/libluajit-5.1.so.2
[root@lua src]# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
[root@lua src]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/bin/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-pcre --with-http_stub_status_module --with-http_addition_module --with-http_gzip_static_module --with-file-aio --with-http_dav_module --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.14 --add-module=../ngx_http_dyups_module

3.7 php安装zip扩展

1
2
3
4
5
6
wget http://pecl.php.net/get/zip-1.20.0.tgz
tar -zxf zip-1.20.0.tgz
cd zip-1.20.0
/usr/local/php/bin/phpize
.configure --with-php-config=/usr/local/php/bin/php-config
make && make install

.configure的时候可能会遇到的问题:

1
2
3
4
5
6
7
8
问题:
checking for libzip... not found
configure: error: Please reinstall the libzip distribution

原因:
这是因为没有安装libzip包,安装libzip即可
解决:
yum install -y libzip
1
2
3
4
5
6
7
8
9
问题:
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11

原因:
这是因为libzip包版本过低,更新到高版本即可
解决:
yum remove libzip libzip-devel #先卸载
rpm -ivh https://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm # 切换源
yum install wlibzip # 重新安装

然后在.configure即可成功。

Reference

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号