SoFunction
Updated on 2025-03-09

Detailed explanation of the complete use example of hyperf development under Docker

HyperfOfficial website
Hyperf Official document installation

1. Docker usage

  • docker search lists hyperf images
  • docker pull download image to local
  • Run the image and mount the directory to the folder in the current directory, and run it in the /bin/sh method.
  • Enter the hyperf-skeleton directory, which is a local affiliation
$ docker search hyperf 
$ docker pull hyperf/hyperf 
$ docker run -v $PWD/:/hyperf-skeleton -p 9501:9501 -it --entrypoint /bin/sh hyperf/hyperf
$ cd hyperf-skeleton

2. After the mirror container is run, and install Composer in the container

Download Composer first and enter the docker container

$ wget /composer/

3. Modify execution permissions

This operation is to resolve the limitation that Composer does not allow root permission execution

When switching users, you can operate directly

Not recommended in production environment 777 Authorization method

$ chmod -R 777 ./

4. Move the composer to the bin directory and change the name to composer

Not recommended in production environment 777 Authorization method

$ mv  /usr/local/bin/composer

5. Modify the root password

At the same time, because we don't know the root password, we will make changes first
The password needs to be entered twice and will not be displayed. Please note

$ passwd root

6. You can check the Linux distribution version (the commands will be different)

The official image is Linux's alpine

$ cat /etc/os-release

7. Create a group with a specified GID

The official image of the alpine of Linux is different from the Centos command used by many friends.
If it is a created image by yourself, just follow the release version command

$ addgroup -g 10001 -S www

8. Create a user with a specified UID

Specify the shell, so that it belongs to the specified user group.

$ adduser www -u 20001 -D -S -s /bin/bash -G www

9. Let the newly created users use su - to root user,

$ chmod 4755 /bin/busybox

10. Switch to www. User executes composer

su www switch user
whoami View current user

$ su www
$ whoami

11. Set the Composer image to Alibaba Cloud image to accelerate domestic download speed

Of course, whether to use Alibaba Cloud mirror to view personal needs (no suspicion of advertising)

$ composer config -g  composer /composer

12. Install the hyperf skeleton through Composer

When installing, choose to look at your personal needs!

$ composer create-project hyperf/hyperf-skeleton

13. Check the configuration and other information

Generally speaking, the official source image of hyperf is configured
The following is just a command
View swoole

$ php --ri swoole
$ php -i | grep ini

14. Write the information inside

Pay special attention that O is capitalized in Off

extension=""
extension=""
extension=""
swoole.use_shortname = 'Off'

15. Extensions with compatibility issues

  • Since Hyperf is implemented based on Swoole coroutine
  • The coroutine function brought by Swoole 4 is unprecedented in PHP, so there are still compatibility issues with many extensions.
  • The following extensions (including but not limited to) can cause certain compatibility issues that cannot be shared or coexist with:
  • xhprof
  • xdebug
  • blackfire
  • trace
  • uopz

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.