LNMP编译安装

摘要

Nginx,MySQL编译安装过程略

bash

wget http://cn2.php.net/distributions/php-7.2.8.tar.gz

bash

tar -xzf php-7.2.8.tar.gz

bash

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

bash

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

bash

make && make install

text

/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

bash

#移动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

bash

vi /usr/local/php/etc/php.ini

text

post_max_size = 8M
max_execution_time = 300
max_input_time = 300

bash

vi /usr/local/php/etc/php-fpm.conf

找到以下内容并修改:

bash

; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid

bash

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

bash

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;
}