#yum install libxml2-devel bzip2 bzip2-devel curl-devel libjpeg-devel libpng libpng-devel freetype-devel libxslt-devel libzip-devel -y
#wget https://www.php.net/distributions/php-7.3.10.tar.gz
tar -zxvf php-7.3.10.tar.gz
cd php-7.3.10
./configure --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc --with-fpm-user=mysql --with-fpm-group=mysql --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli=mysqlnd --with-openssl --with-pcre-regex --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --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-fpm
PHP的默认配置不编译OpenSSL扩展,需要显式指--with-openssl才会编译OpenSSL扩展,若编译时需要使用源码安装的openssl,在执行configure操作时,需这样指定:./configure --with-openssl=/usr/local/openssl --with-libdir=lib。
编译完成后是以下样子:
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql
make && make install
异常场景一:make过程中,若出现
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决方案有:
undefined reference to libiconv_open
之类的提示,可以通过在 make 时附加上对应的库来解决,例如 make ZEND_EXTRA_LIBS='-liconv'。这里是网上能够搜索到的解决方法,但是作者自己遇到的并不是这种或者类似的情形。异常场景二:make过程中,若出现
/usr/local/src/php-7.3.10/sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127
解决方案为(在/etc/ld.so.conf中添加/usr/local/lib并使之生效):
echo '/usr/local/lib' >> /etc/ld.so.conf && /sbin/ldconfig
异常场景三:make过程中,若出现
chmod: cannot access ‘ext/phar/phar.phar’: No such file or directory
make: [ext/phar/phar.phar] Error 1 (ignored)
解决方案为(在php源码所在目录执行以下命令或者重新编译php):
#cd ext/phar/
#cp ./phar.php ./phar.phar
复制以下三个配置文件
cp php.ini-production /usr/local/php73/etc/php.ini
cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf
cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf
配置php.ini(注意:php的注释为 ; 如果设置前面有 ; ,请记得删除 )
vim /usr/local/php73/etc/php.ini
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = Asia/Shanghai
测试php是否安装成功
/usr/local/php73/sbin/php-fpm -t
拷贝启动文件
cp /usr/local/src/php-7.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm-73
赋予执行权限
chmod 755 /etc/init.d/php-fpm-73
启动
service php-fpm-73 start # 或则直接执行:/usr/local/php73/sbin/php-fpm
查询是否启动成功
ps -ef |grep php-fpm # 或执行netstat -tunpl | grep php-fpm
配置 nginx可解析.php文件
nginx配置内容此处省略,但值得注意的一点是:nginx主机配置中,【fastcgi_pass 127.0.0.1:9000】此处所指定的9000端口,必须与/usr/local/php73/etc/php-fpm.d/www.conf里面的【listen = 127.0.0.1:9000】配置的端口要一样,不然无法解析(本示例使用的是9000端口)。