PHP swoole & ext-postgreSQL 開發環境搭建

環境:centos 7

安裝 php 7.4

# 安装repo
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --enable remi-php74
sudo yum update
sudo yum install php php-cli
sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json php-pecl-mongodb php-pecl-redis

安裝 swoole 4.5.4

# 下載
wget https://github.com/swoole/swoole-src/archive/v4.5.4.zip
# 編譯
cd swoole-src && \
phpize && \
./configure && \
make && sudo make install
# 配置
vi /etc/php.d/80-swoole.ini
<<<輸入以下內容>>>
extension=swoole.so
swoole.use_shortname = 'Off'

安裝 swoole/ext-postgresql

# 下載
https://github.com/swoole/ext-postgresql/archive/master.zip
要求編譯環境:
1. Clang and LLVM Toolset 7.0
2. postgresql12-devel
3. libpq
安裝 Clang and LLVM Toolset 7.0
sudo yum install centos-release-scl
sudo yum install llvm-toolset-7.0
安裝 postgresql12-devel
sudo yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum -y install yum-utils
sudo yum install postgresql12-devel
安裝 libpq
yum install libpq
# 在編譯過程中會提示找不到"postgresql/libpq-fe.h"
找到檔案位置 find / -name libpq-fe.h
# 這邊顯示 /usr/pgsql-12/include/libpq-fe.h
編輯檔案 vi swoole_postgresql_coro.h
#include <postgresql/libpq-fe.h> 改為 #include "/usr/pgsql-12/include/libpq-fe.h"
# 編譯
cd ext-postgresql && \
phpize && \
./configure && \
make && sudo make install
# 配置
vi /etc/php.d/80-swoole.ini
<<<新增以下內容>>>
extension=swoole_postgresql.so

重啓服務

systemctl restart php-fpm

— 完成—

--

--