Quickly build the local development environment of Hyperf framework in Windows system under Docker container


Hyperf framework introduction

Hyperf is a high-performance and highly flexible progressive PHP coroutine framework with built-in coroutine server and a large number of commonly used components. Compared with the traditional PHP-FPM , the performance is qualitatively improved. It provides ultra-high performance while maintaining extremely high performance. Flexible scalability, standard components are PSR standard, based on a powerful dependency injection design, to ensure that most components or classes are replaceable and reusable.

Developed under Docker

Assuming that your local environment does not meet Hyperf , or you are not so familiar with the environment configuration, you can run and develop the Hyperf project through the following methods. Here we mainly explain the development under the Windows

Download and install docker

To develop in the Windows system, we need to install docker for windows first, first go directly to the docker official website: https://www.docker.com
Then click successively: Get started -> Download for Windows , you can download docker
The download package may be relatively large. If the network is not very good, you need to wait patiently. After the download is complete, proceed to the next step to install

Start to report WSL2 problem

After the installation is complete, the first time you open it may report WSL2 problems, directly follow the URL address in the prompt to open,
, Download WSL2 Linux kernel update package for x64 computer, after downloading, install it directly and restart the docker client.

Pull the docker image (hyperf official)

Here we use the command line tool powershell win + r at the same time, and then enter powershell and press Enter to open the command line tool
Then enter in the command line: docker pull hyperf/hyperf:7.4-alpine-v3.11-swoole , after downloading the docker image, we can use docker image ls view the list of mirrors, or you can see it in the Images of the docker client.

Bind the local project directory to the directory in the mirror

Assuming that the directory D:\project\hyperf of my local computer is a hyperf project, and the port is the default 9501, now we bind this directory to the docker image to achieve development in docker, the command is as follows:
docker run -d --name hyperf -v D:\project\hyperf:/data/hyperf -p 9501:9501 -it --privileged -u root --entrypoint /bin/sh hyperf/hyperf:7.4-alpine-v3.11-swoole
Since we have pulled the image earlier, this command will create a hyperf . We can use the command dcoker ps NAMES of the container we just ran hyperf , and the port number is 9501

Enter the container

Earlier we have created a project called hyperf, so we need to execute the command docker exec -it hyperf bash to enter the project mirror

Install Composer inside the container

First download composer.phar , you can download it in the following ways, the viewing address of different versions of composer is https://github.com/composer/composer/releases :
wget https://github.com/composer/composer/releases/download/2.1.12/composer.phar
php -r "readfile('https://getcomposer.org/installer');" | php
After the download is complete, execute the command chmod u+x composer.phar to add execution permissions
Then run the command line mv composer.phar /usr/local/bin/composer , move composer.phar to the /usr/local/bin directory and rename it to composer, then the global call can be realized
Then run the command composer to test whether the installation is successful

Set up Composer domestic mirror

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer Cloud Mirror 061a58cbd7618c
Tencent Cloud Mirror composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer
Domestic Composer mirror composer config -g repo.packagist composer https://packagist.phpcomposer.com
Contact the mirror binding and restore to the official mirror composer config -g --unset repos.packagist

Start the Hyperf service

Since our project is bound to the mirror directory is /data/hyperf , so we can execute cd /data/hyperf to enter the project directory
Then execute the command php bin/hyperf.php start to start the service. If there is an error message, solve it in turn according to the error message and then restart
After starting the service, you can press Ctrl+C at the same time to stop the service

Test service

After the service is started, directly enter address bar of the browser, and then it can be accessed normally, indicating that the service has been started successfully. At this point, it means that the development environment is basically set up and you can happily Coding...

阅读 1.3k


1.8k 声望
135 粉丝
0 条评论


1.8k 声望
135 粉丝