很多时候一台主机需要安装php的版本已经非常的多,可能从php5.4-php8都需要安装。
比较历史遗留问题,很多程序运行在各种php版本环境中。
编译安装php 得到各个不同版本,运行互不干扰是非常有效果的。
本文记录 编译安装php 的常用变量:
下载php版本的 源码包:https://www.php.net/downloads
php-7.3.27.tar.gz
以下在centos7 系统 安装 成功。首先要有 基本的make 工具等。
直接cd到 php的源码包目录里面执行configure 命令配置make 参数:
./configure --prefix=/home/php73/php\ --with-config-file-path=/home/php73/php/etc\ --with-config-file-scan-dir=/home/php73/php/conf.d\ --enable-fpm --with-fpm-user=www --with-fpm-group=www\ --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir\ --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml\ --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem\ --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring\ --enable-intl --enable-pcntl --enable-ftp --with-gd --with-openssl --with-mhash\ --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap\ --with-gettext --enable-opcache --with-xsl
解决 Cannot find OpenSSL's <evp.h>
yum install openssl openssl-devel ln -s /usr/lib64/libssl.so /usr/lib/
解决curls错误:
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 -y install curl-devel
解决:configure: error: png.h not found.
If configure fails try --with-vpx-dir=<DIR> If configure fails try --with-jpeg-dir=<DIR> configure: error: png.h not found. 经查资料说是libpng,devel包没安装, 执行下面两条命令即可解决 yum install libpng yum install libpng-devel
error: C++ preprocessor "/lib/cpp" fails sanity check 问题的解决
yum install glibc-headers yum install gcc-c++
CMake版本低,需要更高版本.
#下载cmake wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz #解压文件 tar zxvf cmake-3.9.2.tar.gz cd cmake-3.9.2 ./configure make sudo make install sudo cmake --version
php7.3安装configure: error: Please reinstall the libzip distribution解决方案
[root@localhost ~]# wget https://libzip.org/download/libzip-1.5.2.tar.gz [root@localhost ~]# tar -zxf libzip-1.5.2.tar.gz [root@localhost ~]# cd libzip-1.5.2 [root@localhost ~]# mkdir build [root@localhost ~]# cd build [root@localhost ~]# cmake .. (#注意:cmake后面有两个小数点) [root@localhost ~]# make -j4 [root@localhost ~]# make test [root@localhost ~]# 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 # 使之生效
安装中遇到的 缺少 其他包的 问题,都需要一个一个安装解决。的确有点麻烦。编译安装就是这样麻烦。
不过后面用起来就爽快了。。
配置php-fpm
[Unit] Description=php-fpm73 on /hom/php73/php/sbin/php-fpm Documentation=install on /home/php73/php/sbin/php-fpm After=network.target #dkkdkkd [Service] PIDFile=/home/php73/php/var/run/php-fpm.pid User=www Group=www EnvironmentFile=-/etc/default/php-fpm73 ExecStart=/home/php73/php/sbin/php-fpm --fpm-config /home/php73/php/etc/php-fpm.conf --pid /home/php73/php/var/run/php-fpm.pid ExecReload=/bin/kill -USR2 $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target Alias=php-fpm.service
上面是 php-fpm.service 文件。通过软连接
ln -s /home/php73/php/conf.d/php-fpm.service /lib/systemd/system/php-fpm73.service
systemctl start php-fpm73
启动php-fpm
注意 把
/home/php73/php/etc/php-fpm.conf.default 和 /home/php73/php/etc/php-fpm.d/ 分别复制,去掉default的文件: 得到: /home/php73/php/etc/php-fpm.conf /home/php73/php/etc/php-fpm.d/www.conf
最后还有注意,php73 这个目录 要
chown www:www -R /home/php73/
启动php-fpm
systemctl enable php-fpm systemctl start php-fpm systemctl status php-fpm
配置 nginx 站点 使用 php7.3版本的php
下面以nextcloud 云盘的nginx 站点配置为例 , 在nginx 的 conf/vhost 文件夹里新建 nextcloud.conf 内容如下
upstream php-handler2 { #这里是php-fpm的listen 端口号, #在/home/php73/php/etc/php-fpm.d/www.conf 修改成和这里一致; server 127.0.0.1:9001; } server { listen 20082 default_server; listen [::]:20082 default_server; index index.html index.htm index.php ; root /home/www/nextcloud; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; fastcgi_hide_header X-Powered-By; location = /robots.txt { allow all; log_not_found off; access_log off; } location = /.well-known/carddav { return 301 $scheme://$host:$server_port/remote.php/dav; } client_max_body_size 0; fastcgi_buffers 64 4K; # Enable gzip but do not remove ETag headers gzip on; gzip_vary on; gzip_comp_level 4; gzip_min_length 256; gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; location / { rewrite ^ /index.php$request_uri; } location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ { deny all; } location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|ocs-provider\/.+)\.php(?:$|\/) { fastcgi_split_path_info ^(.+?\.php)(\/.*|)$; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; #fastcgi_param HTTPS on; #Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler2; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^\/(?:updater|ocs-provider)(?:$|\/) { try_files $uri/ =404; index index.php; } location ~ \.(?:css|js|woff2?|svg|gif)$ { try_files $uri /index.php$request_uri; add_header Cache-Control "public, max-age=15778463"; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; # Optional: Don't log access to assets access_log off; } location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$request_uri; # Optional: Don't log access to other assets access_log off; } }
nginx reload 后,打开 http://localhost:20082 即可访问 站点,它 的php 版本为php 7.3
好了,本文内容全部介绍完毕,感谢您的阅读。
上一篇:PHP 安装swoole 扩展
下一篇:php安装imagick扩展
实用工具: JSON字符串格式化 | js压缩代码格式化工具 | 异步XMLHttpRequests库axios.js文档 | vue-axios文档 | Go语言文档