Installing Laravel 5 on Dreamhost VPS

Laravel 5 + Dreamhost
Laravel has great documentation which is only one reason I love working with it so much. With that said, it has some dependencies that require a bit of research and configuration to get it installed. With a little bit of trial and error (and Google) I was able to get it set up. The issues that I had were mostly because of the host, not Laravel itself. Others may not have the same issue that I had, but I’ll walk through what I needed to to to get it up and running.

INSTALLATION
Laravel utilizes composer to install/run. Composer documentation explains two ways to install.

curl -sS https://getcomposer.org/installer | php

or

php -r "readfile('https://getcomposer.org/installer');" | php

I had issues with both because every time I tried to run the command, I’d get an error saying I was running php 5.2.17. Running php -v showed exactly that. Now, I know when I set up the hosting for the domain I selected PHP 5.6 FastCGI. Composer requires PHP 5.3 or later. I took to Google to see if anybody had the same problems and see what I needed to do to resolve it. Without changing the default version being used, you would have to type out the entire location of the php version you want to use. In my case I would have to write out:

curl -sS https://getcomposer.org/installer | /usr/local/bin/php56/bin/php

I really don’t want to do that every time I need to perform a php command. So, I found a couple of different posts where users changed the default php version for CLI. This site explains what I did, only I am using 5.6 instead of 5.3.

$ mkdir -p ~/bin
$ ln -s /usr/local/bin/php-5.6 ~/bin/php
$ echo "export PATH=~/bin/:\$PATH" >> ~/.bash_profile
$ echo "export PATH=~/bin/:\$PATH" >> ~/.bashrc

After starting a new session and running php -v shows that CLI is now using PHP 5.6 as default.

Problem 1 solved! But there is more…

After successfully installing Composer, it was time to install Laravel. The composer.phar executable is whatever directory you installed Composer in. In my case it’s the root of the domain I’m working in (/home/[username]/[domain-name]/).

The next step in the Laravel documentation tells you to download the Laravel installer via composer with the following command:

composer global require "laravel/installer"

Unless you have a previous application using the .phar extension, that command is likely not going to work. To enable the phar extension, it was pretty simple. This will require a phprc file. I found some good direction from this site:

$ mkdir -p ~/.php/5.6
$ echo "extension = phar.so" >> ~/.php/5.6/phprc
$ echo "suhosin.executor.include.whitelist = phar" >> ~/.php/5.6/phprc
$ php -m | grep Phar

Now, instead of the exact command Laravel tells us to use, I followed this method to get it to work:

php composer.phar global require "laravel/installer"

In the Laravel example to create a new project you can use “laravel new” or stick with the composer way like I did with this command:

php composer.phar create-project --prefer-dist laravel/laravel blog

This will create a new directory /blog in your domain. We just have to install the laravel dependencies now. Only, my final problem is I didn’t install composer as a global command. It only works in the directory that I am currently in. In order to install the laravel dependencies, composer requires a composer.json file which exists in the new directory that just got installed.

There may be a better way to do this, but for the sake of time and impatience, I just copied the composer.phar file to my new /blog directory:

cp /home/[username]/[domain-name]/composer.phar /home/[username]/[domain-name]/blog/


The final step is to go to your new /blog directory and run the composer install command:

cd blog
php composer.phar install

Depending on how you have your host setup, you can go to http://yourdomains.com/blog and should see the landing page for your new Laravel application. If that doesn’t work you can go try going to http://yourdomain.com/blog/public and you should see it then.

That was the process for me. It seemed a bit complicated, but it’s so worth it in the end. I am a problem solver and I just couldn’t let each little speed bump stop me from getting Laravel installed. Now, I am on the latest version and love it! I will be sure to show off the app when it’s in beta and ready for testing.

Let me know if this helped you at all. I’d love to hear feedback and challenges other may have faced in the installation process.

Chris
Post Created 6

4 thoughts on “Installing Laravel 5 on Dreamhost VPS

  1. Big help. A couple improvements I can add. If you don’t want to keep moving your composer.phar file around, just move it to your home directory (mv composer.phar ~/). Then you can use “composer” and not have to remember to type “php composer.phar” by adding an alias to your .bashrc

    Like this:
    vim ~/.bashrc

    then add this line to the file at the end of the file (on a new line):
    alias composer=’php ~/composer.phar’

    Save that file then refresh the bashrc with this command:
    source ~/.bashrc

    Voila! You can now use “composer” like a normal command (i.e. composer install, composer global require, etc.)

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top