LNMP编译安装

警告
本文最后更新于 2022-07-01,文中内容可能已过时。

摘要

Nginx,MySQL编译安装过程略

1
wget http://cn2.php.net/distributions/php-7.2.8.tar.gz
1
tar -xzf php-7.2.8.tar.gz
1
yum -y install bzip2-devel freetype-devel gcc gmp-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel make net-snmp-devel libmcrypt-devel openssl-devel readline-devel libxslt-devel
 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
cd php-7.2.8
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysqli \
--with-pdo-mysql \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-curl \
--with-gd \
--with-gmp \
--with-zlib \
--with-xmlrpc \
--with-openssl \
--without-pear \
--with-snmp \
--with-gettext \
--with-mhash \
--with-libxml-dir=/usr \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-xml \
--enable-fpm  \
--enable-ftp \
--enable-bcmath \
--enable-soap \
--enable-shmop \
--enable-sysvsem \
--enable-sockets \
--enable-inline-optimization \
--enable-maintainer-zts \
--enable-mbregex \
--enable-mbstring \
--enable-pcntl \
--enable-zip \
--disable-fileinfo \
--disable-rpath \
--enable-libxml \
--enable-opcache \
--enable-mysqlnd \

--with-ldap \ #如果不添加这两项,要是安装zabbix监控时候,会有提示还得需要再次编译,如果不安装zabbix,也可以忽略
--with-ldap-sasl \

错误:configure: error: Unable to locate gmp.h

解决:yum install gmp-devel

错误:configure: error: Cannot find ldap libraries in /usr/lib.

解决:cp -frp /usr/lib64/libldap* /usr/lib/

错误:configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

解决:yum install net-snmp-devel

1
make && make install
1
2
3
4
/usr/bin/ld: ext/ldap/.libs/ldap.o: undefined reference to symbol 'ber_strdup'
//usr/lib64/liblber-2.4.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1

解决:vi Makefile

在以EXTRA_LIBS开头的一行结尾添加-llber

https://img.bwcxtech.com/img/20200928164307.png

1
2
3
4
5
#移动php配置文件的位置,并修改名称
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
#复制php.ini文件
cp /root/php-7.2.8/php.ini-production /usr/local/php/etc/php.ini
1
vi /usr/local/php/etc/php.ini
1
2
3
post_max_size = 8M
max_execution_time = 300
max_input_time = 300
1
vi /usr/local/php/etc/php-fpm.conf

找到以下内容并修改:

1
2
3
4
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
cat > /usr/lib/systemd/system/php-fpm.service <<'EOF'
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
1
systemctl start php-fpm

nginx中添加如下配置即可解析php页面

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