Logo
  • PHP
    • HipHop / HHVM
    • Modern PHP
    • PHPStorm
    • LAMP
    • Laravel
    • Composer
    • PDO
  • JavaScript
    • node.js
    • AngularJS
  • CSS
    • SASS
    • “CSS4” (CSS level 4)
  • HTML
  • Git
  • LAMP
  • Vagrant
  • UI / UX
  • Architecture of …
  • Off-Topic
With ♥ from Berlin
November 12, 2013
Chris
Laravel, Local Development, PHP, Ubuntu
Comments Off on Install Laravel 4 on Ubuntu 12.04 LTS (a how-to tutorial)

Install Laravel 4 on Ubuntu 12.04 LTS (a how-to tutorial)

PreviousNext

Laravel 4 is the big thing. Every blog talks about it, nearly every developer-twitter-account mentions it. Hmm, looks like everybody should try it out ! But – to my surprise – the official installation tutorial is quite confusing and also incomplete. If you install Laravel exactly like described on http://laravel.com/docs/quick#installation, well, then you’ll be stuck right after the first seconds. There’s another, more detailed installation tutorial, right in http://laravel.com/docs/installation, but this will also not clearly help you with the installation process as it simply leaves out essential steps in the setup, and you’ll have to do a lot of additional stuff to get this thing running. That’s probably why you are reading this, right ? ;) So here’s “my” full step-by-step guideline on how to install laravel 4.0 and 4.1 on a naked Ubuntu 12.04 LTS.

 

Preparing the server / environment

Log in into your naked Ubuntu 12.04 LTS and do an update and upgrade:

sudo apt-get update
sudo apt-get upgrade

Choosing the right PHP version: Laravel 4 uses Composer to install. And currently there’s a bug in composer which makes installation of dependencies extremely slow, like 60 minutes for something that usually takes 10 seconds. This bug only happens on PHP 5.3 systems, so installing PHP 5.4 might be a good choice when Composer runs very very slow. Upgrading to PHP 5.5 is (currently, November 2013) not a good choice as this will also install Apache 2.4 which has different config files, and I also don’t know how to rewrite the Apache 2.2 stuff to 2.4.

OPTIONAL: Preparation of installing PHP 5.4: This can be skipped if you are fine with 5.3.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-cache policy php5

The last command shows the to-be-installed version of PHP (on the top) . Should be 5.4.x! This process replaces the default PHP version by the chosen one, in this case the “old-stable”, 5.4.

 

Installing Apache, PHP and MySQL

sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install mysql-server
sudo apt-get install php5-mysql

The installation process is self-explaining. You can prove the installed versions of PHP and Apache with:

php -v

and

apache2 -v

 

Installing necessary PHP extensions

sudo apt-get install unzip
sudo apt-get install curl
sudo apt-get install openssl
sudo apt-get install php5-mcrypt

Usually these 4 are not installed by default, but they are necessary to 1.) unzip the .zip’ped Laravel 4 download, 2.) use Composer (which needs CURL), 3.) use Composer (which downloads via HTTPS, useable only with installed OpenSSL) 4.) use Laravel 4 (which needs mcrypt).

 

Install Composer (systemwide)

In case you wonder: The download of Composer into each project “by hand” is not recommended anymore. We use the “real” installation of Composer here:

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

 

Activate mod_rewrite

Install the mod_rewrite module (or extension or whatever it is) and restart the Apache:

sudo a2enmod rewrite
sudo service apache2 restart

Open the default vhost config file:

sudo nano /etc/apache2/sites-available/default

Now search for “AllowOverride None” (which should be there TWO times) and change both to “AllowOverride All“. Search for these two lines

DocumentRoot /var/www
<Directory /var/www>

and change them to

DocumentRoot /var/www/public
<Directory /var/www/public>

This will route a user who enters your server directly to /var/www/public (the base folder of Laravel 4) instead of /var/www. Exit and save with CTRL+X, Y, ENTER.

 

Install Laravel 4

These commands will move you into the web root (/var/www), download Laravel from GitHub, extract the files into a folder called “laravel-master”, move it’s content into /var/www and delete the download and the empty folder:

cd /var/www
wget https://github.com/laravel/laravel/archive/master.zip
unzip master.zip && cd laravel-master/ && mv * ../ && cd ..
rm -r laravel-master && rm master.zip

Run the installation with Composer by

composer install

Note from comments: Eventually you’ll have to do a sudo composer install.

Make the storage folder writeable (777 is too much for production servers, but it’s okay for this tutorial. Would be cool if more experienced linux guys could comment here: What’s the best overall-working way to give PHP write-rights to this folder ?)

