Automated Deployment of PHP Application using Github Push.

Nowadays most of my side projects are managed with Github. It has more advantages and flexibility to manage file versions. I am following a different webhook system to automatically deploy my old PHP projects. Not sure about the standards, but the following solution is an alternative approach that may solve your deployment problem for every Github push.

Create a Github Private Repository
Go to Github and create a private repository.

Generate User Token
Go to Github Settings -> Developer Settings -> Personal Access Tokens. Here you can choose token expiration date.

Clone your project
You can checkout the project using developer secret token. Make sure don’t share the developer token with anyone and don’t commit this to Github.

$git clone https://your_developer_token@github.com/username/your-php-application.git
$cd your-php-application

Push Changes
You can create or add files here and push to the repository
$git add .
$git commit -m “Project files”
$git push

Repository Changes
Here I have committed an index.php

Deploy Webhook File
Create a file your-php-application-deploy.php in root level /var/www/html for Apache. If you are using XAMPP create under opt/lampp/htdocs directory. Here the code use your own secret key for code execution directly.
Shell execution

  • Removes the existing project folder.
  • Clone the project using developer token
  • Delete .git folder for preventing git config file.

Leave a Reply

Your email address will not be published.