Deploying Laravel on DreamHost

Dennis Sauve
Apr 11 · 3 min read

My largest frustration was being unable to host more interesting projects; due to the restrictive nature of shared hosting, I had no installation privileges on the server. Without these, running composer is next to impossible. I recently pieced together the process for getting Laravel on DreamHost, and I wanted to share my findings.

Note: I’m assuming that you, the reader, have experience with DreamHost and Laravel, and I won’t bog down this walkthrough with every minute step of the process.


Configuring DreamHost

Step 1

Create a new domain/subdomain.

Step 2

Add /public to the end of the web directory field. This is because Laravel’s index.php file is located here, and is the entry point for all requests.

Note the web directory addition

Step 3

If you’re not using another database provider, create a database through DreamHost (it’s included). On the DreamHost admin menu, under “Advanced”, you’ll see “MySQL Databases”. Create a new database, and note the Hostname URL, database name, database username, and database user password.

N.B. If you’re doing local development, you’ll have to add your IP address to the database user’s allowed IP address field. You can find it by clicking the username in the table at the bottom of the databases page. Any DreamHost domains are added by default.


Preparing Your Laravel Files (locally)

Step 1

Create a new Laravel project locally, or get into the parent directory of your existing project.

Option A (No Source Control)

Step a2

Zip the directory, and upload it to DreamHost. For Mac/Linux users, you can use SCP to quickly upload from the command line. Otherwise, use DreamHost’s in browser FTP service.

Step a3

Unzip on the server. Y̵o̵u̵’̵l̵l̵ ̵n̵e̵e̵d̵ ̵t̵o̵ ̵S̵S̵H̵ ̵i̵n̵ ̵f̵o̵r̵ ̵t̵h̵i̵s̵ ̵s̵t̵e̵p̵.̵ You can now do this via DreamHost’s in browser FTP service.

Step a4

Configure your .env file with the APP_URL and database values you noted down earlier.

Option B (Using Source Control)

Step b2

Initialize a git repository in your Laravel project if you don’t have one already. I would recommend using Laravel’s .gitignore to filter out sensitive files, but it’s your choice. Publish your repository.

Step b3

Clone that git repo in your domain directory on DreamHost. git clone https://url-to-git-repo.git . That period is important, as it tells git to pull files to current directory, and not create a new directory.

Step b4

Upload any missing files via SCP or DreamHost’s in browser FTP. You might find a hint as to what files are missing in your repo’s .gitignore file.


Finalizing Your Deployment

  • Before you run any migrations, update app/Providers/AppServiceProvider.php::boot() with
public function boot()
{
Schema::defaultStringLength(191);
}

This will allow migrations to work with DreamHost’s older MySQL database system.

  • Make sure you run your Laravel migrations (locally, or on the remote server. You’ll have to mess with specifying what version of php to use on DreamHost, so I would recommend running them locally.)
  • Run through your .env file to make sure you have all the necessary fields filled out.
  • Read Laravel’s deployment documentation, it’s always a good idea to read that information from the source.

And that’s it! Now you’re ready to start developing and deploying Laravel applications for dirt cheap.

I’d like to thank Alesh Houdek for the well written article that allowed me to get up and running on DreamHost.

DevOps in the Trenches

Stories, tutorials, and solutions from the day to day life of a software developer.

Dennis Sauve

Written by

Dennis works as a software developer in the wonderful PNW. Unsolved problems fascinate him. He hikes and shoots photos with drones when he’s not glued to a mac.

DevOps in the Trenches

Stories, tutorials, and solutions from the day to day life of a software developer.