DEV Community

Cover image for How to set up a continous deployment pipeline for a Laravel App on a Linux server
Aduramimo Oludare
Aduramimo Oludare

Posted on

How to set up a continous deployment pipeline for a Laravel App on a Linux server

We have seen examples of how to automate application builds by dockerising and deploying them on azure cloud servers. This continous deployment which is being managed by Azure removes the burden of deployment from developers who can focus on the application itself.

In some cases, we have provisioned Linux servers for ourselves and wish to have full control of the CI/CD process (and to stop using the old FTP upload method).

For this tutorial, we have a Linux Ubuntu server (> 18.0) from Azure and have a laravel app already pushed to github which we wish to run on the server. See the latter part of deploying laravel apps on a Linux server after completing this tutorial to set up the deployed laravel app on the server.

1.cd to the desired directory you wish the app on your server and clone the app from Github:

cd /var/www/html
git clone https://github.com/dreywandowski/my-repo.git
cd my-repo
Enter fullscreen mode Exit fullscreen mode

2.Next, we need to create an SSH key-pair that would be used to access your server from Github:

ssh-keygen -t ed25519 -C "your_email@email.com"
Enter fullscreen mode Exit fullscreen mode

Please note that the email to use is the one used to sign in to your Github.
Press "Enter" to save to the default location. Also press "Enter" when asked for a paraphrase.

3.The next step is to start this key in background and add it

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

4.Test the ssh connection to github:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

You should see something like this, which confirms that you have successfully added the ssh key to your server:

Git connect

5.We need to copy the contents of this ssh key and add them to Github:

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Go to your Github > Settings > SSH and GGP keys > New SSH Key
Give it any title you wish and paste the content under the "key" column and save.

ssh key

6.Next, we need to create a workflow file to sync changes from the repository to our server.
Navigate to the repository > Actions > Laravel >configure

Laravel action

7.Click "Commit changes", navigate to the directory on your server and pull the changes:

commit

You will see a .github folder in your directory where there exists a laravel.yaml file, open it up and edit thus:

yaml file
Commit and push this to master. The deployment will fail because we are yet to define what HOST, USERNAME, PASSWORD all mean. Navigate to Settings > Actions secrets and variables > Repository secrets > New Repository secret.

Define HOST, USERNAME, and PASSWORD in turn, where HOST is your server Public IP, Username and password are your server login credentials.

Now, any push we make to the master branch from our IDE will be directly deployed on the server. You can check the workflow status under Actions.

Action

Top comments (0)