安装mochat
环境:qcloud ubuntu20
- PHP >= 7.2 (推荐7.4版本) sudo apt-get install php7.4
- MYSQL >= 5.7 sudo apt-get install mysql-server-8.0
- Swoole PHP 扩展 >= 4.5,并关闭了
Short Name
- OpenSSL PHP 扩展
- JSON PHP 扩展
- PDO PHP 扩展
- Redis PHP 扩展
- Composer
- FFMpeg(会话存档功能需要)
- wxwork_finance_sdk PHP 扩展 (会话存档功能需要)
- Node.js >= 10
安装php和mysql:
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
sudo apt-get install php-7.4 && sudo apt-get install mysql-server && php -v
安装php-7.4时,会将php的apache2模块libapache2-mod-php一起安装上来,看这里。
如何重启apache?
sudo systemctl restart apache2.service
如何查看php的配置信息?
在/var/www/下创建一个phpinfo.php文件,内容为<?php phpinfo(); ?>,然后在主机内访问:http://vagrant_ip/phpinfo.php,即可看到php使用的配置文件以及php的扩展安装信息.
sudo apt-get install php-dev && sudo pecl install swoole-4.5.5
因qcloud未安装gcc,所以先将gcc和g++安装好: sudo apt-get install gcc g++
在php.ini中增加swoole.so:
Build process completed successfully
Installing '/usr/include/php/20190902/ext/swoole/config.h'
Installing '/usr/lib/php/20190902/swoole.so'
install ok: channel://pecl.php.net/swoole-4.5.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=swoole.so" to php.ini
如何关闭short name?
如果需要swoole关闭shortname,在apache2/php.ini中添加swoole.use_shortname = off
然后执行sudo systemctl restart apache2重启apache,访问phpinfo.php,即可看到swoole.use_shortname的local_value和master_value为off。
观察发现安装php7.4时,有5个模式:分别为apache2、cgi、cli、fpm和phpdbg
/etc/php/7.4/
apache2/ cgi/ cli/ fpm/ mods-available/ phpdbg/
每个文件夹下都有一个conf.d文件夹,里面的ini配置文件都是从mods-available内软链接过去的,所以后续如果安装了一个新的extension之后,都需要在mods-available内创建一个ini文件,比如安装了swoole之后,就需要在mods-available内创建一个swoole.ini文件,
sudo vim /etc/php/7.4/mods-available/swoole.ini
文件内容为:
extension=swoole.so
swoole.use_shortname = off
然后创建5个软连接到以上5个文件夹内,即:
sudo ln -s /etc/php/7.4/mods-available/swoole.ini /etc/php/7.4/apache2/conf.d/swoole.ini
sudo ln -s /etc/php/7.4/mods-available/swoole.ini /etc/php/7.4/cgi/conf.d/swoole.ini
如何安装php扩展,看这里
根据php7.4 -m | grep openssl之后,发现执行结果为openssl,说明已经安装了openssl,跳过,
同样也安装了json和pdo,跳过
最后发现没有安装redis,开始安装php-redis
sudo apt-get insitall php-mysql php-common
sudo apt-get install php-redis
如何安装composer:
看这里
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
如何安装FFMpeg:
看这里
sudo apt-get install ffmpeg
如何安装wxwork_finance_sdk PHP 扩展:
看这里
cd wxwork_finance_sdk && phize
./configure --with-php-config=$INSTALL_PHP_PATH/php-config --with-wxwork-finance-sdk=$WXWORK_FINANCE_C_SDK_PATH
INSTALL_PHP_PATH=/usr/bin/php-config
$WXWORK_FINANCE_C_SDK_PATH会报错:
checking .... configure: error: cannot find WeWorkFinanceSdk_C.h in path,解决方法在这里和这里
WeWorkFinanceSdk_C.h在这里下载
./configure --with-php-config=/usr/bin/php-config --with-wxwork-finance-sdk=../sdk_20201116/C_sdk/
make && sudo make install
最终运行结果如下:
Libraries have been installed in:
/home/ubuntu/data/prj/php7-wxwork-finance-sdk-master/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/lib/php/20190902/
定位intl扩展的冲突问题. php -m |grep intl 建议重新编译php 取消intl扩展
php -m
或phpinfo()
来查看是否成功加载了swoole.so
,如果没有可能是php.ini
的路径不对,可以使用php --ini
来定位到php.ini
的绝对路径。如何安装nodejs:
sudo apt-get install nodejs
开始安装mochat:
设置composer:
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer