编译安装 PHP-FPM 7.2

原文转载自 「nginx」 ( https://www.nginx.cn/5941.html ) By 程序员翻身

预计阅读时间 0 分钟(共 0 个字, 0 张图片, 0 个链接)

现在大多数php环境都推荐使用php7版本,本文主要介绍如何安装php-fpm7.2

安装环境准备

如果安装过程报错,见问题排查1,执行完成后,重新执行安装命令。

下载并加压源码

编译PHP

首先生成configure文件

配置PHP安装选项,选择要开启的PHP扩展,例如PDO, FPM, OPCache, GD 库等,可以通过 ./configure --help 检查支持哪些扩展。

这里我们使用最常用的扩展选项。

除了需要打开的扩展模块外,上面的命令还通过设 --prefix 置了php的安装路径。本地php安装在 /usr/local/php ,可以根据自己的需求修改路径。

编译并安装PHP

如果make过程报错virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1,解决办法见问题2。

配置php-fpm.conf和php.ini

生成php.ini配置文件

生成php-fpm配置文件

 

配置centos7下php-fpm启动脚本

创建启动单元文件 vi /lib/systemd/system/php-fpm.service,加入如下内容

启用php-fpm服务,设置php-fpm开机自启

启动php-fpm服务

查看启动成功

 

错误排查

1. Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

解决办法:

2.php编译过程报错

virtual memory exhausted: Cannot allocate memory make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

解决办法:

将 –disable-fileinfo 添加到 ./configure可解决问题。

或者可以扩大swap空间

[root@www php-src-php-7.2.3]# cat /proc/swaps
Filename Type Size Used Priority
/swap file 135164 33632 -1
[root@www php-src-php-7.2.3]# mkdir /opt/images/
[root@www php-src-php-7.2.3]# dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 4.68408 s, 448 MB/s
[root@www php-src-php-7.2.3]# mkswap /opt/images/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=e9e677af-b6ce-40d3-aef9-bbea981af4e0
[root@www php-src-php-7.2.3]# swapon /opt/images/swap
swapon: /opt/images/swap: insecure permissions 0644, 0600 suggested.
[root@www php-src-php-7.2.3]# free -h
total used free shared buff/cache available
Mem: 503M 50M 14M 15M 438M 411M
Swap: 2.1G 32M 2.0G
[root@www php-src-php-7.2.3]# cat /proc/swaps
Filename Type Size Used Priority
/swap file 135164 33620 -1
/opt/images/swap file 2047996 0 -2

编译完成可以关闭swap 释放空间,

swapoff swap
rm -f /opt/images/swap
3.编译链接openssl报错
ext/openssl/.libs/openssl.o: In function zm_startup_openssl':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:1434: undefined reference to
OPENSSL_init_ssl'
ext/openssl/.libs/openssl.o: In function zm_info_openssl':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:1588: undefined reference to
OpenSSL_version'
ext/openssl/.libs/openssl.o: In function php_openssl_asn1_time_to_time_t':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:938: undefined reference to
ASN1_STRING_get0_data'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:953: undefined reference to ASN1_STRING_get0_data'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:953: undefined reference to
ASN1_STRING_get0_data'
ext/openssl/.libs/openssl.o: In function sk_X509_pop':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_pop'
ext/openssl/.libs/openssl.o: In function php_openssl_is_private_key':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4086: undefined reference to
EVP_PKEY_get0_EC_KEY'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4049: undefined reference to EVP_PKEY_get0_DSA'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4053: undefined reference to
DSA_get0_pqg'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4058: undefined reference to DSA_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4067: undefined reference to
EVP_PKEY_get0_DH'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4071: undefined reference to DH_get0_pqg'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4076: undefined reference to
DH_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4032: undefined reference to EVP_PKEY_get0_RSA'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4036: undefined reference to
RSA_get0_factors'
ext/openssl/.libs/openssl.o: In function zif_openssl_spki_export_challenge':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2070: undefined reference to
ASN1_STRING_get0_data'
ext/openssl/.libs/openssl.o: In function php_openssl_add_assoc_name_entry':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:874: undefined reference to
ASN1_STRING_get0_data'
ext/openssl/.libs/openssl.o: In function zif_openssl_x509_parse':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2335: undefined reference to
X509_get_version'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2362: undefined reference to X509_getm_notBefore'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2363: undefined reference to
X509_getm_notAfter'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2365: undefined reference to X509_getm_notBefore'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2366: undefined reference to
X509_getm_notAfter'
ext/openssl/.libs/openssl.o: In function sk_GENERAL_NAME_pop_free':
/usr/local/include/openssl/x509v3.h:166: undefined reference to
OPENSSL_sk_pop_free'
ext/openssl/.libs/openssl.o: In function sk_GENERAL_NAME_num':
/usr/local/include/openssl/x509v3.h:166: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_GENERAL_NAME_value':
/usr/local/include/openssl/x509v3.h:166: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function openssl_x509v3_subjectAltName':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:2265: undefined reference to
ASN1_STRING_get0_data'
ext/openssl/.libs/openssl.o: In function sk_X509_new_null':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_new_null'
ext/openssl/.libs/openssl.o: In function sk_X509_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_free'
ext/openssl/.libs/openssl.o: In function sk_X509_INFO_free':
/usr/local/include/openssl/x509.h:254: undefined reference to
OPENSSL_sk_free'
ext/openssl/.libs/openssl.o: In function sk_X509_INFO_shift':
/usr/local/include/openssl/x509.h:254: undefined reference to
OPENSSL_sk_shift'
ext/openssl/.libs/openssl.o: In function sk_X509_push':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_push'
ext/openssl/.libs/openssl.o: In function sk_X509_INFO_num':
/usr/local/include/openssl/x509.h:254: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_X509_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_free'
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_free'
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_free'
ext/openssl/.libs/openssl.o: In function sk_X509_pop_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_pop_free'
ext/openssl/.libs/openssl.o: In function sk_X509_new_null':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_new_null'
ext/openssl/.libs/openssl.o: In function sk_X509_push':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_push'
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_push'
ext/openssl/.libs/openssl.o: In function
sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function
sk_X509_pop':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_pop'
ext/openssl/.libs/openssl.o: In function
sk_X509_free':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_free'
ext/openssl/.libs/openssl.o: In function
zif_openssl_csr_get_subject':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:3616: undefined reference to X509_REQ_get_subject_name'
ext/openssl/.libs/openssl.o: In function
zif_openssl_pkey_get_details':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4799: undefined reference to EVP_PKEY_get0_DH'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4806: undefined reference to
DH_get0_pqg'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4807: undefined reference to DH_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4821: undefined reference to
EVP_PKEY_get0_EC_KEY'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4830: undefined reference to EVP_PKEY_get0_EC_KEY'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4777: undefined reference to
EVP_PKEY_get0_DSA'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4784: undefined reference to DSA_get0_pqg'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4785: undefined reference to
DSA_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4748: undefined reference to EVP_PKEY_get0_RSA'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4755: undefined reference to
RSA_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4756: undefined reference to RSA_get0_factors'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4757: undefined reference to
RSA_get0_crt_params'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4866: undefined reference to EVP_PKEY_get0_EC_KEY'
ext/openssl/.libs/openssl.o: In function
zif_openssl_dh_compute_key':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4909: undefined reference to EVP_PKEY_get0_DH'
ext/openssl/.libs/openssl.o: In function
sk_X509_value':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function
sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function
sk_X509_free':
/usr/local/include/openssl/x509.h:99: undefined reference to OPENSSL_sk_free'
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_free'
ext/openssl/.libs/openssl.o: In function sk_X509_new_null':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_new_null'
ext/openssl/.libs/openssl.o: In function sk_X509_push':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_push'
ext/openssl/.libs/openssl.o: In function sk_X509_pop_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_pop_free'
ext/openssl/.libs/openssl.o: In function sk_X509_push':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_push'
ext/openssl/.libs/openssl.o: In function sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_X509_value':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function sk_X509_CRL_num':
/usr/local/include/openssl/x509.h:228: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_X509_CRL_value':
/usr/local/include/openssl/x509.h:228: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function sk_X509_pop_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_pop_free'
ext/openssl/.libs/openssl.o: In function zif_openssl_private_encrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5611: undefined reference to
EVP_PKEY_get0_RSA'
ext/openssl/.libs/openssl.o: In function zif_openssl_private_decrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5673: undefined reference to
EVP_PKEY_get0_RSA'
ext/openssl/.libs/openssl.o: In function zif_openssl_public_encrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5741: undefined reference to
EVP_PKEY_get0_RSA'
ext/openssl/.libs/openssl.o: In function zif_openssl_public_decrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5804: undefined reference to
EVP_PKEY_get0_RSA'
ext/openssl/.libs/openssl.o: In function zif_openssl_sign':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5912: undefined reference to
EVP_MD_CTX_new'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5927: undefined reference to EVP_MD_CTX_free'
ext/openssl/.libs/openssl.o: In function
zif_openssl_verify':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5979: undefined reference to EVP_MD_CTX_new'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:5986: undefined reference to
EVP_MD_CTX_free'
ext/openssl/.libs/openssl.o: In function zif_openssl_seal':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6073: undefined reference to
EVP_CIPHER_CTX_reset'
ext/openssl/.libs/openssl.o: In function zif_openssl_digest':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6304: undefined reference to
EVP_MD_CTX_new'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6327: undefined reference to EVP_MD_CTX_free'
ext/openssl/.libs/openssl.o: In function
zif_openssl_encrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6623: undefined reference to EVP_CIPHER_CTX_reset'
ext/openssl/.libs/openssl.o: In function
zif_openssl_decrypt':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6710: undefined reference to EVP_CIPHER_CTX_reset'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:6710: undefined reference to
EVP_CIPHER_CTX_reset'
ext/openssl/.libs/openssl.o: In function sk_CONF_VALUE_num':
/usr/local/include/openssl/conf.h:30: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_CONF_VALUE_value':
/usr/local/include/openssl/conf.h:30: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function zif_openssl_csr_sign':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:3447: undefined reference to
X509_REQ_get_subject_name'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:3456: undefined reference to X509_getm_notBefore'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:3457: undefined reference to
X509_getm_notAfter'
ext/openssl/.libs/openssl.o: In function php_openssl_make_REQ':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:3084: undefined reference to
X509_REQ_get_subject_name'
ext/openssl/.libs/openssl.o: In function sk_CONF_VALUE_num':
/usr/local/include/openssl/conf.h:30: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function sk_CONF_VALUE_value':
/usr/local/include/openssl/conf.h:30: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function sk_CONF_VALUE_num':
/usr/local/include/openssl/conf.h:30: undefined reference to
OPENSSL_sk_num'
/usr/local/include/openssl/conf.h:30: undefined reference to OPENSSL_sk_num'
ext/openssl/.libs/openssl.o: In function
sk_CONF_VALUE_value':
/usr/local/include/openssl/conf.h:30: undefined reference to OPENSSL_sk_value'
ext/openssl/.libs/openssl.o: In function
php_openssl_pkey_init_and_assign_rsa':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4133: undefined reference to RSA_set0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4139: undefined reference to
RSA_set0_factors'
ext/openssl/.libs/openssl.o: In function php_openssl_pkey_init_dsa':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4167: undefined reference to
DSA_set0_pqg'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4174: undefined reference to DSA_set0_key'
ext/openssl/.libs/openssl.o: In function
php_openssl_pkey_init_dh':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4244: undefined reference to DH_set0_pqg'
ext/openssl/.libs/openssl.o: In function
php_openssl_dh_pub_from_priv':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4221: undefined reference to BN_with_flags'
ext/openssl/.libs/openssl.o: In function
php_openssl_pkey_init_dh':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4258: undefined reference to DH_set0_key'
ext/openssl/.libs/openssl.o: In function
php_openssl_pkey_init_dsa':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4186: undefined reference to DSA_get0_key'
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4187: undefined reference to
BN_is_zero'
ext/openssl/.libs/openssl.o: In function php_openssl_pkey_init_dh':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4251: undefined reference to
DH_set0_key'
ext/openssl/.libs/openssl.o: In function php_openssl_pkey_init_and_assign_rsa':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4146: undefined reference to
RSA_set0_crt_params'
ext/openssl/.libs/openssl.o: In function zif_openssl_pkey_export_to_file':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4536: undefined reference to
EVP_PKEY_get0_EC_KEY'
ext/openssl/.libs/openssl.o: In function zif_openssl_pkey_export':
/root/php-src-php-7.2.3/ext/openssl/openssl.c:4613: undefined reference to
EVP_PKEY_get0_EC_KEY'
ext/openssl/.libs/openssl.o: In function sk_X509_free':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_free'
ext/openssl/.libs/xp_ssl.o: In function php_openssl_create_sni_server_ctx':
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1321: undefined reference to
TLS_server_method'
ext/openssl/.libs/xp_ssl.o: In function sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/xp_ssl.o: In function sk_X509_value':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_value'
ext/openssl/.libs/xp_ssl.o: In function sk_X509_num':
/usr/local/include/openssl/x509.h:99: undefined reference to
OPENSSL_sk_num'
ext/openssl/.libs/xp_ssl.o: In function php_openssl_setup_crypto':
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1571: undefined reference to
TLS_client_method'
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1625: undefined reference to SSL_CTX_set_security_level'
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1666: undefined reference to
SSL_CTX_set_options'
ext/openssl/.libs/xp_ssl.o: In function php_openssl_set_server_specific_opts':
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1252: undefined reference to
SSL_CTX_get_options'
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1279: undefined reference to SSL_CTX_set_options'
ext/openssl/.libs/xp_ssl.o: In function
php_openssl_setup_crypto':
/root/php-src-php-7.2.3/ext/openssl/xp_ssl.c:1571: undefined reference to TLS_server_method'
ext/openssl/.libs/xp_ssl.o: In function
sk_GENERAL_NAME_num':
/usr/local/include/openssl/x509v3.h:166: undefined reference to OPENSSL_sk_num'
ext/openssl/.libs/xp_ssl.o: In function
sk_GENERAL_NAME_value':
/usr/local/include/openssl/x509v3.h:166: undefined reference to OPENSSL_sk_value'
ext/phar/.libs/util.o: In function
phar_verify_signature':
/root/php-src-php-7.2.3/ext/phar/util.c:1563: undefined reference to EVP_MD_CTX_new'
/root/php-src-php-7.2.3/ext/phar/util.c:1595: undefined reference to
EVP_MD_CTX_free'
/root/php-src-php-7.2.3/ext/phar/util.c:1586: undefined reference to EVP_MD_CTX_free'
ext/phar/.libs/util.o: In function
phar_create_signature':
/root/php-src-php-7.2.3/ext/phar/util.c:1860: undefined reference to EVP_MD_CTX_new'
/root/php-src-php-7.2.3/ext/phar/util.c:1892: undefined reference to
EVP_MD_CTX_free'
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
解决办法:
openssl版本要大于1.1.1
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl /usr/include/openssl
ln -s /usr/local/lib64/libssl.so /usr/lib64/libssl.so
ln -s /usr/local/lib64/libcrypto.so /usr/lib64/libcrypto.so
echo "/usr/local/lib64" >> /etc/ld.so.conf
ldconfig -v // 建立动态链接

转载请注明本文地址: https://www.nginx.cn/5941.html

more_vert