HomeHow ToHow to Deploy Laravel to Production Server on Ubuntu with GitHub

How to Deploy Laravel to Production Server on Ubuntu with GitHub

In the previous laravel tutorial, we have seen how you can install laravel on your local machine to get started with your laravel project.

But what if your project is ready and you want to transfer it to a production server?

Is it feasible to transfer all the files from your development environment to the production server?

How to provide updates to the project after deploying it to the production server?

Here in this tutorial, we are going to tell you a step by step process by which you can transfer the whole laravel project with the help of GitHub. First of all, let’s have a brief introduction to GitHub before we get started.

What is GitHub?

GitHub is a web-based Git or version control repository and Internet hosting service. It is mostly used for code. It offers all of the distributed version control and source code management functionality of Git as well as adding its own features.

Source: Wikipedia.org

Why are we using GitHub?

Let’s say you have a project that will be modified every once in a while because you want to provide frequent updates and bug fixes from time to time.But does it mean that you have to re-upload your whole project every time you modify something?

But does it mean that you have to re-upload your whole project every time you modify something?

Well, technically yes. But what if after uploading you discover that there is some critical bug in the updated version. How can you roll back?


Protect Your Online Privacy With Surfshark
[The VPN that we use here at Tech Arrival]


All of these problems can easily be addressed by using GitHub. You can find out more about it on the web because in this article we are not diving too much into GitHub.

Steps to Deploy Laravel to Production Server on Ubuntu with GitHub

There are several steps that need to be followed in order to successfully deploy your laravel project on the server.

Creating a GitHub Repository

  1. First of all, you will have to create a GitHub repository so that your project can be uploaded there.
  2. Login to your GitHub Account.
  3. Click on the +(Plus) icon and click New Repository.Github New Repository
  4. Now you will see a page like this. Fill out the repository name. (The one that you can remember easily)
  5. If you want to keep your project private you will need to buy GitHub premium plan.
  6. For Laravel Project select the .gitignore file and search for Laravel. This will add all the dependencies folders and other common folders to the .gitignore file.Github Create Repository
  7. Now click Create Repository.

Uploading Project to The GitHub Repository

There are various softwares available for Windows, Linux, and Mac systems. But here we are considering that you are using a Linux Distribution for Laravel Development.

  1. Install Git by typing sudo apt-get install git.
  2. Now mount the project directory using the cd command.
  3. Type git init to initialize the git repository in that folder.
  4. Execute git remote add origin https://github.org/{yourusername}/{repositoryname}.git to link the GitHub repository to the current directory.Github Linux
  5. Now for user-friendliness, we are going to set git to remember credentials everytime we have to push or pull to the repository. To do so type git config credential.helper store
  6. Fetch the .gitignore file from the repo using git pull origin master.
  7. Now you can add all the files using git add . command
  8. Commit all the file using git commit -m “Initializing the Repo”.
  9. Upload the modifications using git push origin master.

To verify that the push was successfull you can go to your repository URL and check that the files are uploaded or not.

Setting Up the Production Server

Well, this is a very easy task as we have already discussed how to set up a laravel development server on Ubuntu 16.04.

Here is what you have to do. Follow all the steps given in How to Install Laravel 5.5 on Ubuntu 16.04 but don’t create a new laravel app. Just create an empty folder and consider it your project directory.

Note: You can ignore dev packages and install the normal one like php instead of php-dev as it is not really necessary and required on a production server.

Uploading Laravel Project to The Production Server

Now it’s time to deploy your project to the production server. You will have to download all the files of the project that we previously uploaded to the GitHub repository.

  1. Install Git by typing sudo apt-get install git.
  2. Now mount the project directory using the cd command.
  3. Type git init to initialize the git repository in that folder.
  4. Execute git remote add origin https://github.org/{yourusername}/{repositoryname}.git to link the GitHub repository to the current directory.Github Linux
  5. Now for user-friendliness, we are going to set git to remember credentials everytime we have to push or pull to the repository. To do so type git config credential.helper store
  6. Fetch the entire project from the repo using git pull origin master.

