Deploying a Laravel Application

A few months ago, I explained how to set up a new Laravel application. Since that time, I have completed the development of a content management system (or CMS) that utilizes Laravel. This CMS contains administrative interfaces for managing page content, menus, widgets, users, and user permissions. I have also developed 3 packages that can be added to the system to include additional functionality for managing news articles, inquiries, and slides in a carousel on the home page.

I recently redesigned my own personal website using this CMS so that I could test it and work out the bugs before using it on an actual client project. The tricky part was deploying the new site to my web server.


Generally when launching a website, I upload all of the website files to the public_html directory on the web server (i.e. /home/accountname/public_html/) and then I’m good to go. But because of how the Laravel code base is structured (refer to the screenshot to the right), I had to do things differently with my CMS.

The files for the public display of the website are inside of the public directory within the Laravel code base. This directory is at the same level as the Laravel core files. If you put the entire code base into the public_html directory on your server, then your site will have URLs that contain the word “public” (i.e. and this is probably something that you don’t want.

In order to deploy a Laravel application so that the URLs are “clean” (i.e., you need to split up the Laravel core files and the “public” files. The following outlines how I deployed my website using my custom Laravel CMS with “clean” URLs.

1) Create a database and database user in the control panel for your hosting account. If your application does not use a database, you can skip this step.

2) Make sure that your web server meets the server requirements for the Laravel code base. On my server, I needed to enable the proc_open and exec php functions since they were disabled by default by my web host. The proc_open function is needed in order to install Composer packages and run Artisan commands, and the exec function is needed if any of the Artisan commands that you plan on running are asking for information.

3) On your web server, create a directory that is at the same level as the public_html directory that will contain the Laravel core files. I recommend you call this directory laravel (i.e. /home/accountname/laravel/).

4) Upload the following directories and files from your project into the directory you created in step #3. I have excluded some of the directories and files from my code base because they are only necessary during development.

  • app/
  • bootstrap/
  • config/
  • database/
  • resources/
  • storage/
  • tests/
  • artisan
  • composer.json
  • composer.lock
  • .env

5) Upload the contents of the public directory from your project into the public_html directory on your web server (i.e. /home/accountname/public_html/) .

6) Modify the laravel/.env file so that it contains the values specific to your application.

7) Modify the laravel/bootstrap/app.php file to set the public.path value. Add the following block of code to the file before the “Bind Important Interfaces” block. Adjust the path as needed if you are deploying the application on a subdomain.

8) Modify the public_html/index.php file to adjust the paths to point to the directory containing the Laravel core files. Refer to the following code block. Again, adjust the paths as needed if you are deploying the application on a subdomain.

9) SSH into your web server and navigate to the laravel directory that you created in step #3.

10)  Install Composer. You will need Composer to install the dependencies needed for Laravel to run.

11) Install the Composer packages needed by Laravel core and any additional packages that your application is using. The –no-dev flag will exclude any packages that you included in your composer.json file that were strictly for development (i.e. in the require-dev block).

12) Generate your application key. This command will generate a random key and update your laravel/.env file with the value.

13) If your application uses a database, run the following commands to run your migration files and execute your seeders. If you don’t have any seeders, then you can skip the second command.

Your website should now be functioning properly. I did skip some steps that were specific to my CMS. You might have to add some steps depending on your application. But this should get a basic application up and running on your web server.

Related Post

Get Organized!

Get Organized!

Save money on your website project and get off to a good start with your web designer. We'll take you through few crucial planning steps, via email, for free.

Thanks for signing up! Keep an eye out for your first email.