sudo chmod -R 777 app/storage

and restart the server:

sudo service apache2 restart

 

First run of Laravel 4

When you navigate to your server’s IP (or domain), you should see the Laravel startscreen:

how to install laravel 4 on ubuntu 12.04 LTS

Now edit app/routes.php and add a new route:

Route::get('/mytest', function()
{
    return "Oh yeah, this really works !";
});

When you navigate to your server’s IP/adress and add “/mytest” to the URL, you should see “Oh yeah, this really works !” in the browser.

http://your-domain-or-ip/mytest

This is basically how laravel works. To get an idea what’s possible with routes, have a look on http://laravel.com/docs/quick ! Feel free to comment, share and rate this tutorial.

 

Related articles across the web

  • Real-time Apps with Laravel 5.1 and Event Broadcasting
  • Laravel 5.1 with LTS is released
  • Reddit.com: Why experienced developers consider Laravel as a poorly designed framework?
  • Running Laravel and angularjs on Docker
  • Use Gulp to Start a Laravel PHP Server
laravellaravel 4mod_rewriteMySQLPHPUbuntu
Share this

Creators of Laravel launch one-click-installations of Laravel (including nginx, PHP 5.5 etc.)

Again, a game changer: Taylor Otwell, creator of Laravel (which is currently the most popular PHP framework), has released FORGE

O’Reilly’s Learning JavaScript Design Patterns by Addy Osmani for free

Addy Osmani has published his excellent book Learning JavaScript Design Patterns for free! You can read the entire book including

php

“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem

This little projects is basically super-simple, but somehow really really clever and definitly a time-saver: Belt is a typical Composer-loaded

php

Slides from International PHP Conference 2014

Have fun :)   [slideshare id=35391362&doc=codereviewsfranksonsipc2014se-140602104917-phpapp02]     [slideshare id=35383348&doc=ipc14se-planningfortheunplannable-140602073028-phpapp02]   [pdf]http://ilia.ws/files/ipc2014_bottlenecks.pdf[/pdf]   The talk Code Coverage: Covered in Depth

phpstorm 7.0 php

How to install GitHub’s, NetBeans’s and Sublime2’s syntax highlighting code colours theme in PHPStorm 6/7

PHPStorm’s default code colouring might not be what you want, especially when you just switched from NetBeans. But there are

Berlin, prepare for TOA conference (15th – 17th of July)

If you are in Berlin right now (and have 80-300 € to spend and 2-3 days of holidays (or “spontanious

How Instagram.com works

hack-php

The first micro framework written in Hack is there: hack-mvc !

It has been just a few months ago Hack has been first announced, but some awesome people have already developed

What’s new in PHPStorm 9

PHPStorm 9 has just been released a few days ago, and as a PHP developer you should definitly give it

sass

[german video] Modernizing and minimalizing frontend markup code at AutoScout24

As this blog has a lot of german speaking readers I’ll post german stuff from time to time. Sorry for

1/4

Categories

Search

shadow dom
Crossbrowser-safe HTML5 video (IE6+) with a few lines of code and just one .mp4 video file
php
Is there a JSFiddle for PHP ? Yes !
ubuntu-14-04-lts lamp
How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 or Debian 7.0/7.1
This is an experimental advertisement
goodbye-lamp-going-hhvm-nosql-nginx-php
[RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)
Test GZIP compression of your server easily
sass laravel
Extremely easy SASS in Laravel (with pure PHP)
symfony-framework-logo
SensioLabs, creator of Symfony and Silex PHP frameworks, gets $7 million capital
vagrant
A preinstalled Vagrant box with PHP HipHop / HHVM and Ubuntu 12.04 (Precise Pangolin)
How Snapchat wants to earn money (by establishing vertical videos)
How to show the available version of a package (before doing apt-get install)
Going node.js at Netflix (Slides by Micah R of Netflix)
Microsoft enters post-password era with Hello (promo video)
composer
A short & simple Composer tutorial
PHPStorm: 42 Tips and Tricks (47min video talk by Mikhail Vink at Dutch PHP Conference 2015)

Tags

apache bash centos composer conference coupon CSS debian fonts framework git GitHub hack HHVM HipHop HTML HTML5 IDE JavaScript JS LAMP laravel linux mod_rewrite MVC MySQL Nginx optimization PHP PHP 5.5 PHP 5.6 phpmyadmin PHPStorm security server SSD Ubuntu UI UX vagrant video virtual machine voucher VPS wordpress
Side-Project: Wordle-Solver:
www.wordle-helper.info

Pages

  • Privacy Policy