LNMP编译安装
目录
注意
本文最后更新于 2024-05-08,文中内容可能已过时。
摘要
Nginx,MySQL编译安装过程略
1 PHP编译安装
1.1 下载
wget http://cn2.php.net/distributions/php-7.2.8.tar.gz
1.2 解压
tar -xzf php-7.2.8.tar.gz
1.3 安装依赖
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.4 生成配置文件
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 \
1.4.1 异常处理
错误: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.5 编译安装
make && make install
1.5.1 异常处理
/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
1.6 配置php配置文件
#移动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.6.1 修改php.ini
vi /usr/local/php/etc/php.ini
post_max_size = 8M
max_execution_time = 300
max_input_time = 300
1.7 php-fpm服务化
1.7.1 修改php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
找到以下内容并修改:
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid
1.7.2 创建php-fpm服务文件
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.7.3 启动php-fpm服务
systemctl start php-fpm
1.7.4 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;
}