下载安装包
wget http://cn2.php.net/distributions/php-7.2.5.tar.gz
tar -zxvf php-7.2.5.tar.gz
安装依赖
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
编译安装
如需复制,请复制第二种,第一种会超出字符限制
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm
--enable-exif \
--enable-fileinfo \
--enable-calendar \
--enable-readline \
--enable-sodium \
--enable-sysvmsg \
--enable-sysvshm \
--enable-wddx
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml \
--disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-libmbfl --enable-ftp \
--with-gd --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo \
--enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm --enable-exif --enable-fileinfo --enable-calendar --enable-readline --enable-sodium \
--enable-sysvmsg --enable-sysvshm --enable-wddx
安装
make && make install
修改配置文件
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp -a php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp -a www.conf.default www.conf
vim /usr/local/php/etc/php-fpm.conf
取消pid的注释,并将pid的存放路径修改为 `/var/run/` 下
即 pid = /var/run/php-fpm.pid
如果不修改的话,使用systemctl或者service启动php-fpm时会失败
添加全局变量
ln -sf /usr/local/php/bin/php /usr/bin/php
ln -sf /usr/local/php/bin/phpize /usr/local/bin/phpize
#查看扩展信息
php -i
#查看已安装的扩展
php -m
添加www用户
#php-fpm默认的启动用户是www,如果没有www用户需要先添加
groupadd www
useradd www
useradd -g www www
使用systemctl管理php-fpm
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#重载配置
systemctl daemon-reload
systemctl 命令
systemctl status php-fpm
systemctl stop php-fpm
systemctl start php-fpm
systemctl retart php-fpm
第三方扩展(igbinary,psr,phalcon,redis,swoole)安装
#下载
wget https://pecl.php.net/get/igbinary-3.2.1.tgz
wget https://pecl.php.net/get/phalcon-4.1.0.tgz
wget https://pecl.php.net/get/psr-1.0.1.tgz
wget https://pecl.php.net/get/redis-5.3.2.tgz
wget https://pecl.php.net/get/swoole-4.5.10.tgz
#解压编译安装(以igbinary为例)
tar -zxvf igbinary-3.2.1.tgz
cd igbinary
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
#在php.ini添加扩展选项
extension=igbinary
#查看扩展
php -m
yaml扩展安装
- 先安装libyaml
下载地址:https://pyyaml.org/download/libyaml/yaml-0.2.2.tar.gz
# 解压安装
tar -zxvf yaml-0.2.2.tar.gz
cd yaml-0.2.2
./configure #默认安装路径在/usr/local/lib/
make && make install
- 再安装yaml扩展
下载地址:https://pecl.php.net/get/yaml-2.0.4.tgz
tar -zxvf yaml-2.0.4.tgz
cd igbinary
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
#在php.ini添加扩展选项
extension=yaml
#查看扩展
php -m
扩展问题
1.sodium扩展问题
checking for re2c… no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk… gawk
checking for sodium support… yes, shared
checking for pkg-config… /usr/bin/pkg-config
checking for libsodium… configure: error: Please install libsodium - See https://github.com/jedisct1/libsodium
解决办法
1. yum -y groupinstall "Development Tools"
2. wget https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz
3. tar xf libsodium-1.0.11.tar.gz && cd libsodium-1.0.11
4. ./configure && make -j2 && make install
5. echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
6. ldconfig
2.configure: error: Cannot find ldap libraries in /usr/lib
解决办法
cp -frp /usr/lib64/libldap* /usr/lib/
3.configure: error: Please reinstall the BZip2 distribution
yum install bzip2-devel
4.configure: error: Please reinstall libedit - I cannot find readline.h
1.#安装readline扩展提示的错误
解决办法:下载最新版 libedit 编译安装即可。然后重新编译readline
wget http://thrysoee.dk/editline/libedit-20170329-3.1.tar.gz --no-check-certificate
tar -zxvf libedit-20170329-3.1.tar.gz
cd libedit-20170329-3.1
./configure
make && make install
2.#libedit安装完以后再进入readline扩展目录继续编译readline扩展
5.swoole开启支持openssl
需重新编译swoole,假设你已经有了swoole的源码
cd swoole-4.5.10
./configure --with-php-config=/usr/local/php/bin/php-config --enable-openssl --with-openssl-dir=/usr/include/openssl
#这一步很重要
make clean
make && make install
查看swoole是否开启swoole
[root@test ]# php --ri swoole
swoole
Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.5.10
Built => Dec 1 2021 18:26:33
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608