宝塔安装Hyperf

通过 Composer 创建项目

 $ sudo composer create-project hyperf/hyperf-skeleton 
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Creating a "hyperf/hyperf-skeleton" project at "./hyperf-skeleton"
Installing hyperf/hyperf-skeleton (v3.0.2)
  - Downloading hyperf/hyperf-skeleton (v3.0.2)
  - Installing hyperf/hyperf-skeleton (v3.0.2): Extracting archive
Created project in /www/wwwroot/hyperf.yshuq.com/hyperf-skeleton
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> Installer\Script::install
Setting up optional packages
Setup data and cache dir
Removing installer development dependencies

  What time zone do you want to setup ?
  [n] Default time zone for php.ini
Make your selection or type a time zone name, like Asia/Shanghai (n):
n

  Do you want to use Database (MySQL Client) ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): yes 
Invalid answer

  Do you want to use Database (MySQL Client) ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): y
  - Adding package hyperf/database (~3.0.0)
  - Adding package hyperf/db-connection (~3.0.0)

  Do you want to use Redis Client ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): y
  - Adding package hyperf/redis (~3.0.0)
  - Copying config/autoload/redis.php

  Which RPC protocol do you want to use ?
  [1] JSON RPC with Service Governance
  [2] JSON RPC
  [3] gRPC
  [n] None of the above
  Make your selection or type a composer package name and version (n): n

  Which config center do you want to use ?
  [1] Apollo
  [2] Aliyun ACM
  [3] ETCD
  [4] Nacos
  [n] None of the above
  Make your selection or type a composer package name and version (n): n

  Do you want to use hyperf/constants component ?
  [y] yes
  [n] None of the above
  Make your selection (n): y
  - Adding package hyperf/constants (~3.0.0)
  - Copying app/Constants/ErrorCode.php
  - Copying app/Exception/BusinessException.php

  Do you want to use hyperf/async-queue component ? (A simple redis queue component)
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/async-queue (~3.0.0)
  - Copying config/autoload/async_queue.php
  - Copying app/Process/AsyncQueueConsumer.php
  - Copying app/Listener/QueueHandleListener.php
  - Copying config/autoload/redis.php

  Do you want to use hyperf/amqp component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/amqp (~3.0.0)
  - Copying config/autoload/amqp.php

  Do you want to use hyperf/model-cache component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/model-cache (~3.0.0)
  - Copying app/Model/Model.php
  - Copying config/autoload/databases.php
  - Copying config/autoload/redis.php

  Do you want to use hyperf/elasticsearch component ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/elasticsearch (~3.0.0)

  Do you want to use hyperf/tracer component ? (An open tracing protocol component, adapte with Zipkin etc.)
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/tracer (~3.0.0)
  - Copying config/autoload/opentracing.php
Remove installer
Removing composer.lock from .gitignore
Removing Expressive installer classes, configuration, tests and docs
Loading composer repositories with package information