Configuring and Installing Laravel Project on Production Server

  1. Once you fetch all the files to the directory, now it’s time to create .env file for the project. Create the one that is appropriate and needed for your project but make sure to set the environment to production so that confidential data is not revealed when an error occurs.
  2. Now install all the dependencies from composer.json file using command composer update.
  3. Set the permission of the project folder to 755 and storage folder to 777 so that everything can work smoothly.
  4. Test out whether the laravel installation is accessible through the browser. If you have done everything correctly you will be good to go.

Enabling Caching of Routes and Configuration

In a production server, you need to make sure that everything is snappy. For this you can enable caching of configuration and routes but here are some things that you need to keep in mind before enabling them.

  • If you are accessing any environment variables using the env() function then replace all of them to use config option. i.e. env(“APP_NAME”) is equivalent to config(“app.name”)
  • For routes caching you cannot use any Closure Routes that means you will have to compulsorily use controllers for everything.
  1. Type php artisan config:cache to enable configuration cache and php artisan route:cache to enable routes caching.Laravel Cache

You have successfully deployed your laravel project on your production server with Ubuntu.

Now, what if you need to patch an update from your development server. So here you go.


Protect Your Online Privacy With Surfshark
[The VPN that we use here at Tech Arrival]


Updating the Laravel Project

  1. On your development server type git add then type git commit -m “What you have done in the update that you can remember” and type git push origin master to upload the modifications.
  2. Now on your production server type git pull origin master to fetch all the modifications and you are done.
  3. If you have made changes to routes and config then you need to clear the cache for both.
  4. In case if you have added any dependencies to the project then install those dependencies on production server using composer update command.

So that was all on setting up the production server for your laravel project. It may be possible that you will encounter some problems during the process but feel free to leave that in the comment so that we can look into it.

Have a great day!


“As an Amazon Associate & Affiliate Partners of several other brands we earn from qualifying purchases.” [Read More Here]


2 COMMENTS

  1. I found envoyer best for deploying app from git. It really makes the process faster. I use this on my laravel hosting platform, Cloudways and I can setup a server from scratch and deploy laravel on it under half a second.

Leave a Comment

Please enter your comment!
Please enter your name here

By submitting the above comment form, you agree to our Privacy Policy and agree with the storage and handling of your data by this website.


Stay Connected

Subscribe to our Newsletter

Stay updated with all the latest news, offers and special announcements.

By signing up, you agree to our Privacy Policy and agree with the storage and handling of your data by this website.

Latest Posts

Effective Strategies to Secure Your Cloud Infrastructure and Safeguard Your Business

Cloud computing is an essential element in modern businesses due to its scalability, flexibility, and cost-effectiveness. With the widespread adoption of digital transformation, security...

10 Best WhatsApp Privacy Settings to Protect Yourself (2023)

WhatsApp has recently introduced many features to safeguard its users from SPAM and Illicit activities. Some of these features are turned on by default,...

Can You See Who Screenshotted Your WhatsApp Status?

From hiding your profile picture to limiting your audience for status, WhatsApp has introduced many features to increase the privacy level of the app. Like...

How to Automatically Spin Down or Sleep HDD on Debian

It is probably not a great idea to let your HDD spin forever on a server that is always on. Whether you are using...

What is the Black Spot on Phone Screen & How to Fix It?

Smartphone screens are delicate and can get damaged easily. One common issue smartphone users face is the black spot on phone screen. A black spot...

All Time Favorites

11 Best WiFi Hacking Apps for Android (2023)

Today, almost anywhere we go, we are surrounded by tons of WiFi Networks, whether at our homes, hotels, workplaces, or even public places like...

17 Best Illegal Android Apps Not on Play Store (2023)

Google Play Store has the most extensive collection of apps for Android. Almost everyone downloads apps from the Play Store. However, certain genuinely excellent...

15 Best Game Hacking Apps for Android (2023)

Are you a mobile gamer? If you are, then you've come to the right place. This post will tell you about the Best Game...

How to Download Torrent Files with IDM (Torrent to IDM)

Hey guys, you may all have heard about different ways to download torrent files. And some of you may also have downloaded them using...

11 Best Download Managers for Windows

The Internet is a vast resource of a lot of things which includes music, videos, movies and a lot of other things. The ability...