阿里云centos7.6安装php7.3的详细教程(超级详细)

正在搭建LNMP环境,nginx所用的启动用户是nginx
详细过程:
[root@test2 ~]# tar -zxvf php-7.3.20.tar.gz -C /home/ops
[root@test2 ~]# cd /home/ops/php-7.3.20
安装支持包:

[root@test2 /home/ops/php-7.3.20]#
yum install -y  libxml2-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel libzip-devel
./configure --prefix=/home/ops/php --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm

编译错误,解决问题:
configure: error: libxml2 not found. Please check your libxml2 installation.
解决:yum install -y libxml2-devel

configure: error: Please reinstall the BZip2 distribution
解决:yum install -y bzip2-devel

checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
解决:yum install -y curl-devel

configure: error: jpeglib.h not found.
解决:yum install -y libjpeg-devel

configure: error: png.h not found.
解决:yum install -y libpng-devel

configure: error: freetype-config not foun
解决:yum install -y freetype-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决:yum install -y libxslt-devel

configure: error: Please reinstall the libzip distribution
解决:yum install -y libzip-devel

checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
解决:需要安装libzip的版本大于0.11
[root@test2 /home/ops/php-7.3.20]# yum -y remove libzip-devel
[root@test2 /home/ops/php-7.3.20]# cd …
[root@test2 /home/ops]# wget https://libzip.org/download/libzip-1.7.3.tar.gz
[root@test2 /home/ops]# tar -zxvf libzip-1.7.3.tar.gz

安装libzip-1.7.3需要用到cmake,先安装cmake

wget https://github.com/Kitware/CMake/releases/download/v3.18.1/cmake-3.18.1.tar.gz
tar -zxvf cmake-3.18.1.tar.gz
mv cmake-3.18.1 /home/ops/cmake
yum install gcc-c++
cd /home/ops/cmake
./bootstrap #执行完之后会在当前目录生成一个bin目录,cmake执行程序在里面
遇到下面这个报错:
gmake: *** [cmStandardIncludes.o] Error 1
--------------------------------------------
Error when bootstrapping CMake:
Problem while running gmake
--------------------------------------------
Log of errors: /root/cmake-2.8.7/Bootstrap.cmk/cmake_bootstrap.log
如果检查不出来是哪里的问题,那就有可能是机器内存太小,导致编译的时候出现下面那个报错(执行两次./bootstrap可以看到):
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
在这里插入图片描述
出现如上图的错误是因为用户权限不够,需要sudo

解决报错之后继续安装cmake:
gmake
gmake install
/home/ops/cmake/bin/cmake --help #出现一大堆东西说明安装成功了

装好cmake之后返回libzip-1.7.3目录,准备继续安装libzip-1.7.3
[root@test2 /home/ops]# cd libzip-1.7.3
[root@test2 /home/ops/libzip-1.7.3]# mkdir build
[root@test2 /home/ops/libzip-1.7.3]# cd build
[root@test2 /home/ops/libzip-1.7.3/build]# cmake ..
[root@test2 /home/ops/libzip-1.7.3/build]# make
[root@test2 /home/ops/libzip-1.7.3/build]# make install(如果是普通用户:sudo make install)

到此libzip-1.7.3就安装完毕了,重新configure php-7.3.20
[root@test2 /home/ops/libzip-1.7.3/build]# cd …/php-7.3.20
[root@test2 /home/ops/php-7.3.20]# ./configure --prefix=/home/ops/php --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm

configure: error: off_t undefined; check your library configuration
解决:添加四行,如下:
vim /etc/ld.so.conf #打开文件
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64

重新configure php-7.3.20
[root@test2 /home/ops/php-7.3.20]# ./configure --prefix=/home/hahaha/data/server/php --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-fpm
在这里插入图片描述
成功,接着开始编译
make #这里遇到了虚拟内存问题,现在服务器内存为1G,到服务器后台升配2G或者更大即可解决
virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprentice.lo] Error
make install

配置建立目录
[root@test2 /home/ops/php-7.3.20]# cp php.ini-production /home/ops/php/lib/php.ini
[root@test2 /home/ops/php-7.3.20]# cp /home/ops/php/etc/php-fpm.conf.default /home/ops/php/etc/php-fpm.conf

[root@test2 /home/ops/php-7.3.20]# ln -s /home/ops/php/sbin/php-fpm /usr/local/bin/php-fpm
[root@test2 /home/ops/php-7.3.20]# cd /home/ops/php/etc/php-fpm.d
[root@test2 /home/ops/php/etc/php-fpm.d]# vim www.conf

[www]
listen = 127.0.0.1:9000
listen.mode = 0666

user = nginx
group = nginx

pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000

rlimit_files = 1024

slowlog = log/$pool.log.slow

[root@test2 /home/ops/php/etc/php-fpm.d]# cd /home/ops/php-7.3.20/sapi/fpm/
[root@test2 /home/ops/php-7.3.20/sapi/fpm/]# cp php-fpm.service /usr/lib/systemd/system/
[root@test2 /home/ops/php-7.3.20/sapi/fpm/]# systemctl start php-fpm
如果有提示:
Warning: php-fpm.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
运行再启动php-fpm:
[root@test2 /home/ops/php-7.3.20/sapi/fpm/]# systemctl daemon-reload
[root@test2 /home/ops/php-7.3.20/sapi/fpm/]# systemctl start php-fpm
查看状态,确认php-fpm的启动状态
[root@test2 /home/ops/php-7.3.20/sapi/fpm/]# systemctl status php-fpm
正确的状态应该如下图:
在这里插入图片描述
完毕!

猜你喜欢

转载自blog.csdn.net/weixin_44901564/article/details/108167186