Problem 1
    - hyperf/redis[v3.0.0-alpha.1, ..., v3.0.35] require ext-redis * -> it is missing from your system. Install or enable PHP's redis extension.
    - hyperf/redis[v3.0.36, ..., 3.0.x-dev] require ext-redis <6.0 -> it is missing from your system. Install or enable PHP's redis extension.
    - hyperf/redis[v3.0.39, ..., 3.0.x-dev] require ext-redis ^5.0|^6.0 -> it is missing from your system. Install or enable PHP's redis extension.
    - Root composer.json requires hyperf/redis ~3.0.0 -> satisfiable by hyperf/redis[v3.0.0-alpha.1, ..., 3.0.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /www/server/php/81/etc/php-cli.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-redis` to temporarily ignore these required extensions.
ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com$ 

安装redis扩展之后,删除安装的代码,重新执行安装命令,安装完成如下;

$ sudo composer create-project hyperf/hyperf-skeleton
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Creating a "hyperf/hyperf-skeleton" project at "./hyperf-skeleton"
Installing hyperf/hyperf-skeleton (v3.0.2)
  - Installing hyperf/hyperf-skeleton (v3.0.2): Extracting archive
Created project in /www/wwwroot/hyperf.yshuq.com/hyperf-skeleton
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> Installer\Script::install
Setting up optional packages
Setup data and cache dir
Removing installer development dependencies

  What time zone do you want to setup ?
  [n] Default time zone for php.ini
Make your selection or type a time zone name, like Asia/Shanghai (n):
n

  Do you want to use Database (MySQL Client) ?
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (yes): y
  - Adding package hyperf/database (~3.0.0)
  - Adding package hyperf/db-connection (~3.0.0)
  ......
  ......
  ......
  Do you want to use hyperf/tracer component ? (An open tracing protocol component, adapte with Zipkin etc.)
  [y] yes
  [n] None of the above
  Make your selection or type a composer package name and version (n): y
  - Adding package hyperf/tracer (~3.0.0)
  - Copying config/autoload/opentracing.php
Remove installer
Removing composer.lock from .gitignore
Removing Expressive installer classes, configuration, tests and docs
Loading composer repositories with package information
Updating dependencies
Lock file operations: 145 installs, 0 updates, 0 removals
  - Locking composer/pcre (3.1.1)
  - Locking composer/semver (3.4.0)
  - Locking composer/xdebug-handler (3.0.3)
  - Locking doctrine/inflector (2.0.8)
  - Locking doctrine/instantiator (1.5.0)
  - Locking elasticsearch/elasticsearch (v7.17.2)
  - Locking ezimuel/guzzlestreams (3.1.0)
  - Locking ezimuel/ringphp (1.2.2)
  - Locking fig/http-message-util (1.1.5)
  - Locking friendsofphp/php-cs-fixer (v3.38.0)
  - Locking graham-campbell/result-type (v1.1.1)
  - Locking symfony/stopwatch (v6.3.0)
  - Locking symfony/string (v6.3.5)
  - Locking symfony/translation (v6.3.7)
  - Locking symfony/translation-contracts (v3.3.0)
  - Locking theseer/tokenizer (1.2.1)
  - Locking vlucas/phpdotenv (v5.5.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 145 installs, 0 updates, 0 removals
  - Downloading composer/pcre (3.1.1)
  - Downloading symfony/stopwatch (v6.3.0)
  - Downloading symfony/process (v6.3.4)
  - Installing openzipkin/zipkin (3.2.0): Extracting archive
  - Installing jcchavezs/zipkin-opentracing (2.0.3): Extracting archive
  - Installing opentracing/opentracing (1.0.2): Extracting archive
  - Installing hyperf/tracer (v3.0.39): Extracting archive
  - Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
  - Installing mockery/mockery (1.6.6): Extracting archive
  - Installing phpstan/phpstan (1.10.41): Extracting archive
  - Installing swoole/ide-helper (5.1.0): Extracting archive
35 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> rm -rf runtime/container
65 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com$ 

修改文件用户root为www

ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com$ ls -al
total 32
drwxr-xr-x  4 www  www  4096 Nov  9 19:01 .
drwxr-xr-x 13 root root 4096 Nov  9 18:21 ..
-rwxr-xr-x  1 www  www   138 Nov  9 18:21 404.html
-rwxr-xr-x  1 www  www     1 Nov  9 18:21 .htaccess
drwxr-xr-x  9 root root 4096 Nov  9 19:02 hyperf-skeleton
-rwxr-xr-x  1 www  www   917 Nov  9 18:21 index.html
-rw-r--r--  1 root root   49 Nov  9 18:21 .user.ini
drwxr-xr-x  3 www  www  4096 Nov  9 18:22 .well-known
ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com$ sudo chown -R www:www ./hyperf-skeleton/
ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com$ ls -al
total 32
drwxr-xr-x  4 www  www  4096 Nov  9 19:01 .
drwxr-xr-x 13 root root 4096 Nov  9 18:21 ..
-rwxr-xr-x  1 www  www   138 Nov  9 18:21 404.html
-rwxr-xr-x  1 www  www     1 Nov  9 18:21 .htaccess
drwxr-xr-x  9 www  www  4096 Nov  9 19:02 hyperf-skeleton
-rwxr-xr-x  1 www  www   917 Nov  9 18:21 index.html
-rw-r--r--  1 root root   49 Nov  9 18:21 .user.ini
drwxr-xr-x  3 www  www  4096 Nov  9 18:22 .well-known

启动项目

$ cd hyperf-skeleton
$ php bin/hyperf.php  start
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\RpcClient\Listener\AddConsumerDefinitionListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\JsonRpc\Listener\RegisterProtocolListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
ERROR Swoole short function names must be disabled before the server starts, please set swoole.use_shortname='Off' in your php.ini.

问题: ERROR Swoole short function names must be disabled before the server starts, please set swoole.use_shortname=’Off’ in your php.ini.

解决办法:https://hyperf.wiki/3.0/#/zh-cn/quick-start/questions

Swoole 短名未关闭:

您需要在您的 php.ini 配置文件增加 swoole.use_shortname = 'Off' 配置项

注意该配置必须于 php.ini 内配置,无法通过 ini_set() 函数来重写

当然,也可以通过以下的命令来启动服务,在执行 PHP 命令时关闭掉 Swoole 短名功能

php -d swoole.use_shortname=Off bin/hyperf.php start

现在我们在php.ini里面修改了配置,重启了php 。现在重新启动hyperf

ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com/hyperf-skeleton$ php bin/hyperf.php  start
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\RpcClient\Listener\AddConsumerDefinitionListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\JsonRpc\Listener\RegisterProtocolListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
ERROR Swoole short function names must be disabled before the server starts, please set swoole.use_shortname='Off' in your php.ini.
ubuntu@VM-4-13-ubuntu:/www/wwwroot/hyperf.yshuq.com/hyperf-skeleton$ php -d swoole.use_shortname=Off bin/hyperf.php start
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\RpcClient\Listener\AddConsumerDefinitionListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\JsonRpc\Listener\RegisterProtocolListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\ExceptionHandler\Listener\ExceptionHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\DbConnection\Listener\RegisterConnectionResolverListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Amqp\Listener\BeforeMainServerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\BeforeMainServerStart handled by Hyperf\Process\Listener\BootProcessListener listener.
[DEBUG] Event Hyperf\Framework\Event\OnManagerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\OnStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\MainWorkerStart handled by Hyperf\Amqp\Listener\MainWorkerStartListener listener.
[INFO] Worker#1 started.
[INFO] Process[queue.default.0] start.
[DEBUG] Event Hyperf\Process\Event\BeforeProcessHandle handled by Hyperf\Process\Listener\LogBeforeProcessStartListener listener.
[DEBUG] Event Hyperf\Process\Event\BeforeProcessHandle handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.
[DEBUG] Event Hyperf\Framework\Event\MainWorkerStart handled by Hyperf\ServiceGovernance\Listener\RegisterServiceListener listener.
[INFO] Worker#0 started.
[INFO] HTTP Server listening at 0.0.0.0:9501
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\AfterWorkerStartListener listener.
[DEBUG] Event Hyperf\Framework\Event\AfterWorkerStart handled by Hyperf\Server\Listener\InitProcessTitleListener listener.

Leave a Reply

您的邮箱地址不会被公开。 必填项已用 * 标注