Linux下编译安装以及配置PHP环境 Nginx Swoole

yum update
#安装编译工具
yum -y install gcc gcc-c++ pcre openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel make
#php下载以及安装https://www.php.net/downloads
wget -c  http://www.php.net/distributions/php-7.2.33.tar.gz
#解压安装包
tar -zxvf php-7.2.33.tar.gz
#进入目录开始编译安装
cd php-7.2.33
#配置
./configure --prefix=/usr/local/php7.2
make && make install
#安装成功后配置PHP环境变量
方法一、建立软链接
ln -s /usr/local/php7.2/bin/php /usr/bin/php

方法二
vi ~/.bash_profile

增加
alias php=/usr/local/php7.2/bin/php

source ~/.bash_profile
#增加配置文件

查看配置文件目录
php -i |grep php.ini

[root@7c73e1180bfb lib]# php -i |grep php.ini
Configuration File (php.ini) Path => /usr/local/php7.2/lib


将编译目录配置文件拷贝到对应目录
cp php.ini-production /usr/local/php7.2/lib/php.ini
#编译安装swoole
#Swoole 扩展是按照 PHP 标准扩展构建的。使用 phpize 来生成编译检测脚本,./configure 来做编译配置检测,make 进行编译,make install 进行安装。

#下载页面 https://github.com/swoole/swoole-src/releases

#下载源码
wget -c https://github.com/swoole/swoole-src/archive/v4.4.18.tar.gz

#解压 tar -zxvf v4.4.18.tar.gz

#进入解压目录
cd swoole-src-4.4.18/

生成configure文件
/usr/local/php7.2/bin/phpize

########注意################
#执行出错提示未安装
[root@7c73e1180bfb swoole-src-4.4.18]# phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.


#安装 autoconf

yum install autoconf
#重试上一步
/usr/local/php7.2/bin/phpize

#编译配置检测
./configure --with-php-config=/usr/local/php7.2/bin/php-config

# make 进行编译,make install 进行安装。
make && make install

#安装目录
[root@7c73e1180bfb swoole-src-4.4.18]# make install
Installing shared extensions:     /usr/local/php7.2/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /usr/local/php7.2/include/php/

#php配置文件中引入swoole扩展
vi /usr/local/php7.2/lib/php.ini

新增一行数据
extension=swoole
或者
#extension = "/usr/local/php7.2/lib/php/extensions/no-debug-non-zts-20170718//swoole.so"

#查看扩展是否已经引用成功
php -m