Detailed explanation of the complete usage example of developing hyperf under Docker

Detailed explanation of the complete usage example of developing hyperf under Docker

Hyperf official website
Hyperf official documentation installation

1. Docker usage

  • docker search lists hyperf images
  • Docker pull downloads the image to the local
  • Run the image and mount the directory to the folder under the current directory, and run it in the same way as /bin/sh
  • Enter the hyperf-skeleton directory, which is mounted locally
$ 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 image container is running, install Composer in the container

First download Composer into the docker container

$ wget https://mirrors.aliyun.com/composer/composer.phar

3. Modify execution permissions

This operation is to solve the limitation that Composer does not allow root permissions to execute

At the same time, when switching users, you can directly operate

777 authorization is not recommended in production environments

$ chmod -R 777 ./composer.phar

4. Move composer to the bin directory and rename it to composer

777 authorization is not recommended in production environments

$ mv composer.phar /usr/local/bin/composer

5. Change the root password

At the same time, because we don't know the root password, we need to enter it twice to change the password, and it will not be displayed. Please note

$ passwd root

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

The official image is Linux alpine

$ cat /etc/os-release

7. Create a group with a specified GID

The official image is Linux alpine. The commands are different from the Centos commands used by many friends. If you have created your own image, just follow the distribution 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. Allow the newly created user to use su - to the root user,

$ chmod 4755 /bin/busybox

10. Switch to www user and execute composer

su www switch user
whoami View current user

$ su www
$ whoami

11. Set the Composer image to Alibaba Cloud image to speed up domestic downloads

Of course, whether to use Alibaba Cloud images depends on personal needs (no advertising suspicion)

$ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

12. Install the hyperf skeleton via Composer

When installing, choose according to your personal needs!

$ composer create-project hyperf/hyperf-skeleton

13. Check the configuration and other information

In general, the official source images of hyperf are configured. The following is just a command to view swoole

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

14. Write the following information in php.ini

Pay special attention to the capital O in Off.

extension="grpc.so"
extension="redis.so"
extension="swoole.so"
swoole.use_shortname = 'Off'

15. Extensions with compatibility issues

  • Since Hyperf is based on Swoole coroutine implementation
  • 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) will cause certain compatibility issues and cannot be used or coexist with it:
  • xhprof
  • xdebug
  • blackfire
  • trace
  • uopz

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to elegantly debug Hyperf in PhpStorm
  • Arrangement and supplement of PHP framework knowledge points
  • Example explanation of Workerman framework in PHP
  • A brief discussion on the advantages and disadvantages of the seven commonly used PHP frameworks
  • Analysis of the automatic loading and autonomous object creation operation examples of the PHP framework CI (codeigniter)
  • Example of using JWT in ThinkPHP5 framework
  • Thinkphp5 framework exception handling operation example analysis
  • Example of introducing Markdown editor in Thinkphp5 framework
  • A brief discussion on reducing the scanning time of Hyperf framework

<<:  Detailed explanation of how to monitor MySQL statements

>>:  Implementation of Portals and Error Boundary Handling in React

Recommend

JS implements layout conversion in animation

When writing animations with JS, layout conversio...

A line of CSS code that crashes Chrome

General CSS code will only cause minor issues wit...

Summary of commonly used tags in HTML (must read)

Content Detail Tags: <h1>~<h6>Title T...

MySQL stored procedure method example of returning multiple values

This article uses an example to describe how to r...

Detailed explanation of MySQL Truncate usage

Table of contents MySQL Truncate usage 1. Truncat...

7 interview questions about JS this, how many can you answer correctly

Preface In JavaScript, this is the function calli...

Docker Basic Tutorial: Detailed Explanation of Dockerfile Syntax

Preface Dockerfile is a script interpreted by the...

Common methods of Vue componentization: component value transfer and communication

Related knowledge points Passing values ​​from pa...

How to insert a link in html

Each web page has an address, identified by a URL...

Detailed explanation and summary of the URL for database connection

Detailed explanation and summary of the URL for d...

CSS Paint API: A CSS-like Drawing Board

1. Use Canvas images as CSS background images The...

HTML Tutorial: Collection of commonly used HTML tags (6)

These introduced HTML tags do not necessarily ful...

Vue complete code to implement single sign-on control

Here is a Vue single sign-on demo for your refere...

MySQL statement summary

Table of contents 1. Select database USE 2. Displ...

Detailed explanation of how to find the location of the nginx configuration file

How can you find the location of the configuratio...