前言
现在我们来做做后一步的工作(安装PHP-7.4.4),话不多说,着实CentOS8部署LNMP很打脑壳。
注意:安装PHP在我这报了很多次错,需要的兄弟们先看,在执行,避免报错。
一、前提准备
软件源代码包存放位置:/usr/local/src
源码包编译安装位置:/usr/local/软件名字
1、准备源码包
php-7.4.4.tar.xz
oniguruma-6.9.4.tar.gz
libmcrypt-2.5.8.tar.bz2
2、解决依赖问题
[14:03:25 root@wangzhike src]#yum -y install php-pear
Installed:
php-pear-1:1.10.5-9.module_el8.1.0+209+03b9a8ff.noarch
httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch
php-cli-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64
php-common-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64
php-process-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64
php-xml-7.2.11-2.module_el8.1.0+209+03b9a8ff.x86_64
[14:21:21 root@wangzhike ~]#yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel libzip libzip-devel
Installed:
libjpeg-turbo-devel-1.5.3-10.el8.x86_64
libxml2-devel-2.9.7-5.el8.x86_64
libzip-1.5.1-2.module_el8.1.0+209+03b9a8ff.x86_64
libzip-devel-1.5.1-2.module_el8.1.0+209+03b9a8ff.x86_64
freetype-devel-2.9.1-4.el8.x86_64
libcurl-devel-7.61.1-11.el8.x86_64
libpng-devel-2:1.6.34-5.el8.x86_64
bzip2-devel-1.0.6-26.el8.x86_64
xz-devel-5.2.4-3.el8.x86_64
3、安装PHP加密算法扩展库
libmcrypt加密算法扩展库,支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256, ARCFOUR, SERPENT, SAFER+等算法,下载地址:http://mcrypt.hellug.gr/index.html
[14:02:57 root@wangzhike software]#tar xf libmcrypt-2.5.8.tar.bz2 -C /usr/local/src/
[14:16:25 root@wangzhike src]#cd libmcrypt-2.5.8/
[14:18:34 root@wangzhike libmcrypt-2.5.8]#./configure --prefix=/usr/local/libmcrypt
appending configuration tag "F77" to libtool
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libmcrypt.spec
config.status: creating lib/Makefile
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating include/mutils/mcrypt.h
config.status: creating include/Makefile
config.status: creating modules/Makefile
config.status: creating modules/modes/Makefile
config.status: creating modules/algorithms/Makefile
config.status: creating lib/libmcrypt-config
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing default-1 commands
[14:119:04 root@wangzhike libmcrypt-2.5.8]#make ; make install ; cd
4、需要添加到库文件路径
[14:23:08 root@wangzhike ~]#vi /etc/ld.so.conf
include ld.so.conf.d/*.conf //此行原有
/usr/local/libmcrypt/lib //添加
/usr/local/mysql/lib //添加
[14:24:33 root@wangzhike ~]#ldconfig //重新加载
[14:24:36 root@wangzhike ~]# echo 'ldconfig' >> /etc/rc.local
二、源码安装php-7.4.4
1、解包
[14:25:46 root@wangzhike software]#tar xf php-7.4.4.tar.xz -C /usr/local/src/
[14:25:58 root@wangzhike software]#cd /usr/local/src/php-7.4.4/
[14:26:18 root@wangzhike php-7.4.4]#
2、编译(先编译,有报错一一解决)
[14:29:22 root@wangzhike php-7.4.4]#./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/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-mcrypt \
--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-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--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 \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
报错一
configure: error: Package requirements (sqlite3 > 3.7.4) were not met:
解决:
[14:33:30 root@wangzhike php-7.4.4]#yum install sqlite-devel
报错二
configure: error: GNU MP Library version 4.2 or greater required.
解决:
[14:45:22 root@wangzhike software]#yum -y install gmp-devel
报错三
configure: error: Package requirements (oniguruma) were not met:
Package ‘oniguruma’, required by ‘virtual:world’, not found
解决:
说明我没有安装oniguruma包
[14:45:22 root@wangzhike software]#wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
安装oniguruma-6.9.4
[14:47:12 root@wangzhike software]# cd /usr/local/src/oniguruma-6.9.4/
[14:50:51 root@wangzhike oniguruma-6.9.4]#./autogen.sh && ./configure --prefix=/usr
[14:52:25 root@wangzhike oniguruma-6.9.4]#make && make install
出现以下就OK
----------------------------------------------------------------------
/usr/bin/mkdir -p '/usr/include'
/usr/bin/install -c -m 644 oniguruma.h oniggnu.h onigposix.h '/usr/include'
make[2]: Leaving directory '/usr/local/src/oniguruma-6.9.4/src'
make[1]: Leaving directory '/usr/local/src/oniguruma-6.9.4/src'
Making install in test
make[1]: Entering directory '/usr/local/src/oniguruma-6.9.4/test'
make[2]: Entering directory '/usr/local/src/oniguruma-6.9.4/test'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/usr/local/src/oniguruma-6.9.4/test'
make[1]: Leaving directory '/usr/local/src/oniguruma-6.9.4/test'
Making install in sample
make[1]: Entering directory '/usr/local/src/oniguruma-6.9.4/sample'
make[2]: Entering directory '/usr/local/src/oniguruma-6.9.4/sample'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/usr/local/src/oniguruma-6.9.4/sample'
make[1]: Leaving directory '/usr/local/src/oniguruma-6.9.4/sample'
make[1]: Entering directory '/usr/local/src/oniguruma-6.9.4'
make[2]: Entering directory '/usr/local/src/oniguruma-6.9.4'
/usr/bin/mkdir -p '/usr/bin'
/usr/bin/install -c onig-config '/usr/bin'
/usr/bin/mkdir -p '/usr/lib64/pkgconfig'
/usr/bin/install -c -m 644 oniguruma.pc '/usr/lib64/pkgconfig'
make[2]: Leaving directory '/usr/local/src/oniguruma-6.9.4'
make[1]: Leaving directory '/usr/local/src/oniguruma-6.9.4'
重新编译PHP
报错四
configure: error: Package requirements (libxslt >= 1.1.0) were not met:
Package ‘libxslt’, required by ‘virtual:world’, not found
解决:
[14:56:14 root@wangzhike php-7.4.4]#yum -y install libxslt-devel
再重新编译
出现以下则表示PHP编译成功
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
3、执行make -j 3 && make install
[15:08:14 root@wangzhike php-7.4.4]#make -j 3 && make install ; cd
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.8
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.3
[PEAR] PEAR - installed: 1.10.10
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-7.4.4/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
4、添加环境变量
[15:09:31 root@wangzhike ~]#echo "export PATH=$PATH:/usr/local/php/bin" >> /etc/profile
[15:10:08 root@wangzhike ~]#source /etc/profile
5、准备配置文件
[15:11:26 root@wangzhike php-7.4.4]#cp php.ini-production /usr/local/php/etc/php.ini
[15:11:42 root@wangzhike php-7.4.4]#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[15:11:51 root@wangzhike php-7.4.4]#cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx
[15:20:33 root@wangzhike ~]#chown nginx.nginx /usr/local/php/etc/php-fpm.conf
6、修改文件(在这里就修改最基础内容)
1)、修改www.conf文件
[15:56:19 root@wangzhike ~]#vi /usr/local/php/etc/php-fpm.d/www.conf
user = nginx #设置php-fpm运行账号为nginx
group = nginx #设置php-fpm运行组为nginx
2)、修改php-fpm文件
[15:57:57 root@wangzhike ~]#vi /etc/init.d/php-fpm
prefix=/usr/local/php
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
3)、修改php.ini文件
[15:58:38 root@wangzhike ~]#vi /usr/local/php/etc/php.ini
找到:disable_functions =
修改为
disable_functions =
passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,
posix_getegid,posix_geteuid,posix_getgid,
posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,
posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit,
posix_getsid,posix_getuid,posix_isatty,
posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,
posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
保存退出
启动脚本
[15:28:39 root@wangzhike ~]#/etc/init.d/php-fpm start
Starting php-fpm done
三、测试LNMP的PHP支持
先查看是否开启
[16:19:10 root@wangzhike html]#ps -aux | grep php
root 29269 0.0 0.3 140444 11028 ? Ss 15:48 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nginx 29270 0.0 0.5 166204 14848 ? S 15:48 0:00 php-fpm: pool www
nginx 29271 0.0 0.5 166204 14908 ? S 15:48 0:00 php-fpm: pool www
root 114459 0.0 0.0 9180 980 pts/3 S+ 16:19 0:00 grep --color=auto php
测试
[16:10:47 root@wangzhike html]#echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php
浏览器访问:http://IP地址/
CentOS8-------------------------------------------------------LNMP搭建成功