全网最细且手把手一起学CentOS8.0源码编译安装LNMP环境之PHP7.3.10源码安装(三)
重新安装一下依赖的原因是为了确保安装那些没有安装的依赖
4.1、安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel libicu-devel
yum install -y libzip-devel
4.2、安装php
cd /usr/local/src
tar -zxvf php-7.3.10.tar.gz
cd php-7.3.10
#编译的过程中可能会出现缺少依赖包的情况,请自行安装
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--with-pear \
--enable-opcache
报错一 system libzip must be upgraded to version >= 0.11 解决办法 yum -y remove libzip-devel
wget https://libzip.org/download/libzip-1.3.2.tar.gz
tar xvf libzip-1.3.2.tar.gz
cd libzip-1.3.2
./configure
make && make install
报错二 php安装执行configure报错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 # 使之生效
预编译 && 安装
make && make install
4.3、拷贝php配置文件
/usr/local/src/php-7.3.10
cp php.ini-production /etc/php.ini
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
4.4、编辑配置文件
# 编辑php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
pid = /run/php-fpm.pid 去掉前面的 ; 号
# 编辑www.conf
vim /usr/local/php7/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
4.5、设置开机自启
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
4.6、添加php到系统环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/php7/bin
source /etc/profile
设置开机自启
systemctl enable php-fpm.service 开机自启
systemctl disable php-fpm.service 取消开机自启
systemctl reload php-fpm.service 重新加载服务
systemctl status php-fpm.service 查看状态
快速启动php服务
systemctl start php-fpm.service 启动php服务
systemctl stop php-fpm.service 停止php服务
systemctl restat php-fpm.service 重启php服务
4.7、配置nginx解析php文件
修改一
/usr/local/nginx/conf
vim nginx.conf
修改文件路径
注释掉 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
在它的后面新增配置
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
完整配置示例
location ~ \.php$ {
root /WWW;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
修改二
修改默认访问php文件
location / {
root /WWW;
index index.php index.html index.htm;
}
4.8、配置虚拟主机
1)添加主机配置
/usr/local/nginx/conf
vim nginx.conf
添加虚拟主机配置
server {
listen 8081;
#server_name aabb.com;
root "/WWW/demo01";
location / {
index index.php index.html;
autoindex off;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
2)创建root对应的目录文件
mkdir -p /WWW/demo01
vim /WWW/demo01/index.php
配置到这里已经可以基于ip访问了。如192.168.55.158:8081
3)配置基于域名的虚拟主机
第一步:删除掉 1)中的 #server_name aabb.com; 的 # 号
第二步:打开本机的hosts文件进行配置 C:\Windows\System32\drivers\etc\hosts
192.168.55.158 aabb.com
^_^php安装完成
到了这里,那么整个LNMP环境也就搭建完成了。若是你按照此文章进行安装出现了错误,那么,欢迎前来一起交流学习。
更新时间,2019年10月26
我是夕阳何处寻,期能和优秀的你一起同行!
夕阳何处寻
2019年10月7
请登录后再评论