Compile, install and run PHP 7.0.23, Swoole 1.9.19 in Windwos 10 64, VirtualBox, CentOS 7 64 GNOME

在一个 Xshell 终端中运行客户端
1. Open the URL: https://wiki.swoole.com/wiki/page/7.html , check the environment dependencies, as shown in Figure 1 environment dependence Only supports Linux, FreeBSD, macOS, 3 types of operating systems Linux kernel version 2.3.32 or above php-5.3.10 and above, including php7 GCC4.4 or above or clang CMake2.4+, you need to use CMake when compiling to libswoole.so as a C/C++ library It is recommended to use Ubuntu14, CentOS7 or later operating systems
打开网址:https://wiki.swoole.com/wiki/page/7.html ,查看环境依赖
Figure 1
2. Set the port forwarding rules in VirtualBox to facilitate remote connection of CentOS 7 64, as shown in Figure 2
在 VirtualBox 设置端口转发规则,以便于远程连接 CentOS 7 64
Figure 2
3. Check the IP address of VirtualBox, as shown in Figure 3
查看 VirtualBox 的IP地址
Figure 3
4. Connect CentOS 7 64 through Xshell 5, as shown in Figure 4
通过 Xshell 5 连接 CentOS 7 64
Figure 4
5. The SSH connection is successful, as shown in Figure 5
ssh 连接成功
Figure 5
6. Environmental dependency check, check the installation of gcc, gcc-c++, make, autoconf, and pcre respectively. If it is not installed, it needs to be installed. rpm -qa gcc rpm -qa gcc-c++ rpm -qa make rpm -qa autoconf rpm -qa pcre
环境依赖检查,分别查看gcc、gcc-c++、make、autoconf、pcre的安装情况,未安装的,需要安装,gcc、gcc-c++、autoconf未安装
Figure 6
7. Install gcc, gcc-c++, autoconf, as shown in Figure 7 yum install gcc gcc-c++ autoconf
安装 gcc、gcc-c++、autoconf
Figure 7
8. Check the installation of GCC, GCC-C++, and AutoConf again, all of which have been installed successfully, as shown in Figure 8 rpm -qa gcc rpm -qa gcc-c++ rpm -qa autoconf
再次查看gcc、gcc-c++、autoconf的安装情况,皆已安装成功
8
9. Before compiling and installing php7, you need to install the corresponding compilation tools and dependencies, run the following commands, as shown in Figure 9 rpm -qa libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
编译安装 php7 之前需要安装对应的编译工具和依赖包,运行如下命令
Figure 9
10. Check the installation situation, libmcrypt-devel is not installed, as shown in Figure 10 rpm -qa libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel rpm -qa libcurl-devel rpm -qa libjpeg-turbo-devel
查看安装情况,libmcrypt-devel未安装
Figure 10
11. libmcrypt-devel is not installed because: there is no available package libmcrypt-devel, as shown in Figure 11
libmcrypt-devel未安装,原因在于:没有可用软件包 libmcrypt-devel
Figure 11
12. Search EPEL related software packages, as shown in Figure 12 yum search EPEL
搜索 EPEL 相关的软件包
Figure 12
13. Install the EPEL package, as shown in Figure 13 yum install epel-release
安装 EPEL 软件包
Figure 13
14. Install libmcrypt-devel again, as shown in Figure 14 yum -y install libmcrypt-devel
再次安装 libmcrypt-devel
Figure 14
15. Check the installation situation, libmcrypt-devel has been installed, as shown in Figure 15 rpm -qa libmcrypt-devel
查看安装情况,libmcrypt-devel已安装
Figure 15
16. Reference URL: http://www.shaunfreeman.name/compiling-php-7-on-centos/, create a new directory: /usr/local/php7, as shown in Figure 16 mkdir /usr/local/php7
参考网址:http://www.shaunfreeman.name/compiling-php-7-on-centos/ ,新建目录:/usr/local/php7
Figure 16
17. Install git, as shown in Figure 17 yum install git-core
安装 Git
Figure 17
18. Enter the user home directory, as shown in Figure 18 cd ~
进入用户主目录
18
19. Get the source code from the php github repository, as shown in Figure 19 git clone https://github.com/php/php-src.git
从 PHP Github 仓库中获取源代码
Figure 19
20. Enter the directory: php-src, as shown in Figure 20 cd php-src/
进入目录:php-src
Figure 20
21. Open the URL: https://github.com/php/php-src , the latest branch of the current 7.0.* is 7.0.23, as shown in Figure 21
打开网址:https://github.com/php/php-src ,当前 7.0.* 的最新分支为 7.0.23
Figure 21
22. Switch to 7.0.23, as shown in Figure 22 Git Checkout PHP-7.0.23
切换至 7.0.23
Figure 22
23. Generate a configuration script, as shown in Figure 23 ./buildconf –force
生成配置脚本
Figure 23
24. Use the following command to compile the configuration, as shown in Figure 24 ./configure –prefix=/usr/local/php7 \ –with-config-file-path=/usr/local/php7/etc \ –with-config-file-scan-dir=/usr/local/php7/etc/conf.d \ –enable-bcmath \ –with-bz2 \ –with-curl \ –enable-filter \ –enable-fpm \ –with-gd \ –enable-gd-native-ttf \ –with-freetype-dir \ –with-jpeg-dir \ –with-png-dir \ –enable-intl \ –enable-mbstring \ –with-mcrypt \ –enable-mysqlnd \ –with-mysql-sock=/var/lib/mysql/mysql.sock \ –with-mysqli=mysqlnd \ –with-pdo-mysql=mysqlnd \ –with-pdo-sqlite \ –disable-phpdbg \ –disable-phpdbg-webhelper \ –enable-opcache \ –with-openssl \ –enable-simplXml \ –with-sqlite3 \ –enable-xmlreader \ –enable-xmlwriter \ –enable-zip \ –with-zlib
使用如下命令编译配置
Figure 24
25. Report an error, as shown in Figure 25 Configure: this Bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: ). Checking for re2c… no configure: warning: you will need re2c 0.13.4 or later if you want to regenerate php parsers. configure: error: bison is required to build php/zend when building a git checkout!
报错
Figure 25
26. Install bison, as shown in Figure 26 yum install bison
安装 bison
Figure 26
27. Compile and configure again, report an error, as shown in Figure 27 Checking for bzip2 support… yes Checking for bzip2 in default path… not found configure: error: please reinstall the bzip2 distribution
再次编译配置,报错
Figure 27
28. Install bzip2-devel, as shown in Figure 28 yum install bzip2-devel
安装 bzip2-devel
Figure 28
29. Compile and configure again, report an error, as shown in Figure 29 Checking build system type… config.sub: missing argument try `config.sub –helpfor more information. configure: error: /bin/sh ./config.sub failed
再次编译配置,报错
Figure 29
30. After checking, it is found that there is an extra space after –enable-zip \, as shown in Figure 30
检查之后,发现 --enable-zip \ 后面多了一个空格
Figure 30
31. Remove the space after –enable-zip\, compile and install php again, and report an error, as shown in Figure 31 Checking for ICU-config… No Checking for location of ICU headers and libraries… not found Configure: Unable to Detect ICU prefix or no failed. Please verify ICU install prefix and make sure ICU-config works.
去掉 --enable-zip \ 后面的空格,再次编译安装PHP,报错
Figure 31
32. Install libicu-devel, as shown in Figure 32 yum install libicu-devel
安装 libicu-devel
Figure 32
33. Compile and configure again, normal, as shown in Figure 33
再次编译配置,正常
Figure 33
34. Formal installation and execution in sequence, as shown in Figure 34 make make test make install
正式安装,依次执行
Figure 34
35. Add the ini option, as shown in Figure 35 mkdir /usr/local/php7/etc/conf.d cp ./php.ini-development /usr/local/php7/lib/php.ini
添加ini选项
Figure 35
36. Add the executable directory of php to the environment variable, use vim to open ~/.bashrc, add the following content at the end: as shown in Figure 36 vim ~/.bashrc export path=/usr/local/php7/bin:$PATH export path=/usr/local/php7/sbin:$path
将PHP的可执行目录添加到环境变量中,使用 Vim 打开 ~/.bashrc,在末尾添加如下内容
Figure 36
37. After saving, run the following command in the terminal: as shown in Figure 37 source ~/.bashrc
保存完毕后,在终端中运行以下命令:
Figure 37
38. Check the PHP version, as shown in Figure 38 php –version PHP 7.0.23 (CLI) (Built: Sep 4 2017 17:12:44) (NTS) Copyright (C) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (C) 1998-2017 Zend Technologies
查看 PHP 版本
Figure 38
39. Enter the user home directory, as shown in Figure 39 cd ~
进入用户主目录
Figure 39
40. Get the source code from the Swoole GitHub repository, as shown in Figure 40 Git clone https://github.com/swoole/swoole-src.git
从 Swoole Github 仓库中获取源代码
Figure 40
41. Enter the directory: swoole-src, as shown in Figure 41 cd swoole-src/
进入目录:swoole-src
Figure 41
42. Open the URL: https://github.com/swoole/swoole-src/releases, the latest stable version is v1.9.19, as shown in Figure 42
打开网址:https://github.com/swoole/swoole-src/releases ,当前最新稳定版为 v1.9.19
Figure 42
43. Switch to V1.9.19, as shown in Figure 43 Git Checkout v1.9.19 Error: note: checking outv1.9.19. You are indetached headState. You can look around, make experimental Changes and commit them, and you can discard any commits you make in this State without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may Do so (now or later) by using -b with the checkout command again. Example: git checkout -b new_branch_name HEAD is currently at 124C4F5… FIX #1337
切换至 v1.9.19
Figure 43
44. Switch to V1.9.19, as shown in Figure 44 git checkout -b v1.9.19
切换至 v1.9.19
Figure 44
45. Use phpize to generate php compilation configuration, execute the command: as shown in Figure 45 phpize
使用 phpize 来生成php编译配置,执行命令
Figure 45
46. Use ./configure for compilation configuration detection. Swoole’s ./configure has many additional parameters, which can be viewed through the ./configure –help command. The default items are selected here, as shown in Figure 46 ./configure
使用 ./configure 来做编译配置检测,swoole的./configure有很多额外参数,可以通过 ./configure --help 命令查看,这里均选择默认项
Figure 46
47. Compile and install, execute in sequence, as shown in Figure 47 make make test make install
编译安装,依次执行
Figure 47
48. After the installation is complete, edit the /usr/local/php7/etc/conf.d/modules.ini file, as shown in Figure 48 vim /usr/local/php7/etc/conf.d/modules.ini
安装完成后,编辑 /usr/local/php7/etc/conf.d/modules.ini 文件
Figure 48
49. Add the following sentence, as shown in Figure 49 extension=swoole.so
在其中加上如下一句
Figure 49
50. Enter the command php -m to view the extension installation, and see swoole in the listed extensions, indicating that the installation is successful, as shown in Figure 50 php-m
输入命令 php -m 查看扩展安装情况,在列出的扩展中看到了 swoole,说明安装成功
Figure 50
51. Install the enhancement function, as shown in Figure 51
安装增强功能
Figure 51
52. Report an error, as shown in Figure 52 Failed to set up service vBoxAdd, please check the log file /var/log/vBoxGuestAdditions.log for details. Press return to close this window…
报错
Figure 52
53. Check the /var/log/vboxguestadditions.log file, as shown in Figure 53 cat /var/log/vboxguestadditions.log log: vboxadd.sh: failed: look at /var/log/vboxadd-install.log to find out what went wrong. vboxadd.sh: failed: look at /var/log/vboxadd-install.log to find out what went wrong. vboxadd.sh: failed: modprobe vboxguest failed.
查看 /var/log/VBoxGuestAdditions.log 文件
Figure 53
54. View the /var/log/vboxadd-install.log file, as shown in Figure 54 cat /var/log/vboxadd-install.log log: /tmp/vbox.0/makefile.include.header:112: *** Error: Unable to find the sources of your current Linux kernel. specify kern_dir=<directory> and run make again. stop. Creating user for the guest additions. Creating udev rule for the guest additions kernel module.
查看 /var/log/vboxadd-install.log 文件
Figure 54
55. Check the installation of kernel-headers and kernel-devel, kernel-devel is not installed, as shown in Figure 55 rpm -qa kernel-headers rpm -qa kernel-devel
查看kernel-headers、kernel-devel的安装情况,kernel-devel 未安装
Figure 55
56. Install Kernel-Devel, as shown in Figure 56 yum install kernel-devel
安装 kernel-devel
Figure 56
57. Restart the virtual computer based on VirtualBox, and install the enhancement function again, as shown in Figure 57 Error: Failed to load virtual disc vboxsguestadditions.iso to virtual computer
基于 VirtualBox 重启虚拟电脑,再次安装增强功能
Figure 57
58. Pop the optical drive in the virtual computer, as shown in Figure 58
将虚拟电脑中的光驱弹出
Figure 58
59. Install the enhancement function again, and still report an error, as shown in Figure 59
再次安装增强功能,仍然报错
Figure 59
60. Upgrade all packages and also upgrade the software and system kernel, as shown in Figure 60 yum update
升级所有包同时也升级软件和系统内核
Figure 60
61. Restart the virtual computer based on CentOS, install the enhancement function again, and the installation is successful, as shown in Figure 61
基于 CentOS 重启虚拟电脑,再次安装增强功能,安装成功
Figure 61
62. According to the installation prompt, restart the Windows system. In View – Virtual Display, if the resolution is optional, the enhancement function is successfully installed, as shown in Figure 62
根据安装提示,重启 Windows 系统,在 视图 - 虚拟显示屏 中,如果分辩率可选,表示增强功能成功安装
Figure 62
63. Create a new shared folder, e:\wwwroot\centos-7-x86_64-dvd_share, as shown in Figure 63
新建共享文件夹,E:\wwwroot\CentOS-7-x86_64-DVD_share
Figure 63
64. Create a mount folder in CentOS, as shown in Figure 64 mount -t vboxsf centos-7-x86_64-dvd_share /mnt/share Error: /sbin/mount.vboxsf: Mounting failed with the error: no such file or directory
在 CentOS 中创建挂载文件夹
Figure 64
65. Create a new directory /mnt/share, as shown in Figure 65 mkdir /mnt/share
新建目录 /mnt/share
Figure 65
66. Mount the folder again in CentOS, normal, as shown in Figure 66 mount -t vboxsf centos-7-x86_64-dvd_share /mnt/share
在 CentOS 中再次挂载文件夹,正常
Figure 66
67. In the directory e:\wwwroot\centos-7-x86_64-dvd_share, create a new phpinfo.php file, as shown in Figure 67
在目录 E:\wwwroot\CentOS-7-x86_64-DVD_share 中,新建 phpinfo.php 文件
Figure 67
68. Check /mnt/share , the phpinfo.php file already exists, the sharing is successful, as shown in Figure 68
查看 /mnt/share ,已经存在 phpinfo.php 文件,共享成功
Figure 68
69. Run php phpinfo.php, normal, as shown in Figure 69
运行 php phpinfo.php,正常
Figure 69
70. Create an echo server, create a server.php file and enter the following content: as shown in Figure 70


<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/5
 * Time: 15:33
 */

// Server
class Server
{
    private $serv;

    public function __construct() {
        $this->serv = new swoole_server("0.0.0.0", 9501);
        $this->serv->set(array(
            'worker_num' => 8,
            'daemonize' => false,
        ));

        $this->serv->on('Start', array($this, 'onStart'));
        $this->serv->on('Connect', array($this, 'onConnect'));
        $this->serv->on('Receive', array($this, 'onReceive'));
        $this->serv->on('Close', array($this, 'onClose'));

        $this->serv->start();
    }

    public function onStart( $serv ) {
        echo "Start\n";
    }

    public function onConnect( $serv, $fd, $from_id ) {
        $serv->send( $fd, "Hello {$fd}!" );
    }

    public function onReceive( swoole_server $serv, $fd, $from_id, $data ) {
        echo "Get Message From Client {$fd}:{$data}\n";
        $serv->send($fd, $data);
    }

    public function onClose( $serv, $fd, $from_id ) {
        echo "Client {$fd} close connection\n";
    }
}
// 启动服务器 Start the server
$server = new Server();


搭建Echo服务器,创建一个Server.php文件并输入如下内容:
Figure 70
71. Create a client.php file and enter the following content: as shown in Figure 71


<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/5
 * Time: 15:35
 */

class Client
{
    private $client;

    public function __construct() {
        $this->client = new swoole_client(SWOOLE_SOCK_TCP);
    }

    public function connect() {
        if( !$this->client->connect("127.0.0.1", 9501 , 1) ) {
            echo "Error: {$this->client->errMsg}[{$this->client->errCode}]\n";
        }

        fwrite(STDOUT, "请输入消息 Please input msg:");
        $msg = trim(fgets(STDIN));
        $this->client->send( $msg );

        $message = $this->client->recv();
        echo "Get Message From Server:{$message}\n";
    }
}

$client = new Client();
$client->connect();


创建一个Client.php文件并输入如下内容:
Figure 71
72. Run the server in an Xshell terminal, as shown in Figure 72 php server.php
在一个 Xshell 终端中运行服务端
Figure 72
73. Run the client in an Xshell terminal, as shown in Figure 73 php client.php
在一个 Xshell 终端中运行客户端
Figure 73
     

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.