Centos 7源码安装LNMP环境三 PHP
安装扩展:
yum -y install libicu-devel openldap-develpcre pcre-developenssl openssl-devel gcc gcc-c++ autoconf automake ma ke libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel
安装:
cd /src wget https://www.php.net/distributions/php-7.3.5.tar.gz tar -zxvf php-7.3.5.tar.gz cd php-7.3.5 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-gd --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm make(此过程需花费时间较长) make install
提示libzip的版本要求是>= 0.11
安装libzip:
wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make make install
报错解决办法:
error: Cannot find ldap libraries in /usr/lib
原因是动态链接库地址的问题。
解决方法
具体的解决办法如下:
cp -frp /usr/lib64/libldap* /usr/lib
error: off_t undefined; check your library configuration
vim /etc/ld.so.conf
#添加如下几行
/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 #保存退出 :wq ldconfig -v # 使之生效
usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
找不到文件,加zipconf.h软连接
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
将PHP包解压目录中的配置文件放置到正确位置(configure命令中的--with-config-file-path设置的位置)
cp php.ini-development /etc/php.ini
设置运行账号的位置:
所以:
cd php-fpm.d cp www.conf.default www.conf(否则include匹配不到文件) vim www.conf
搜索“user”设置运行账号:
user=www-data group=www-data
配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
修改前
修改后
修改完成之后重启nginx服务:
systemctl restart nginx.service
7. 设置php-fpm为系统服务:
vim /etc/systemd/system/php-fpm.service
文件内容:
[Unit] Description=php-fpm After=network.target [Service] Type=forking ExecStart=/usr/local/php/sbin/php-fpm PrivateTmp=True [Install] WantedBy=multi-user.target
8. 设置php-fpm服务开机自启动:
systemctl enable php-fpm.service
9. 启动php-fpm:
systemctl start php-fpm.service
查看是否启动成功:
ps aux | grep php-fpm
10.写一个PHP脚本测试nginx是否已支持PHP,PHP是否已支持mysql。
至此,LNMP搭建完成