PHP - Docker开发库社区Linux下优雅的部署PHP环境

PHP生产环境 02 - 使用webhooks自动部署服务器代码

2018-08-06  本文已影响0人  7c03aed0f01f

配置PHP项目(以KFKCms为例)

配置vhost
cd ~/kfkdock/vhost
cp laravel.cc.conf kfkcms.com.conf

# 更改对应的内容
vi kfkcms.com.conf

# 修改内容
server {
    listen       80;
    server_name  kfkcms.com;

    root   /var/www/kfkcms/public;
    index  index.php index.html index.htm;

    location / {
    try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass   php71:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

sudo docker-compose stop
sudo docker-compose up -d
进入容器
cd ~/kfkdock
sudo docker-compose exec php71 bash
将容器的用户公钥,配置到Git服务器
//生成用户公钥,一直回车
sudo ssh-keygen -t rsa -C "kfkdock" -f ~/.ssh/id_rsa

//生成部署公钥,一直回车
mkdir /var/www/.ssh
chown -R www-data:www-data /var/www/.ssh
sudo -Hu www-data ssh-keygen -t rsa  -f /var/www/.ssh/id_rsa
查看公钥
//查看用户公钥
cat ~/.ssh/id_rsa.pub

//查看部署公钥
cat /var/www/.ssh/id_rsa.pub
配置用户公钥
image
配置部署公钥
image
初始化项目
//授权
chown -R www-data:www-data /var/www/
cd /var/www

//注意:
//      必须使用的是SSH Git地址,而非HTTPS
//      必须使用www-data权限clone代码
sudo -Hu www-data git clone git@github.com:kfkme/kfkcms.git --depth=1

root@a3e52b3694bd:/var/www# cd kfkcms
root@a3e52b3694bd:/var/www/kfkcms# composer install
root@a3e52b3694bd:/var/www/kfkcms# cp .env.example .env
root@a3e52b3694bd:/var/www/kfkcms# php artisan key:generate
修改Git配置
root@a3e52b3694bd:/var/www/kfkcms# git config --global user.name "kafu"
root@a3e52b3694bd:/var/www/kfkcms# git config --global user.email "admin@kfk.me" # 邮箱请与conding上一致
配置Git服务器的WebHook
image
上一篇下一篇

猜你喜欢

热点阅读