From 835d261f2fde0080280f4057bf58349134e23f3b Mon Sep 17 00:00:00 2001 From: lixworth Date: Fri, 17 Nov 2023 22:29:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20php8.2.12=20?= =?UTF-8?q?=E4=B8=8E=20swoole=20v5.1=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macos-php-8212-v5.sh | 88 +++++++++++++++++++++++++++++++++++++++++++ php-8212-v5.sh | 81 +++++++++++++++++++++++++++++++++++++++ readme.md | 65 ++++++++++++++++++++------------ setenv_macos_php82.sh | 7 ++++ setenv_php82.sh | 7 ++++ 5 files changed, 224 insertions(+), 24 deletions(-) create mode 100644 macos-php-8212-v5.sh create mode 100644 php-8212-v5.sh create mode 100644 setenv_macos_php82.sh create mode 100644 setenv_php82.sh diff --git a/macos-php-8212-v5.sh b/macos-php-8212-v5.sh new file mode 100644 index 0000000..15e5fe0 --- /dev/null +++ b/macos-php-8212-v5.sh @@ -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" \ No newline at end of file diff --git a/php-8212-v5.sh b/php-8212-v5.sh new file mode 100644 index 0000000..4fed09b --- /dev/null +++ b/php-8212-v5.sh @@ -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" diff --git a/readme.md b/readme.md index bd5134d..4f43974 100644 --- a/readme.md +++ b/readme.md @@ -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``) diff --git a/setenv_macos_php82.sh b/setenv_macos_php82.sh new file mode 100644 index 0000000..ce67494 --- /dev/null +++ b/setenv_macos_php82.sh @@ -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" \ No newline at end of file diff --git a/setenv_php82.sh b/setenv_php82.sh new file mode 100644 index 0000000..ba3de02 --- /dev/null +++ b/setenv_php82.sh @@ -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" \ No newline at end of file