0%

LNMP编译安装

Nginx,MySQL编译安装过程略

PHP编译安装

下载

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 gcc gcc-c++ gcc-g77 make libtool autoconf patch unzip automake libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl libmcrypt libmcrypt-devel libpng libpng-devel libjpeg-devel openssl openssl-devel gd-devel curl curl-devel libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl autoconf automake gmp-devel net-snmp-devel libaio*

生成配置文件

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

配置php配置文件

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

修改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

php-fpm服务化

修改php-fpm.conf

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

创建php-fpm服务文件

1
vi /usr/lib/systemd/system/php-fpm.service
1
2
3
4
5
6
7
8
9
10
11
12
13
[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

重新加载systemctll配置

1
systemctl daemon-reload

nginx配置

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;
}
-------------    本文结束  感谢您的阅读    -------------
请作者一杯咖啡。