Compile, install and run PHP 7.0.23, Swoole 1.9.19 in Windwos 10 64, VirtualBox, CentOS 7 64 GNOME
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
2. Set the port forwarding rules in VirtualBox to facilitate remote connection of CentOS 7 64, as shown in Figure 2
3. Check the IP address of VirtualBox, as shown in Figure 3
4. Connect CentOS 7 64 through Xshell 5, as shown in Figure 4
5. The SSH connection is successful, as shown in 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
7. Install gcc, gcc-c++, autoconf, as shown in Figure 7
yum install gcc gcc-c++ autoconf
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
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
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
11. libmcrypt-devel is not installed because: there is no available package libmcrypt-devel, as shown in Figure 11
12. Search EPEL related software packages, as shown in Figure 12
yum search EPEL
13. Install the EPEL package, as shown in Figure 13
yum install epel-release
14. Install libmcrypt-devel again, as shown in Figure 14
yum -y install libmcrypt-devel
15. Check the installation situation, libmcrypt-devel has been installed, as shown in Figure 15
rpm -qa libmcrypt-devel
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
17. Install git, as shown in Figure 17
yum install git-core
18. Enter the user home directory, as shown in Figure 18
cd ~
19. Get the source code from the php github repository, as shown in Figure 19
git clone https://github.com/php/php-src.git
20. Enter the directory: php-src, as shown in Figure 20
cd php-src/
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
22. Switch to 7.0.23, as shown in Figure 22
Git Checkout PHP-7.0.23
23. Generate a configuration script, as shown in Figure 23
./buildconf –force
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
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!
26. Install bison, as shown in Figure 26
yum install bison
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
28. Install bzip2-devel, as shown in Figure 28
yum install bzip2-devel
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
30. After checking, it is found that there is an extra space after –enable-zip \, as shown in 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.
32. Install libicu-devel, as shown in Figure 32
yum install libicu-devel
33. Compile and configure again, normal, as shown in Figure 33
34. Formal installation and execution in sequence, as shown in Figure 34
make
make test
make install
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
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
37. After saving, run the following command in the terminal: as shown in Figure 37
source ~/.bashrc
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
39. Enter the user home directory, as shown in Figure 39
cd ~
40. Get the source code from the Swoole GitHub repository, as shown in Figure 40
Git clone https://github.com/swoole/swoole-src.git
41. Enter the directory: swoole-src, as shown in Figure 41
cd swoole-src/
42. Open the URL: https://github.com/swoole/swoole-src/releases, the latest stable version is v1.9.19, as shown in 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
44. Switch to V1.9.19, as shown in Figure 44
git checkout -b v1.9.19
45. Use phpize to generate php compilation configuration, execute the command: as shown in Figure 45
phpize
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
47. Compile and install, execute in sequence, as shown in Figure 47
make
make test
make install
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
49. Add the following sentence, as shown in Figure 49
extension=swoole.so
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
51. Install the enhancement function, as shown in 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…
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.
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.
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
56. Install Kernel-Devel, as shown in Figure 56
yum install kernel-devel
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
58. Pop the optical drive in the virtual computer, as shown in Figure 58
59. Install the enhancement function again, and still report an error, as shown in Figure 59
60. Upgrade all packages and also upgrade the software and system kernel, as shown in Figure 60
yum update
61. Restart the virtual computer based on CentOS, install the enhancement function again, and the installation is successful, as shown in 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
63. Create a new shared folder, e:\wwwroot\centos-7-x86_64-dvd_share, as shown in 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
65. Create a new directory /mnt/share, as shown in Figure 65
mkdir /mnt/share
66. Mount the folder again in CentOS, normal, as shown in Figure 66
mount -t vboxsf centos-7-x86_64-dvd_share /mnt/share
67. In the directory e:\wwwroot\centos-7-x86_64-dvd_share, create a new phpinfo.php file, as shown in Figure 67
68. Check /mnt/share , the phpinfo.php file already exists, the sharing is successful, as shown in Figure 68
69. Run php phpinfo.php, normal, as shown in 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 start the server
$server = new server();
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 enter the message 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();
72. Run the server in an Xshell terminal, as shown in Figure 72
php server.php
73. Run the client in an Xshell terminal, as shown in Figure 73
php client.php








































































