[Full version] Install Cygwin on a Windows system to build a Swoole test environment

Posted May 28, 20207 min read

Foreword

Yesterday, when installing the Swoole debugging environment locally, I encountered several pits. Because my computer is a Windows system, I installed cygwin, but the process was not smooth, and there were problems with the installation terminal. And step by step to check the data pits, and finally the installation was successful. In order to allow others to install successfully at one time, saving a lot of trouble and trouble, I wrote this article specifically, hoping to have something for those in need help.

Download Swoole

Swoole download address: https://github.com/swoole/swoole-src/releases

Open the download address in the browser, slide to the download location, you can download the zip file package or tar.gz file package, the download is complete and wait for later.

Download cygwin

cygwin download address: https://www.cygwin.com/

Open the cygwin official website in the browser, slide to the Installing Cygwin section, click setup-x86_64.exe to download the exe file

Install cygwin

Find the setup-x86_64.exe file you just downloaded, double click to open, and start installing cygwin

  • Step 1:Open the installation interface and click Next

  • Step 2:Select the download source, we directly select Install from Internet by default, and then click Next

  • Step 3:Select the installation directory, you can directly modify the installation directory in the input box, or click Browse to select the directory, click next

  • Step 4:Select the directory for package download, you can directly modify the directory in the input box, or click Browse to select the directory, click next

  • The fifth step:select the network server, just default directly, click to continue to the next step

  • Step 6:Choose a download server URL, we choose http://mirrors.metapeer.com, here, we can also add 163 download server ourselves, the address is http://mirrors.163.com/cygwin/, choose to continue to the next step

  • Step 7:Select the interface of the software package to be installed, select the Category option from the View drop-down

  • Step 8:Search and select the software package to be installed

gcc-core, search for gcc-core in Search, expand Devel, find the blue selected item in the figure below, in the New column, double-click to select

For php and php-devel, search for php in Search, expand Interpreters, find the blue selection in the figure below, double-click to select in the New column, remember php and php- devel

libpcre-devel, search for libpcre-devel in Search, expand Libs, find the blue selected item in the figure below, in the New column, double-click to select

autoconf-archive, search for autoconf-archive in Search, expand Devel, find the blue selected item in the figure below, in the New column, double-click to select

gcc-objc ++, search for gcc-objc ++ in Search, expand Devel, find the blue selected item in the figure below, in the New column, double-click to select

libc ++-devel, search for libc ++-devel in Search, expand Devel, find the blue selected item in the figure below, in the New column, double-click to select

libc ++ 1, search for libc ++ 1 in Search, expand Devel, find the blue selected item in the figure below, in the New column, double-click to select

php-json, search for php-json in Search, expand PHP, find the blue selected item in the figure below, in the New column, double-click to select

pcre2, search for pcre2 in Search, expand Text, find the blue selected item in the figure below, in the New column, double-click to select

libpcre2-devel, search for libpcre2-devel in Search, expand Libs, find the blue selected item in the figure below, in the New column, double-click to select

  • In the last step, select all the software packages, click Next, until the installation is completed, the time may be a bit long, wait patiently

Compile and install Swoole

  • Unzip and put in home directory

Decompress the Swoole compressed package downloaded above and place it in the home directory under the installation directory of cygwin. For convenience, it is renamed as Swoole, of course

  • Open cygwin and enter the Swoole directory

Double-click to run Cygwin software, and then enter the source code of Swoole decompression through the command cd/home/swool/

  • Generate compiled configuration files

In the root directory of Swoole, execute the command phpize to generate the compiled configuration file configure

  • Compile configuration and detect environment and compile and install

After generating the compiled configuration file above, enter the command ./configure && make && make install, and then wait for the compilation and installation of Swoole to complete

Check if Swoole is installed successfully

  • Check whether Swoole extension is enabled

After the installation is complete, we enter the command php --ini, you can find the directory location of the php.ini configuration file, you can find that the directory of the configuration file is in /etc/php.ini, and then through vi Edit and view the command vi/etc/php.ini, and enter the last line of the file, and then find that there is a line of extension configuration of extension = swoole.dll, this is because when compiling and installing, This module is compiled into php.

Then we can check whether there is really this extension through the command php -m. As you can see from the picture below, there is indeed an extension of swoole

Test the Swoole environment

  • Select and enter the test directory

In the "Swoole" source code we downloaded, there are many examples, we can run directly to test, enter the examples directory, all of which are sample code, we choose http/server.php to test, then cd http/into the http directory

  • Execute php program

The above has entered the http directory, and found that there is a server.php file in the current directory, we can use the command php server.php to execute

  • Browser running test

We open the server.php file and there is a line of code$http = new swoole_http_server("0.0.0.0", 9501); Enter127.0.0.1:9501 or localhost:9501in the field and visit it. IfHello Swoole. is displayed, then the installation of Swoole` is successful!

to sum up

As long as you install it step by step according to the article, you should be able to install it at once, because I stepped on it one step at a time, and I have filled the holes. Do n t praise me, I will be proud. During the installation process, if you have any questions, you can leave a message directly to me. I will reply in time and help solve it. If you have other better ideas, you will also analyze the environment and communicate with you. Thank you!