# Swoft环境要求 现在我们来介绍如何安装Swoft需要的环境。 ### 环境要求 * PHP > 7.1 * Swoole > 4.3.0 * PHP包管理器Composer * 连接迭代器依赖 pcre 库 * OpenSSL PHP 扩展 * JSON PHP 扩展 * PDO PHP 扩展 (如需要使用到 MySQL 客户端) * Redis PHP 扩展 (如需要使用到 Redis 客户端) ### 课程实验环境 * Linux(本文使用Centos6.8 64位) * 安装git * PHP7.3.8 * Swoole4.4 ### 1、安装依赖 这个根据用户自己的需求安装相关依赖,依赖的安装可以根据php编译的时候带上的参数决定。 ```shell yum -y install \ gcc gcc-c++ wget vim make cmake automake autoconf kernel-devel ncurses-devel \ libxml2-devel pcre-devel openssl openssl-devel curl-devel libjpeg-devel \ libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file \ bison bison-devel patch mlocate flex diffutils readline-devel glibc-devel \ glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel gmp-devel \ libxslt-devel git libevent libevent-devel perl-ExtUtils-MakeMaker package xz ``` ### 2、安装Git ```shell yum -y remove git wget https://www.kernel.org/pub/software/scm/git/git-2.6.0.tar.gz --no-check-certificate tar zxvf git-2.6.0.tar.gz cd git-2.6.0 ./configure --prefix=/usr/local/git make make install echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile source /etc/profile ``` 给当前登陆的linux用户设置环境变量,当你使用的账号是非root账号设置环境变量使用git ```shell echo "export PATH=$PATH:/usr/local/git/bin" >> ~/.bashrc source ~/.bashrc ``` 如果使用git clone出现 Peer certificate cannot be authenticated with known CA certificates 则可以关闭证书验证解决 ```shell git config --global http.sslVerify false ``` ### 3、安装php 我编译的参数大家可以进行参考不一定需要跟我的一摸一样。 ```shell wget https://www.php.net/distributions/php-7.3.8.tar.gz --no-check-certificate tar zxvf php-7.3.8.tar.gz cd php-7.3.8 ./configure --prefix=/usr/local/php \ --enable-fpm \ --with-config-file-path=/etc \ --with-libxml-dir --with-openssl \ --with-mysqli \ --enable-bcmath \ --with-bz2 \ --enable-calendar \ --with-curl \ --enable-exif \ --with-pcre-dir \ --enable-ftp \ --with-openssl-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-mbstring \ --with-onig \ --with-pdo-mysql \ --with-readline \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-xmlrpc \ --with-xsl \ --with-pear \ --enable-shared \ --enable-inline-optimization \ --disable-debug \ --enable-xml \ --with-sqlite3 \ --with-iconv \ --with-cdb \ --enable-dom \ --enable-fileinfo \ --enable-filter \ --enable-json \ --enable-mbregex \ --enable-mbregex-backtrack \ --enable-pdo \ --with-pdo-sqlite \ --enable-session \ --enable-simplexml \ --enable-opcache \ --enable-mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-maintainer-zts make make install ``` 建立php相关命令的软连接 ```shell ln -s /usr/local/php/bin/php /usr/bin/php ln -s /usr/local/php/bin/phpize /usr/bin/phpize ln -s /usr/local/php/bin/php-config /usr/bin/php-config ``` ### 4、安装Swoole扩展 我这里使用的Swoole扩展是目前最新的,编译最新Swoole需要gcc4.8以上,如果你的gcc低于这个版本则需要升级。 ```shell gcc --version #查看版本 ``` 升级gcc的教程 升级gcc ```shell git clone https://gitee.com/swoole/swoole.git cd swoole phpize ./configure \ --with-php-config=/usr/local/php/bin/php-config \ --enable-openssl \ --enable-sockets \ --enable-mysqlnd make clean make make install ``` 关于参数问题可以参考 编译参数 ### 5、让php支持swoole ```shell echo "extension=swoole.so" >> /etc/php.ini ``` ### 6、安装Redis的php扩展 Redis扩展的源码地址:http://pecl.php.net/package/redis ```shell wget http://pecl.php.net/get/redis-5.0.2.tgz tar -zxvf redis-5.0.2.tgz cd redis-5.0.2 phpize ./configure --with-php-config=/usr/local/php/bin/php-config make make install ``` ### 错误解决 ```shell configure: error: Please reinstall the libzip distribution ``` 需要重新安装 `libzip` ```shell wget https://libzip.org/download/libzip-1.5.1.tar.gz --no-check-certificate tar -zxvf libzip-1.5.1.tar.gz cd libzip-1.5.1 mkdir build cd build cmake .. make && make install ``` 注意:如果提示cmake版本过低,需新版本,则需要重新安装cmake。 ```shell yum remove cmake wget https://cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz --no-check-certificate tar -zxvf cmake-3.10.2-Linux-x86_64.tar.gz mv cmake-3.10.2-Linux-x86_64 /usr/local/cmake echo "export CMAKE_HOME=/usr/local/cmake" >> /etc/profile echo "export PATH=$PATH:$CMAKE_HOME/bin" >> /etc/profile source /etc/profile ``` ```shell configure: error: off_t undefined; check your library configuration ``` 安装swoole错误 ```shell configure.ac:3: error: Autoconf version 2.68 or higher is required ``` 需要重新安装更高版本的 `autoconf` ```shell yum remove autoconf -y wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar -zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure make make install ```