Skip to content

Commit

Permalink
feat: 添加 php8.2.12 与 swoole v5.1 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lixworth committed Nov 17, 2023
1 parent 87facea commit 835d261
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 24 deletions.
88 changes: 88 additions & 0 deletions macos-php-8212-v5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
echo "Mfuns build php with swoole and more extensions on macos, PHP 8.2.12 Swoole v5.1"

brew install wget autoconf automake libtool re2c bison pkg-config openssl libiconv oniguruma readline pcre2

base_dir=$(cd "$(dirname "$0")";pwd)

#sudo rm -rf ${base_dir}"/macos/*"
sudo rm -rf /tmp/pecl/install
sudo rm -rf /tmp/pear/install
sudo rm -rf ${base_dir}"/macos/php82"
mkdir -p ${base_dir}"/macos/php82"
cd ${base_dir}"/macos/php82" || exit

wget https://www.php.net/distributions/php-8.2.12.tar.gz
tar -xzvf php-8.2.12.tar.gz

cd "php-8.2.12" || exit

./configure --prefix="${base_dir}"/macos/php82/php \
--with-external-pcre=$(brew --prefix pcre2) \
--with-openssl=$(brew --prefix openssl) \
--with-iconv=$(brew --prefix libiconv) \
--with-readline=$(brew --prefix readline) \
--enable-mysqlnd \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
--enable-bcmath \
--enable-fpm \
--enable-mbstring \
--enable-phpdbg \
--enable-shmop \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-zlib \
--with-curl \
--with-pear \
--enable-pcntl

make -j $(sysctl -n hw.ncpu)
make install

cp php.ini-development ${base_dir}/macos/php82/php/lib/php.ini
export PATH=${base_dir}"/macos/php82/php/bin:$PATH"

cd "${base_dir}/macos/php82" || exit
wget https://github.com/swoole/swoole-src/archive/refs/tags/v5.1.0.zip
unzip v5.1.0.zip
cd "swoole-src-5.1.0" || exit
"${base_dir}"/macos/php82/php/bin/phpize

ln -s $(brew --prefix pcre2)/include/pcre2.h "${base_dir}"/macos/php82/php/include/php/ext/pcre/pcre2.h
./configure \
--enable-openssl \
--with-openssl-dir=$(brew --prefix openssl) \
--enable-http2 \
--enable-swoole-curl \
--enable-swoole-json \
--enable-thread-context \
--with-php-config=${base_dir}/macos/php82/php/bin/php-config

make -j $(sysctl -n hw.ncpu)
make install

cd "${base_dir}"/macos/php82
wget http://pear.php.net/go-pear.phar
sudo ${base_dir}/macos/php82/php/bin/php go-pear.phar
sudo ${base_dir}/macos/php82/php/bin/pear config-get php_dir

sudo ${base_dir}/macos/php82/php/bin/pecl channel-update pecl.php.net
sudo ${base_dir}/macos/php82/php/bin/pecl install redis

echo "memory_limit=1G" >> "${base_dir}"/macos/php82/php/lib/php.ini
echo "opcache.enable_cli = 'On'" >> "${base_dir}"/macos/php82/php/lib/php.ini
echo "extension=redis.so" >> "${base_dir}"/macos/php82/php/lib/php.ini
echo "extension=swoole.so" >> "${base_dir}"/macos/php82/php/lib/php.ini
echo "swoole.use_shortname = 'Off'" >> "${base_dir}"/macos/php82/php/lib/php.ini

"${base_dir}"/macos/php82/php/bin/php -v
"${base_dir}"/macos/php82/php/bin/php -m
"${base_dir}"/macos/php82/php/bin/php --ri swoole

cd ${base_dir}/macos/php82 || exit
wget https://mirrors.aliyun.com/composer/composer.phar
"${base_dir}"/macos/php82/php/bin/php composer.phar

