修改完后更新源
apt-get update
安装必要工具 net-tools 包含netstat iputils-ping 包含ping
apt-get -y vim install net-tools wget curl iputils-ping
添加php源
apt-get -y install software-properties-common && add-apt-repository ppa:ondrej/php && apt-get update
安装过程中会选择地区,城市
6 Asia 70 Shanghai
安装php以及一些常用扩展
apt-get -y install php7.2-dev php7.2-cli php7.2-xml php7.2-mysql php7.2-mbstring php7.2-curl php7.2-bcmath php7.2-zip
4 swoole扩展简单安装
mkdir -p /tmp/php-extension &&
cd /tmp/php-extension &&
wget https://pecl.php.net/get/swoole-4.5.1.tgz &&
tar zxvf swoole-4.5.1.tgz &&
cd swoole-4.5.1 &&
phpize &&
./configure &&
make && make install
扩展写入php.ini
sed -i "924 i extension=swoole.so" /etc/php/7.2/cli/php.ini
查看php扩展
php -m|grep swoole
5 laravel项目启动laravel-swoole
假如本地有laravel项目,可以把本地目录挂载到docker容器下,代码可以git仓库拉推都不影响
ps:假如原来项目中访问的mysql,redis等在本地话,那么挂载后需要把对应的ip,localhost|127.0.0.1 替换成 容器内部访问宿主机的ip
容器中连接宿主机(本地),下面是两种查看宿主ip 的方法
ping host.docker.internal 查看对应ip,C类内网地址
本地windows安装目录查看,比如 C:\ProgramData\DockerDesktop\tmp-d4w\host.docker.internal B类内网地址
退出当前容器
shell命令中 exit
把当前安装了php-swoole扩展的容器提交一个镜像
docker commit ls-demo swoole-php-ubuntu
启动刚生成的带有自己安装php-swoole环境的镜像,挂载本地的laravel项目
docker run -it -d -p 本机端口:容器端口 -v "本机路径":容器路径 swoole-php-ubuntu
下面介绍容器中安装laravel并运行laravel-swoole
下载安装composer并且更换阿里镜像
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" &&
php composer-setup.php &&
php -r "unlink('composer-setup.php');" && mv composer.phar /usr/local/bin/composer &&
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
composer下载laravel5.8
mkdir -p /data/www && cd /data/www &&
composer create-project --prefer-dist laravel/laravel ls-demo 5.8.*
安装laravel-swoole v2.6.67
cd ls-demo && composer require swooletw/laravel-swoole v2.6.67
添加配置文件config目录下生成3个,swoole开头的,这里只用到了swoole_http.php
php artisan vendor:publish --tag=laravel-swoole
修改对应配置
sed -i "177 i SwooleTW\\\\Http\\\LaravelServiceProvider::class," config/app.php &&
sed -i "44 a SWOOLE_HTTP_DAEMONIZE=true" .env
启动查看端口
php artisan swoole:http start && curl 127.0.0.1:1215
laravel-swoole wiki 地址[关于配置启动可以查看]
https://github.com/swooletw/laravel-swoole/wiki
总结:
上面命令批量汇总
1 下载ubuntu镜像并启动
docker pull ubuntu
docker run -it --name=ls-demo ubuntu /bin/bash
2 批量执行
cp /etc/apt/sources.list /etc/apt/sources.list.bak &&
echo '' > /etc/apt/sources.list &&
echo '
deb focal main restricted universe multiverse
deb-src focal main restricted universe multiverse
deb focal-security main restricted universe multiverse
deb-src focal-security main restricted universe multiverse
deb focal-updates main restricted universe multiverse
deb-src focal-updates main restricted universe multiverse
deb focal-proposed main restricted universe multiverse
deb-src focal-proposed main restricted universe multiverse