PHP7 安裝 Swoole 教學

2020-07-16 10:06:15
PHP7 原始碼安裝

步驟

1、解壓 tar -xjvf

2、configure

3、make

4、make install

安裝上傳下載命令

yum install -y lrzsz

linux 操作

[[email protected]_0_5_centos ~]# cd /home/
[[email protected]_0_5_centos home]# mkdir -p work/study/softpackage
[[email protected]_0_5_centos softpackage]# pwd
/home/work/study/softpackage
[[email protected]_0_5_centos softpackage]# ll
total 14900
-rw-r--r-- 1 root root 15235268 Apr  2 21:19 php-7.2.29.tar.bz2
[[email protected]_0_5_centos softpackage]# tar -xjvf php-7.2.29.tar.bz2
drwxrwxr-x 14 root root     4096 Mar 17 18:16 php-7.2.29
-rw-r--r--  1 root root 15235268 Apr  2 21:19 php-7.2.29.tar.bz2
[[email protected]_0_5_centos softpackage]# cd php-7.2.29/
[[email protected]_0_5_centos php-7.2.29]# yum install gcc
----
configure: error: libxml2 not found. Please check your libxml2 installation.
----
//start安裝豪華套餐
yum -y install gcc libxml2 yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel
//end
[[email protected]_0_5_centos php-7.2.29]# ./configure --prefix=/home/work/study/soft/php
[[email protected]_0_5_centos php-7.2.29]# make
[[email protected]_0_5_centos php-7.2.29]# make install
[[email protected]_0_5_centos php-7.2.29]# cd /home/work/study/
[[email protected]_0_5_centos study]# ll
total 8
drwxr-xr-x 3 root root 4096 Apr  2 22:04 soft
drwxr-xr-x 3 root root 4096 Apr  2 21:44 softpackage
[[email protected]_0_5_centos study]# cd soft/php/
[[email protected]_0_5_centos php]# 
[[email protected]_0_5_centos php]# ./bin/php -m
//測試
[[email protected]_0_5_centos php]# vim test.php
[[email protected]_0_5_centos php]# ./bin/php test.php 
1585836467[[email protected]_0_5_centos php]# 
//編輯
[[email protected]_0_5_centos php]# vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
 . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
alias php=/home/work/study/soft/php/bin/php
//讓設定生效
[[email protected]_0_5_centos php]#  source ~/.bash_profile 
[[email protected]_0_5_centos php]# php -v
PHP 7.2.29 (cli) (built: Apr  2 2020 22:03:18) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
//測試
[[email protected]_0_5_centos study]# mkdir demo
[[email protected]_0_5_centos study]# cd demo/
[[email protected]_0_5_centos demo]# vim t.php
[[email protected]_0_5_centos demo]# php t.php
1585836787[[email protected]_0_5_centos demo]# pwd
/home/work/study/demo

轉移 php.ini

[[email protected]_0_5_centos study]# cd softpackage/php-7.2.29/
[[email protected]_0_5_centos php-7.2.29]# pwd
/home/work/study/softpackage/php-7.2.29
[[email protected]_0_5_centos php-7.2.29]# cp php.ini-development /home/work/study/soft/php/etc/
[[email protected]_0_5_centos ~]# cd /home/work/study/soft/php/etc/
[[email protected]_0_5_centos etc]# ll
total 80
-rw-r--r-- 1 root root  1354 Apr  2 22:05 pear.conf
-rw-r--r-- 1 root root 71232 Apr  2 22:17 php.ini-development
[[email protected]_0_5_centos etc]# mv php.ini-development php.ini
[[email protected]_0_5_centos php-7.2.29]# php -i | grep php.ini
Configuration File (php.ini) Path => /home/work/study/soft/php/lib
[[email protected]_0_5_centos php-7.2.29]# cd /home/work/study/soft/php/
[[email protected]_0_5_centos php]#  mv ./etc/php.ini ./lib/

上傳 swoole 檔案包

[[email protected]_0_5_centos softpackage]# rz
[[email protected]_0_5_centos softpackage]# ll
total 17076
drwxrwxr-x 17 root root     4096 Apr  2 21:55 php-7.2.29
-rw-r--r--  1 root root 15235268 Apr  2 21:19 php-7.2.29.tar.bz2
-rw-r--r--  1 root root  2217161 Apr  2 22:27 swoole-swoole-master.zip
[[email protected]_0_5_centos softpackage]# unzip swoole-swoole-master.zip 
[[email protected]_0_5_centos softpackage]# ll
total 17080
drwxrwxr-x 17 root root     4096 Apr  2 21:55 php-7.2.29
-rw-r--r--  1 root root 15235268 Apr  2 21:19 php-7.2.29.tar.bz2
drwxr-xr-x  9 root root     4096 Jan  9 20:06 swoole
-rw-r--r--  1 root root  2217161 Apr  2 22:27 swoole-swoole-master.zip
//生成configure檔案
[[email protected]_0_5_centos swoole]# /home/work/study/soft/php/bin/phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
[[email protected]_0_5_centos swoole]# ./configure --with-php-config=/home/work/study/soft/php/bin/php-config
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/home/work/study/softpackage/swoole':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
//說明
error: C++ preprocessor "/lib/cpp" fails sanity check 問題的解決
 問題的根源是缺少必要的C++庫。如果是CentOS系統,執行,如下命令解決:
 yum install glibc-headers
 yum install gcc-c++

再執行

[[email protected]_0_5_centos swoole]# ./configure --with-php-config=/home/work/study/soft/php/bin/php-config
[[email protected]_0_5_centos swoole]# make
[[email protected]_0_5_centos swoole]# make install
[[email protected]_0_5_centos swoole]# cd /home/work/study/soft/php/lib/php/extensions/no-debug-non-zts-20170718/
[[email protected]_0_5_centos no-debug-non-zts-20170718]# ll
total 17664
-rwxr-xr-x 1 root root  3589814 Apr  2 22:04 opcache.a
-rwxr-xr-x 1 root root  1979620 Apr  2 22:04 opcache.so
-rwxr-xr-x 1 root root 12488337 Apr  2 22:41 swoole.so
[[email protected]_0_5_centos lib]# ll
total 80
drwxr-xr-x 15 root root  4096 Apr  2 22:05 php
-rw-r--r--  1 root root 71232 Apr  2 22:17 php.ini
[[email protected]_0_5_centos lib]# vi php.ini 
[[email protected]_0_5_centos lib]# pwd
/home/work/study/soft/php/lib

在php.ini檔案中新增:extension=swoole.so

檢視是否新增成功:php -m

[[email protected]_0_5_centos server]# php echo.php 
^C
[[email protected]_0_5_centos server]# pwd
/home/work/study/softpackage/swoole/examples/server
//新開視窗
[[email protected]_0_5_centos server]# netstat -anp|grep 9501
tcp        0      0 0.0.0.0:9501            0.0.0.0:*               LISTEN      23406/php 
[[email protected]_0_5_centos server]# netstat -anp|grep 9501
[[email protected]_0_5_centos server]# pwd
/home/work/study/softpackage/swoole/examples/server
以上就是PHP7 安裝 Swoole 教學的詳細內容,更多請關注TW511.COM其它相關文章!