• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

markomarkovic/simple-php-git-deploy: Automatically deploy the code using PHP and ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

markomarkovic/simple-php-git-deploy

开源软件地址:

https://github.com/markomarkovic/simple-php-git-deploy

开源编程语言:

PHP 100.0%

开源软件介绍:

Simple PHP Git deploy script

Automatically deploy the code using PHP and Git.

Requirements

  • git and rsync are required on the server that's running the script (server machine).
    • Optionally, tar is required for backup functionality (BACKUP_DIR option).
    • Optionally, composer is required for composer functionality (USE_COMPOSER option).
  • The system user running PHP (e.g. www-data) needs to have the necessary access permissions for the TMP_DIR and TARGET_DIR locations on the server machine.
  • If the Git repository you wish to deploy is private, the system user running PHP also needs to have the right SSH keys to access the remote repository.

Usage

  • Configure the script and put it somewhere that's accessible from the Internet. The preferred way to configure it is to use deploy-config.php file. Rename deploy-config.example.php to deploy-config.php and edit the configuration options there. That way, you won't have to edit the configuration again if you download the new version of deploy.php.
  • Configure your git repository to call this script when the code is updated. The instructions for GitHub and Bitbucket are below.

GitHub

  1. (This step is only needed for private repositories) Go to https://github.com/USERNAME/REPOSITORY/settings/keys and add your server SSH key.
  2. Go to https://github.com/USERNAME/REPOSITORY/settings/hooks.
  3. Click Add webhook in the Webhooks panel.
  4. Enter the Payload URL for your deployment script e.g. http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile.
  5. Optional Choose which events should trigger the deployment.
  6. Make sure that the Active checkbox is checked.
  7. Click Add webhook.

Bitbucket

  1. (This step is only needed for private repositories) Go to https://bitbucket.org/USERNAME/REPOSITORY/admin/deploy-keys and add your server SSH key.
  2. Go to https://bitbucket.org/USERNAME/REPOSITORY/admin/services.
  3. Add POST service.
  4. Enter the URL to your deployment script e.g. http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile.
  5. Click Save.

Generic Git

  1. Configure the SSH keys.
  2. Add a executable .git/hooks/post_receive script that calls the script e.g.
#!/bin/sh
echo "Triggering the code deployment ..."
wget -q -O /dev/null http://example.com/deploy.php?sat=YourSecretAccessTokenFromDeployFile

Done!

Next time you push the code to the repository that has a hook enabled, it's going to trigger the deploy.php script which is going to pull the changes and update the code on the server machine.

For more info, read the source of deploy.php.

Tips'n'Tricks

  • Because rsync is used for deployment, the TARGET_DIR doesn't have to be on the same server that the script is running e.g. define('TARGET_DIR', '[email protected]:/full/path/to/target_dir/'); is going to work as long as the user has the right SSH keys and access permissions.
  • You can have multiple scripts with different configurations. Simply rename the deploy.php to something else, for example deploy_master.php and deploy_develop.php and configure them separately. In that case, the configuration files need to be named deploy_master-config.php and deploy_develop-config.php respectively.

If you find this script useful, consider donating BTC to 1fLnPZkMYw1TFNEsJZCciwDAmUhDw2wit.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap