centos7 PHP7单独编译安装
编译安装了好几次,记录下来:
主要有以下步骤:
1、准备编译环境;
2、下载PHP7 源码包;
3、编译安装;
4、配置;
一、准备编译环境:
准备gcc
sudo yum install git gcc gcc-c++ libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel
二、下载PHP源码
有两种方式下载:
第一种是 https://www.php.net/releases/ 下载对应版本 , 下载之后用 tar -zxvf 解压;
第二种是 用git,
git clone https://github.com/php/php-src.git git checkout PHP-7.0.2 #换成你想要的版本
三、编译安装
配置脚本:PHP7安装目录在/usr/local/php7下。
./buildconf --force
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg --with-freetype --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=apache --with-fpm-group=apache --without-gdbm --with-mcrypt
编译安装:
make clean && make && make install
四、配置
1、拷贝php.ini 配置文件 ,是生产环境的配置文件:
cp php.ini-development /usr/local/php7/etc/php.ini
2、配置php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
3、修改php-fpm.conf
#将pid换一个命名,取消配置的备注 pid = /run/php-fpm/php7-fpm.pid #日志文件 error_log = /var/log/php-fpm/php7-error.log
4、修改www.conf配置文件,更换监听的端口
#换成9001 listen = 127.0.0.1:9001
5、配置服务:
#建议软链接
ln -s /usr/local/php7/sbin/php-fpm /usr/sbin/php7-fpm
ln -s /usr/local/php7/bin/php /usr/bin/php
vi /usr/lib/systemd/system/php7-fpm.service
文件内容为:
[Unit]
Description=The PHP7 FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple PIDFile=/run/php-fpm/php7-fpm.pid
ExecStart=/usr/sbin/php7-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
6、启动服务
systemctl enable php7-fpm systemctl start php7-fpm
Ubuntu 16.4 编译安装PHP7
关于使用openssl 1.1版本造成PHP Curl打开 https链接失败的问题,请参考:https://github.com/oerdnj/deb.sury.org/issues/566
php5.6 curl: https://github.com/laruence/yar/issues/111
openssl 1.1 https://github.com/openssl/openssl/issues/4133
open ssl 兼容: https://stackoverflow.com/questions/53537433/how-to-compile-php5-6-with-imap-function-and-openssl-1-0-1-compiled
PHP5 redis单独编译 https://github.com/phpredis/phpredis/issues/1539 , 直接使用pecl 4.3 https://pecl.php.net/package/redis 下载编辑安培,不使用git代码中代码
WSL PHP-FPM TCP_INFO问题: https://stackoverflow.com/questions/46244431/php7-fpm-error-failed-to-retrieve-tcp-info-for-socket-protocol-not-available?rq=1
wget -c https://github.com/remicollet/php-src/commit/4ca75ff1f3c341b83932f85310595f5c0a10f57e.patch
# git apply path:https://www.devroom.io/2009/10/26/how-to-create-and-apply-a-patch-with-git/
git apply 4ca75ff1f3c341b83932f85310595f5c0a10f57e.patch
PHP 7.4.3 安装遇到的问题:
1. Package requirements (oniguruma) were not met: https://qna.habr.com/q/698309
https://www.limstash.com/en/articles/202002/1539
apt-get install libonig-dev
2. sqlite3
apt-get install libsqlite3-dev
3.正常安装后没有正常生成 gd库
切换到编译源码 php-src/ext ,找到相应的扩展按照phpredis的方式make,将生成的库文件拷贝到 安装目录并且修改配置文件重启 fpm进程
一、安装库文件
apt-get install libkrb5-dev libc-client2007e libc-client2007e-dev libcurl4-openssl-dev libbz2-dev libjpeg-dev libmcrypt-dev libxslt1-dev libxslt1.1 libpq-dev libpng-dev libfreetype6-dev build-essential make
二、make 配置
./configure \
--prefix=/usr/local/php7 \
--with-config-file-path=/etc/php/7 \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-soap \
--enable-calendar \
--with-curl \
--with-mcrypt \
--with-zlib \
--with-gd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock=/var/run/mysqld/mysqld.sock \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-gd-native-ttf \
--with-openssl \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-ftp \
--with-imap \
--with-imap-ssl \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-opcache \
--enable-fpm
三、编译安装
make && make install
四、配置
五、设置开机自启动