How to put a Laravel App into Production

How to put a Laravel App into Production

Putting a Laravel App into Production: Manually deploying your Laravel project to a live web server


You’ve been developing your new Laravel project locally for some time, you’ve hit your feature milestones and the app has passed testing. Everything is checked in to your git master branch, so now it’s time to deploy it to a live server and let your end customers access it.

Whilst there are a number of tools to help automate or simplify the deployment process, such as Laravel Forge, we believe it’s beneficial to go through the process of manually deploying a Laravel project at least once, as it helps with understanding the architecture and can make for smoother updates and easier troubleshooting in the future.

In this guide we’ll be doing just that, we’re not going to focus heavily on the server configuration side of things as this can vary depending on your host but instead on the steps required to get your app from your local environment into your production environment.


We’ll assume you have access to a web server configured with the LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) stack, with (at time of writing for Laravel 5.8, the following specs:

  • PHP >= 7.1.3
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

You’ll also need SSH access to run terminal commands as part of the deployment process.

We like DigitalOcean for quickly spinning up a server instance and getting everything configured (use this link to get a 30 day free trial with $50 credit to get you up and running). There’s some good guides on their site explaining these setup steps, and an example server configuration for Nginx in the Laravel docs.

Finally, we’ll assume you’ve checked your code into your git repository and you have all the necessary credentials to access it from your server.

Putting your Laravel app into production

Using the example server config file from the Laravel docs above, on your web server you will have an / directory with a /public/ directory inside (depending on your specific server configuration this could be a /public_html/ directory or something else).

So first of all we’ll clone our project into the / directory from our git repository. That directory is not publicly accessible and therefore maintains the security of the project files. Then we’ll create a symlink between our project’s /public/ directory and the / directory.

So from inside the / directory, run

git clone http://[GIT_SERVER]/your-app.git

You should see your project files in the / directory now.

To link the / directory to your / directory run the following commands:

mv public public_bak
ln -s your-app/public public

Check that the paths in the following two lines in your index.php in /your-app/public/ are correct relative to the location of your project files:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

If your app requires a database make sure you have a suitable database set up and have the credentials to hand.

Now we need to update the project’s .env file. These are usually not checked into git repositories by default as they can contain sensitive password information and local and production deployments will require different settings.

There should be an .env.example file in your project which you can rename to .env. The key areas to edit now are the database settings if a database is being used, and this section:


Set APP_DEBUG to false and APP_ENV to production, and update the APP_NAME and APP_URL accordingly. If you leave APP_DEBUG as true, in the event of errors you’ll be displaying sensitive debug information to the world (see our Seaborne Freight article), so make sure you change it!

We need to set some folder permissions so they are writeable, specifically the /storage/ and /bootstrap/cache/ folders. These commands may vary depending on your server configuration, but the following commands should set the necessary folder permissions:

chmod -R o+w storage
chmod -R o+w bootstrap/cache

Now we need to install Composer, so run the following:

composer install — optimize-autoloader — no-dev

We need to generate an application key (the APP_KEY setting from the .env file above), to do this, run:

php artisan key:generate

Laravel uses this key for (amongst other things) encrypting cookies.

If you have any database migrations that need to be run to structure your tables, then run the following:

php artisan migrate

If you have seed data to populate your tables with, then run:

php artisan db:seed

That’s basically it! You should be able to go to your new site and see your Laravel project default page. Test out some of your app’s features and make sure the database is working as expected.

To cache the site config, run:

php artisan config:cache

To cache the routes, run:

php artisan route:cache

We hope this article has been a helpful overview of what’s involved with deploying Laravel based websites and web apps. If you need help with a deployment don’t hesitate to get in touch.

laravel php web-development

What's new in Bootstrap 5 and when Bootstrap 5 release date?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[]( ""), we at Data EximIT have...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer]( "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Advantages of Hiring PHP Developer for your Website Project

PHP - Hypertext pre-processor, a scripting language used by many people in developing web pages, but most of us are unaware even of the full form. To train someone and make them learn this whole language is as difficult and time-consuming as it is...

Hire PHP Developer and Web Developer for your Online Business

PHP is widely used open-source scripting language it helps in making dynamically easy your websites and web application. Mobiweb Technology is your best technical partner and offering you solution for any kind of website and application...