Hyperf所需安装条件PHP>=7.2SwoolePHP扩展>=4.4,和ShortNameOpenSSLPHP扩展JSONPHP扩展PDOPHP扩展(如果需要使用MySQL客户端)RedisPHP扩展(如果需要使用Redis客户端)ProtobufPHP扩展(如果需要使用gRPCserver或client)installphp7.2wgethttps://www.php.net/distributions/php-7.2.30.tar.gzinstallphpdependenciesyuminstall-ygccgcc-c++makezlibzlib-develpcrepcre-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develglibcglibc-develglib2glib2-develbzip2bzip2-develncursesncurses-develcurlcurl-devele2fsprogse2fsprogdevelkrb5krb5-developensslopenssl-developenldapopenldap-develnss_ldapopenldap-clientsopenldap-serverslibxsltlibxslt-devel解压php7.2编译安装./configure--prefix=/usr/local/src/php-7.2.30\--with-config-文件路径=/usr/local/src/php-7.2.30/etc\--with-curl\--with-mhash\--with-gd\--with-gettext\--with-iconv-dir\--with-kerberos\--with-libdir=lib64\--with-libxml-dir\--with-openssl\--with-pcre-regex\--with-pdo-sqlite\-和-梨\--with-xmlrpc\--with-xsl\--with-zlib\--enable-fpm\--enable-bcmath\--enable-libxml\--enable-inline-optimization\--enable-mbregex\--enable-mbstring\--enable-opcache\--enable-pcntl\--enable-shmop\--enable-soap\--enable-sockets\--enable-sysvmsg\--enable-sysvsem\--enable-sysvshm\--enable-xml\--enable-zip\--enable-static\--enable-mysqlnd\--with-mysqli=mysqlnd\--with-pdo-mysql=mysqlnd\--with-freetype-dir\--with-jpeg-dir\--with-png-dir\--disable-debug\--disable-fileinfo编译安装make&&makeinstall打开后修改环境变量vi/etc/profile文件末尾输入PATH=$PATH:你的编译目录exportPATH例如:PATH=$PATH:/usr/local/php-7.2.19/binexportPATH然后保存并运行命令PATH=$PATH:/usr/local/src/php-7.2.30/binexportPATHsource/etc/profile使配置生效2处理配置文件,启动文件展开要价目录/usr/local/src/php-7.2.30/lib/php/extensions/no-debug-non-zts-20170718/复制php.ini的配置文件cp/usr/local/src/php-7.2.30/php.ini-production/usr/local/src/php-7.2.30/etc/php.ini查看php.iniphp--inicopyphp-fpm.confcd/usr/local/src/php-7.2.30/etcpphp-fpm.conf.defaultphp-fpm.conf复制www.confcd/usr/local/src/php-7.2.30/etc/php-fpm.dcpwww.conf.defaultwww.conf修改配置文件vim/usr/local/src/php-7.2.30/etc/php-fpm.conf去掉pid=run/php-fpm.pid前的分号vim/usr/local/src/php-7.2.30/etc/php-fpm.d/www.conf修改用户和组用户为当前用户(也可以不改,用户和用户组nobody会被添加default)执行命令将解压目录下的fpm启动文件复制到指定目录下cp/usr/local/src/php-7.2.30/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm5.修改执行文件权限chmod+x/etc/init.d/php-fpm6.启动php-fpmcd/etc/init.d./php-fpmstart编写php启动脚本pid文件/usr/local/src/php-7.2.30/var/run/php-fpm.pidphp-fpm配置文件/usr/local/src/php-7.2.30/etc/php-fpm.conf执行文件/usr/local/src/php-7.2.30/sbin/php-fpm创建php-fpm.service文件vim/usr/lib/systemd/system/php-fpm.service为php-fpm编写脚本#systemd服务文件[Unit]Description=ThePHPFastCGIProgressManagerAfter=syslog.target.network.target[Service]Type=forkingPIDFile=/usr/local/src/php-7.2.30/var/run/php-fpm.pidExecStart=/usr/local/src/php-7.2.30/sbin/php-fpmExecStop=/bin/pkill-9php-fpmExecReload=/bin/kill-USR2$MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target执行启动命令systemctlenablephp-fpm.servicestartphpsystemctlstartphp-fpm.service生产视图进程根364211018:45?00:00:00php-fpm:主进程(/usr/local/src/php-7.2.30/etc/php-fpm.conf)没有人3642236421018:45?00:00:00php-fpm:池wwwnobody3642336421018:45?00:00:00php-fpm:poolwwwroot3647136177018:52pts/100:00:00grep--color=autophpstopphpsystemctlstartphp-fpm.service生产视图进程root3648736177018:53pts/100:00:00grep--color=autophprestartphpsystemctlrestartphp-fpm.servicecompileinstallswooleextensioncompile安装swoole前先安装相关扩展yuminstallm4yum-yinstallautoconf下载swoole文件解压wgethttps://github.com/swoole/swoole-src/archive/master.zipuzipmaster.zipmvswoole-masterswoole-srccompile安装swoolecdswoole-src&&\phpize&&\./configure&&\make&&sudomakeinstallcheckmaketestenableswooleextension编译安装到系统成功,需要在php.ini中添加一行extension=swoole.so来启用swoole扩展php-m检查是否有swoolecompileinstallredisextensioninstallrediswgethttp://下载.redis.io/releases/redis-5.0.8.tar.gztarxzfredis-5.0.8.tar.gzcdredis-5.0.8make修改redis配置文件vim/usr/local/src/redis-5.0.8/redis.conf将daemonizeno改为daemonizeyes该选项表示redis将在后台运行,并将redis添加到系统服务#systemdservicefileforredis#[Unit]Description=TheRedisProgressManagerAfter=syslog.target.network.target[Service]Type=forkingPIDFile=/var/run/redis_6379.pidExecStart=/usr/local/src/redis-5.0.8/src/redis-server/usr/local/src/redis-5.0.8/redis.confExecStop=/bin/kill-sQUIT$MAINPIDEExecReload=/bin/kill-sHUP$MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target安装phpredis扩展下载phprediswgethttps://github.com/phpredis/phpredis/archive/develop。zipunzipdevelop.zimvphpredis-developphpredis为phpredis生成.configure文件/usr/local/src/php-7.2.30/bin/phpize生成.configure文件compile./configure--with-php-config=/usr/local/src/php-7.2.30/bin/php-configmake&&makeinstallrestartphpsystemctlrestartphp-fpm.servicephp-m可以看到有redis写的测试文件cd/usr/local/varvimphp.phpconnect('127.0.0.1',6379);$redis->set("name","小雪狼");echo$redis->get("名字");编译安装Protobuf扩展下载最新的protobufwgethttps://github.com/allegro/php-protobuf/archive/master.zipunzipmaster.zipcdphp-protobuf-master为protobuf生成.configure文件/usr/local/src/php-7.2.30/bin/phpize由.configure文件编译生成。/configure--with-php-config=/usr/local/src/php-7.2.30/bin/php-configmake&&makeinstallinstallphpprotobufwgethttps://github。com/allegro/php-protobuf/archive/master.zipunzipmaster.zipcdphp-protobuf-masteryuminstallphp-devel(安装依赖,如果没有安装)/usr/local/src/php-7.2.30/bin/phpize./configure--with-php-config=/usr/local/src/php-7.2.30/bin/php-configmake&&makeinstall//然后添加extension="protobuf.so",然后重启php和nginx。