echo -e "\033[42;37m Build Completed :).\033[0m\n"
81 changes: 81 additions & 0 deletions php-8212-v5.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
echo "Mfuns build php with swoole and more extensions on ubuntu-22xx, PHP 8.2.12 Swoole v5.1"

base_dir=$(cd "$(dirname "$0")";pwd)

sudo apt update
sudo apt upgrade
sudo apt install git wget autoconf automake bison build-essential curl flex \
libtool libssl-dev libcurl4-openssl-dev libxml2-dev libreadline8 \
libreadline-dev libsqlite3-dev libzip-dev openssl \
pkg-config re2c sqlite3 zlib1g-dev libonig5 libonig-dev libsodium-dev \
unzip

sudo apt install libboost-all-dev
sudo rm -rf "${base_dir}/tmp/php82"
sudo rm -rf /tmp/pecl/install
sudo rm -rf /tmp/pear/install
mkdir -p "${base_dir}/tmp/php82"
cd "${base_dir}/tmp/php82" || exit
wget https://www.php.net/distributions/php-8.2.12.tar.gz
tar -xzvf php-8.2.12.tar.gz
cd "php-8.2.12" || exit
./configure --prefix=${base_dir}/tmp/php82/php \
--enable-mysqlnd \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
--enable-bcmath \
--enable-fpm \
--enable-mbstring \
--enable-phpdbg \
--enable-shmop \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-zip \
--with-libzip=/usr/lib/x86_64-linux-gnu \
--with-zlib \
--with-curl \
--with-pear \
--with-openssl \
--enable-pcntl \
--with-readline
make -j 12 || exit
make install || exit
cp php.ini-development ${base_dir}/tmp/php82/php/lib/php.ini

cd "${base_dir}/tmp/php82" || exit
wget https://github.com/swoole/swoole-src/archive/refs/tags/v5.1.0.zip
unzip v5.1.0.zip
cd "swoole-src-5.1.0" || exit
"${base_dir}"/tmp/php82/php/bin/phpize
./configure --enable-openssl --enable-http2 --enable-swoole-curl --enable-swoole-json --with-php-config=${base_dir}/tmp/php82/php/bin/php-config
make -s -j 12
make install

wget http://pear.php.net/go-pear.phar
sudo ${base_dir}/tmp/php82/php/bin/php go-pear.phar
sudo ${base_dir}/tmp/php82/php/bin/pear config-get php_dir

sudo ${base_dir}/tmp/php82/php/bin/pecl channel-update pecl.php.net
#sudo ${base_dir}/tmp/php82/php/bin/pecl install zendopcache
sudo ${base_dir}/tmp/php82/php/bin/pecl install redis
#sudo ${base_dir}/tmp/php82/php/bin/pecl install libsodium

echo "memory_limit=1G" >> ${base_dir}/tmp/php82/php/lib/php.ini
echo "opcache.enable_cli = 'On'" >> ${base_dir}/tmp/php82/php/lib/php.ini
echo "extension=redis.so" >> ${base_dir}/tmp/php82/php/lib/php.ini
#echo "extension=sodium.so" >> ${base_dir}/tmp/php82/php/lib/php.ini
echo "extension=swoole.so" >> ${base_dir}/tmp/php82/php/lib/php.ini
echo "swoole.use_shortname = 'Off'" >> ${base_dir}/tmp/php82/php/lib/php.ini

${base_dir}/tmp/php82/php/bin/php -v
${base_dir}/tmp/php82/php/bin/php -m
${base_dir}/tmp/php82/php/bin/php --ri swoole
#${base_dir}/tmp/php82/php/bin/php --ri yasd

cd ${base_dir}/tmp/php82 || exit
wget https://mirrors.aliyun.com/composer/composer.phar
${base_dir}/tmp/php82/php/bin/php composer.phar

echo -e "\033[42;37m Build Completed :).\033[0m\n"
65 changes: 41 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,52 @@
# 构建适用于 Swoole Hyperf 的 PHP 开发环境
**本脚本仅适用于开发,上线部署请使用项目仓库中的容器脚本。**

