# ubuntu编译安装 php7.3.5+swoole4 **Repository Path**: joker_mm/ubuntu_php7.3.5 ## Basic Information - **Project Name**: ubuntu编译安装 php7.3.5+swoole4 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-12-22 - **Last Updated**: 2022-04-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 开启WSL 控制面板->程序->启动和关闭Windows功能 勾选 适用于Linux的Windows子程序 Windows PowerShell 2.0 ### 设置window subsystem ubuntu默认用root启动 找到ubuntu路径 一般在C:\Users\zhengxm\AppData\Local\Microsoft\WindowsApps下 然后打开cmd执行ubuntu1804.exe config --default-user root 重启子系统就默认用root登入了 ### 下载PHP wget https://www.php.net/distributions/php-7.3.5.tar.gz tar xzf php-7.3.5.tar.gz cd php-7.3.5 ### 安装依赖 sudo apt install -y gcc make openssl curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libcurl4-gnutls-dev libssl-dev ### 依赖安装有误可能是软件源问题 sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup #中科大镜像源 deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ trusty main universe restricted multiverse #保存之后执行更新命令 apt-get update apt-get upgrade ### 执行编译安装 ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=bandit --with-fpm-group=bandit --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts ### 可能遇到的问题 1)openssl问题,建立软连接 find /usr/ -name libssl.so ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib 2)configure: error: Please reinstall the libcurl distribution - apt-get install -y curl libcurl4-gnutls-dev #根据保存信息建立软连接 sudo ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl/curl sudo ln -s /usr/include/x86_64-linux-gnu/curl /usr/include/curl 3)Ubuntu 19.04 PHP 7.3.5 GD库 无法启用 freetype的问题 “freetype-config not found” #参考链接 https://www.doopsky.com/ops/981.html #解决方案 sudo apt install pkg-config sed -i "s/freetype-config/pkg-config/g" ./configure sed -i "s/freetype-config/pkg-config/g" ./ext/gd/config.m4 sed -i "s/FREETYPE2_CONFIG --cflags/FREETYPE2_CONFIG freetype2 --cflags/g" ./configure sed -i "s/FREETYPE2_CONFIG --libs/FREETYPE2_CONFIG freetype2 --cflags/g" ./configure ### 安装PHP sudo make && make install ### php加入系统变量 sudo echo "PATH=$PATH:/usr/local/php/bin">> /etc/profile sudo echo "export PATH">> /etc/profile source /etc/profile ### php命令加入软连接 ln -s /usr/local/php/bin/php /usr/bin/php ### 先找php.ini位置再复制到具体目录 php -i |grep php.ini ### 复制php.ini文件 sudo cp php.ini-development /usr/local/php/lib/php.ini ### 安装swoole #### 如果安装http2需要安装nghttp2 wget https://github.com/nghttp2/nghttp2/releases/download/v1.30.0/nghttp2-1.30.0.tar.bz2 tar -jxvf nghttp2-1.30.0.tar.bz2 cd nghttp2-1.30.0 ./configure make && sudo make install #### 如果安装--enable-async-redis需要安装hiredis wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz tar xzf v0.13.3.tar.gz cd hiredis-0.13.3/ make && sudo make install #### 安装swoole wget https://pecl.php.net/get/swoole-4.8.1.tgz tar xzf swoole-4.8.1.tgz cd swoole-4.8.1 # 建议使用自己php版本的phpize #sudo phpize (ubuntu 没有安装phpize可执行命令:sudo apt-get install php-dev来安装phpize) /usr/local/php/bin/phpize #如果重新安装新扩展需要清空重新编译 sudo make clean ./configure --with-php-config=/usr/local/php/bin/php-config --enable-coroutine --enable-openssl --enable-http2 --enable-async-redis --enable-sockets --enable-mysqlnd sudo make -j sudo make install #### 配置hiredis sudo mkdir /usr/lib/hiredis sudo cp /usr/local/lib/libhiredis.so /usr/lib/hiredis sudo mkdir /usr/include/hiredis sudo cp /usr/local/include/hiredis/hiredis.h /usr/include/hiredis sudo vim /etc/ld.so.conf 文件末尾添加 /usr/local/lib sudo ldconfig #### 配置php.ini extension=swoole #### 升级swoole pecl upgrade swoole ### php8 # 通过运行以下命令,将所有系统软件包更新为最新版本: sudo apt update sudo apt -y upgrade # 升级Ubuntu 20.04/18.04后重新启动建议: sudo systemctl reboot # 添加ondrej PPA存储库 sudo apt install lsb-release ca-certificates apt-transport-https -y sudo add-apt-repository ppa:ondrej/php # 如果报 sudo: add-apt-repository: command not found 执行以下命令安装 sudo apt-get install software-properties-common # 在Ubuntu 20.04下安装PHP 8.0 sudo apt install php8.0 # 安装PHP 8扩展 sudo apt install php8.0- # 一些可用的扩展名如下所示,如: $ sudo apt install php8.0-amqp php8.0-common php8.0-gd php8.0-ldap php8.0-odbc php8.0-readline php8.0-sqlite3 php8.0-xsl php8.0-apcu php8.0-curl php8.0-gmp php8.0-mailparse php8.0-opcache php8.0-redis php8.0-sybase php8.0-yac php8.0-ast php8.0-dba php8.0-igbinary php8.0-mbstring php8.0-pgsql php8.0-rrd php8.0-tidy php8.0-yaml php8.0-bcmath php8.0-dev php8.0-imagick php8.0-memcached php8.0-phpdbg php8.0-smbclient php8.0-uuid php8.0-zip php8.0-bz2 php8.0-ds php8.0-imap php8.0-msgpack php8.0-pspell php8.0-snmp php8.0-xdebug php8.0-zmq php8.0-cgi php8.0-enchant php8.0-interbase php8.0-mysql php8.0-psr php8.0-soap php8.0-xhprof php8.0-cli php8.0-fpm php8.0-intl php8.0-oauth php8.0-raphf php8.0-solr php8.0-xml 例子: sudo apt install php8.0-cli php8.0-common php8.0-imap php8.0-redis php8.0-snmp php8.0-xml # 切换版本 sudo update-alternatives --config php # 安装phpize sudo apt install php8.0-dev 安装之后文件路径 /use/bin/phpize8.0 # 查看swoole信息 php --ri swoole # 关闭 swoole.use_shortname=off php.ini、swoole.ini配置文件路径 /eth/php/*/ ### php配置ssl证书 php.ini开启openssl、curl扩展 curl.cainfo = "D:\phpstudy_pro\certificate\cacert.pem" openssl.cafile = "D:\phpstudy_pro\certificate\cacert.pem" ### Vscode+Swoole提示 1.下载composer.phar文件 https://install.phpcomposer.com/composer.phar 2.将composer.phar移动到与php.exe程序同一个目录,并创建composer.bat composer.bat文件添加如下一段内容 @php "%~dp0composer.phar" % 3.为php程序设置为全局-设置环境变量 4.为swoole项目安装Swoole/ide-helper插件 composer require Swoole/ide-helper