Image for post
Image for post

Deploying Laravel on DreamHost

Dennis Sauve
Apr 11, 2019 · 3 min read

I first started using DreamHost shared hosting in college, as an affordable means of hosting web projects. It includes domain management, no hassel SSL certs, MySQL databases, and more. It’s a great solution for most PHP projects.

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

Create a new domain/subdomain.

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.

Image for post
Image for post
Note the web directory addition

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)

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

Option A (No Source Control)

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.

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.

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

Option B (Using Source Control)

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.

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.

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…

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.

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.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store