**NOTICE 每次执行脚本均会删除所有 tmp 目录的东西 由于偷懒为将编译好的php指定到固定目录或添加是否删除确认 所以请自觉注意下(**
[//]: # (**NOTICE 每次执行脚本均会删除所有 tmp 目录的东西 由于偷懒为将编译好的php指定到固定目录或添加是否删除确认 所以请自觉注意下(**)

适用环境: ubuntu 20.04
**请自行阅读并调整脚本内容后使用**

适用环境: ubuntu 20.04+ / macos apple silicon

**默认安装**
* swoole
* redis
* libsodium ( 这是上游 jwt库 强制要求的 事实上早在很久之前这个包已纳入php内核 )
* composer
* yasd swoole官方的调试工具 ( 类型xdebug 对于hyperf是否有用请看自身 )
* Swoole Tracker 官方的内存泄漏检测 ( 仅php80 )

## PHP 8.0 with Swoole
* ``sudo bash php-80.sh`` 一路回车即可
* 请自行将所需php与composer绑定到环境变量
* PHP 位置 ./tmp/phpxx/php/bin/php
* Composer 位置 ./tmp/phpxx/composer.phar

## Set PHP 8.0 Env
* ``sudo bash setenv_php80.sh``
* 只软连接了 php 与 composer 俩个必要命令

## PHP 8.1 with Swoole
* ``sudo bash php-81.sh`` 一路回车即可
* 实验性内容
* hyperf 2.2 绝大多数包未能支持
* libsodium 未能支持 上游 jwt库 也不听网友建议 删除这个没用库的依赖( 就离谱

## Set PHP 8.1 Env
* ``sudo bash setenv_php81.sh``

[//]: # (* libsodium ( 这是上游 jwt库 强制要求的 事实上早在很久之前这个包已纳入php内核 ))
[//]: # (* yasd swoole官方的调试工具 ( 类型xdebug 对于hyperf是否有用请看自身 ))
[//]: # (* Swoole Tracker 官方的内存泄漏检测 ( 仅php80 ))

[//]: # (## PHP 8.0 with Swoole)

[//]: # (* ``sudo bash php-80.sh`` 一路回车即可)

[//]: # (* 请自行将所需php与composer绑定到环境变量)

[//]: # (* PHP 位置 ./tmp/phpxx/php/bin/php)

[//]: # (* Composer 位置 ./tmp/phpxx/composer.phar)

[//]: # ()
[//]: # (## Set PHP 8.0 Env)

[//]: # (* ``sudo bash setenv_php80.sh`` )

[//]: # (* 只软连接了 php 与 composer 俩个必要命令)

[//]: # ()
[//]: # (## PHP 8.1 with Swoole)

[//]: # (* ``sudo bash php-81.sh`` 一路回车即可)

[//]: # (* 实验性内容 )

[//]: # (* hyperf 2.2 绝大多数包未能支持)

[//]: # (* libsodium 未能支持 上游 jwt库 也不听网友建议 删除这个没用库的依赖( 就离谱)

[//]: # ()
[//]: # (## Set PHP 8.1 Env)

[//]: # (* ``sudo bash setenv_php81.sh``)


7 changes: 7 additions & 0 deletions setenv_macos_php82.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "Set environment variables for PHP 8.2"
base_dir=$(pwd)

sudo ln -s -f ${base_dir}/macos/php82/php/bin/php /usr/local/bin/php
sudo ln -s -f ${base_dir}/macos/php82/composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
echo "Done"
7 changes: 7 additions & 0 deletions setenv_php82.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
echo "Set environment variables for PHP 8.2"
base_dir=$(cd "$(dirname "$0")";pwd)

sudo ln -s -f ${base_dir}/tmp/php82/php/bin/php /usr/bin/php
sudo ln -s -f ${base_dir}/tmp/php82/composer.phar /usr/bin/composer
sudo chmod +x /usr/bin/composer
echo "Done"

0 comments on commit 835d261

Please sign in to comment.