Set up Laravel Environment on Elementary OS

Install Apache, PHP, MySQL

You can probably skip this part if you’re going to only use Homestead. Just skip down to Install Composer.


Add Apache respository

sudo add-apt-repository ppa:ondrej/apache2

Install Apache

sudo apt-get update
sudo apt-get install apache2

PHP 5.6

Add repository

sudo add-apt-repository ppa:ondrej/php5-5.6

Install PHP

sudo apt-get update
sudo apt-get install php5-cli php5-json php5-curl php5-mcrypt

MySQL 5.6

Add repository

sudo add-apt-repository ppa:ondrej/mysql-5.6

Install MySQL 5.6

sudo apt-get update
sudo apt-get install mysql-server

Now, if all went well, you should see the Apache2 default page when you visit http://localhost. To test that things are working, create a new file in /var/www/html/ called info.php (or whatever you want to call it) with the phpinfo function in it:


Then go to that file at http://localhost/info.php and you should see the php info page.

Install Composer

curl -sS | php

You should get a message saying that composer was successfully installed to: /home/username/composer.phar. Move it to /usr/local/bin so you can just type “composer” to use it.

sudo mv /home/username/composer.phar /usr/local/bin/composer

Now, you should be able to just type “composer” and get the list of commands.

Install Git

Just install Git through the software center. Then set it up.

git config --global "John Doe"
git config --global ""

If you want to see your settings type

git config --list

Generate your SSH public key. If you don’t already have an SSH key, run ssh-keygen to generate one.


When prompted where to save, just hit enter to accept the default. You can leave the passphrase empty if you don’t want to type a password when you use the key.

Create a Test Laravel Project

Create a folder where you want your project to live. I will create a Code folder in my home folder. Then cd into that directory and create a new laravel project with Composer.

composer create-project laravel/laravel name-of-project

Once that has installed, you can test it by booting up the php server.

php -S localhost:8888 -t public

Visit http://localhost:8888 in your browser and you should see the default Laravel start page.

Install Homestead

First, install VirtualBox through the Software Center or download it from the website. I installed it from Software Center but probably should have just downloaded it since I think you get a newer version that way. Next you install Vagrant. I tried installing it from Software Center but I got an old version and wasn’t able to pull in the Laravel box. So then I went to the Vagrant website and just downloaded the Linux Debian 64-bit version and opened it from the Downloads folder. Software Center took over from there and offered an upgrade. Then I was able to pull in the laravel box.

vagrant box add laravel/homestead

Now, install Homestead with Composer.

composer global require "laravel/homestead=~2.0"

Next, you’ll need to add “~/.composer/vendor/bin” to your PATH so you can use the “homestead” executable.

sudo vi ~/.bashrc

Append the following to this file and save it.

export PATH="~/.composer/vendor/bin:$PATH"

Then reload.

source ~/.bashrc

Then check to see if it’s been added correctly.

echo $PATH

Now you should be able to run the homestead command. Now, run homestead init to create the Homestead.yaml file. Then run homestead edit to edit this file and configure Homestead. I actually haven’t been able to get homestead edit to work so I just do sudo vim /home/username/.homestead/Homestead.yaml

I had a lot of issues getting Homestead up and running so just follow the Laravel docs because I don’t have good instructions for this. Eventually you should be able to do homestead up and then homestead ssh and be there. If you configured your Homestead.yaml file correctly, you should be able to view the start page of your project in the browser now. Oh, and also edit the hosts file so you can go to ‘’ or whatever url you want to use.

Install Chrome Browser

Download this from the Chrome website and open it from Downloads. It should install when you click on it.

Install PHPStorm

Then download PhpStorm from the website and uncompress where you want it to be installed and follow the instructions in the Install-Linux-tar.txt file. Once it’s installed you can open it from the terminal with pstorm.

Laravel on Bluehost Shared Hosting

Project Code

Create new directory at root called “laravel” and put entire project minus the public folder there. Create a new .env file and call it .env.production. Change the values inside that file to reflect the production environment. Upload that file to the production server and rename it to .env.

Public Code: Subdomain

Do this if you want to put the public folder into a subdomain (like for testing). Create your subdomain through cPanel and your directory structure will be /public_html/subdomain. Clear out the “subdomain” folder.

In the public folder, create a new file and call it bluehost.index.php or whatever – just so you know it’s the index file only for the live site. Copy the contents of index.php into it.

Then, change

require __DIR__.'/../bootstrap/autoload.php';


require __DIR__.'/../../laravel/bootstrap/autoload.php';


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


$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';

// set the public path to this directory
// so that public_path() still works
$app->bind('path.public', function() {
return __DIR__;

Now upload the contents of your public folder to the subdomain directory. Rename bluehost.index.php to index.php.

Add Note Within Zend Form

Add a note such as “forgot password” inside a Zend form. I haven’t tried this – I just came across it when I was researching something else but I think I will want it later.

new Zend_Form_Element_Note('forgot_password', array(
    'value' => '<a href="' . $this->getView()->serverUrl($this->getView()->url(array('action' => 'forgot-password'))) . '">Forgot Password?</a>',


Check For an Element on the Page with jQuery

Sometimes I write a function that I only want to apply to certain pages. Say, a form. I may need some javascript to apply to the form when I’m inserting and different javascript to apply when I’m editing. Since I’m reusing the form, I just change the id of the form and use this check:

if ($('#insert-form').length > 0) {
// do stuff that only applies to the insert form

Naming Controllers and Models with Multiple Words

Here are the rules regarding using multiple words in your controllers and models. Just use capital camel-case.

class Default_Model_TwoWords extends Zend_Db_Table


The name of the file would just be TwoWords.php.


class Default_TwoWordsController extends Zend_Controller_Action


The name of the file would, of course, be TwoWordsController.php.

However, your views will be in a folder called “two-words” and the url will be Note the dash.