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
52

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
This article was written quite a while ago (9 years), please keep this in mind when using the information written here. Links, code and commands might be outdated or broken.

Random articles

  • Generate Vagrant boxes with Laravel, HipHop, Nginx, WordPress, MySQL, MariaDB, MongoDB, RabbitMQ etc. with one clickGenerate Vagrant boxes with Laravel, HipHop, Nginx, WordPress, MySQL, MariaDB, MongoDB, RabbitMQ etc. with one click
  • How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 14.04 LTSHow to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 14.04 LTS
  • [Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)[Link] How to set up HipHop, Nginx and Laravel in Ubuntu 12.04 LTS (in a Vagrant box)
  • How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 or Debian 7.0/7.1How to install/setup a basic LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 or Debian 7.0/7.1
  • [RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)[RePost] Goodbye LAMP: Going Nginx, NoSQL, HHVM (41min conference talk with Arne Blankerts)
  • Extremely easy SASS in Laravel (with pure PHP)Extremely easy SASS in Laravel (with pure PHP)
  • [Link] How to create, read, update and delete (CRUD) with PDO, MySQLi and MySQL the right way (prepared statements)[Link] How to create, read, update and delete (CRUD) with PDO, MySQLi and MySQL the right way (prepared statements)
  • How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)
  • How to install the mcrypt php extension (to use Laravel 4)How to install the mcrypt php extension (to use Laravel 4)
laravellaravel 4mod_rewriteMySQLPHPUbuntu
Share this

52 Comments

  • Joseph Donahue
    May 31, 2022 1:46 pm

    I think that is one of the so much important info for me.
    And i am happy reading your article. But want to observation on few
    general issues, The website taste is great, the articles is truly excellent

    Reply
  • techcloud7
    May 19, 2018 6:35 pm

    thanks for sharing

    Reply
  • Oliver Russell
    March 12, 2018 12:10 pm

    Instead of manually setting up an Ubuntu based environment on a server for Laravel website, I think going with some solution that automates this process would be more efficient. Like Cloudways. This platform is great for hosting Laravel websites because the platform setups the server automatically. This means you can skip the server setup and configuration part and get right down to working on your Laravel website.

    Reply
  • Sudheer Kumar
    October 4, 2017 6:46 pm

    Looking forward for the updated version :D

    Reply
  • Mehul @ Tech Arrival
    September 4, 2017 9:39 pm

    Great tutorial. Can you please update it for the latest version of Laravel 5.5? It would be awesome

    Reply
  • Steve Bignell
    May 18, 2015 3:28 pm

    Thi is the best guide I’ve seen on the topic thank you so much!!!! For my scenario I was installing it on amazon linux and upgraded to httpd24 and php54 first, and laravel is now v5. *Most* items here worked, only a few I had to figure out what to change but the process as you’ve laid out worked great. Cheers :D

    Reply
  • LX
    March 28, 2015 12:57 pm

    this command does not work;

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

    Reply
  • StyleZz
    March 4, 2015 11:53 pm

    Thanks alot! Great tutorial worked very well

    Reply
  • Thomas Macaigne
    November 5, 2014 9:40 am

    I have a fresh install of Debian, followed everything, I get the Laravel homepage but when I browse to the route /about, I get 404 not found.
    Anyone explain me ?

    Reply
  • Kamlesh kumar
    October 7, 2014 12:35 pm

    Hi everyone,

    I follow the following steps and install successfully but a major problem comes,

    when I’m try to access another project folder like : http://localhost/demo

    than error comes like :

    Not Found

    The requested URL /demo was not found on this server.

    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    Reply
  • Marcus Perrout
    September 9, 2014 3:59 pm

    Nice Tuto! Thanks!

    Reply
  • Ravinesh Kumar
    September 9, 2014 4:20 am

    This installation tutorial is awesome . will you provide me another laravel Example for beginners like how to create controller , model or will you provide any small application tutorial in laravel

    Thanks Chris

    Reply
  • osoandrade
    August 7, 2014 8:11 pm

    Thanks for the tutorial! it works great! (some people already mentioned the caveats found with some distros – Mint in my case).

    How would you go about if you want to work on several projects? I understand this creates one Laravel web app. Can I work on more than one at the same time?

    Reply
  • Sanju
    July 16, 2014 9:20 am

    Thanks for your detailed instruction to set up the laravel. I follow the same all steps. However i am facing one issue. When i used to run the url in browser as you suggested either http://localhost or http://localhost/mytest

    It just display the pop up with filename do you want to download etc.. But in browser i can’t see anything.

    Could you please help me to get resolve this.

    Thanks in advance

    Reply
  • Sanju
    July 16, 2014 9:12 am

    Thanks for your detailed instruction to set up the laravel. I follow the same all steps. However i am facing one issue. When i used to run the url in browser as you suggested either http://localhost or http://localhost/mytest

    It just display the pop up with filename do you want to download etc.. But in browser i can’t see anything.

    Could you please help me to get resolve this.

    Thanks in advance

    Reply
  • hookshot
    June 28, 2014 3:14 am

    Thanks for the great tutorial!

    Instead of chmod 777’ing the app/storage folder I chown’d it:

    sudo chown -R www-data:www-data /var/www/app/storage

    I’m not a Linux expert, but basically the idea is to give ownership of the storage directory to Apache’s user & group www-data instead of changing the write permissions.

    Also, on Ubuntu 14.04 my default vhost was named 000-default.conf and I only had to change the document root.

    I used this guide to fix the mcrypt error:
    http://askubuntu.com/questions/460837/mcrypt-extension-is-missing-in-14-04-server-for-mysql

    Reply
    • Chris
      August 20, 2014 10:49 pm

      Thanks! This article was written before 14.04 came out, and as 14.04 ships with a newer version of Apache that also has different configs (!) and different config file names (as you already said). I’ll add a better version and a guide for 14.04 when there’s time! :)

      Reply
  • Andrew
    June 16, 2014 6:22 am

    This tutorial is probably the best “we” tried so far. I and my teammates tried several tutorials but nothing worked perfectly or ideally as a submodule-like installation. And found the mcrypt needs to be enabled before execute “install composer” in localhost folder. Hereunder is some commands that may require on Ubuntu 14.04/PHP 5.5.9/Apache/2.4.7:

    1. To enable mcrypt: $ sudo php5enmod mcrypt
    2. Install Composer:
    2.1 I have permission problems even prefix sudo, so root solved the problem: $ sudo -i
    2.2 Since logged in root mode…
    2.2.1 $ cd /root
    2.2.2 Then $ mv composer.phar /usr/local/bin/composer
    2.2.3 Don’t forget to: $ exit
    2.2.4 Back to the dev-metal tutorial!

    3. Specific to my freshly installed Apache:
    3.1 Only has ONE “AllowOverride None” at /etc/apache2/apache2.conf.
    3.2 Change localhost dir at /etc/apache2/sites-available/000-default.conf

    4. I create a public folder under /var/www. But the folder must be empty or laravel installation won’t complete.

    Thank you Chris!!!!

    Reply
    • Chris
      August 20, 2014 10:50 pm

      Thanks you too, I’ll use this for detailed tutorial for 14.04 soon! Merci!

      Reply
  • brentdp
    June 8, 2014 8:44 pm

    There’s one crucial step you need to do before running the command “sudo composer install” on Ubuntu 14.04.
    You should also run: sudo php5enmod mcrypt . If you don’t, it will give an error saying that the mcrypt module is missing.

    Reply
  • Joseph Rex
    June 3, 2014 3:39 pm

    I’ve not had any problem with leaving my storage folder with a 755 permission. Is it likely there are future errors? Does it really matter to give it full drwx permissions?

    Reply
  • Tharaka
    May 30, 2014 11:46 am

    It was really helpful for me. Thank you!

    Reply
  • Bruno Javier Blasco Smaranda
    May 27, 2014 6:19 pm

    Great guide!

    But it only seems to work if I try http://127.0.0.1/index.php/mytest
    Otherwise it’ll say not found. I wonder where I can change this…

    Reply
  • winendah ayu
    May 22, 2014 11:32 am

    I’m using ubuntu 14.04 and must be try it on virtualbox :D
    Thanks. It works on my virtualbox

    Reply
  • Naveed Ramzan
    April 25, 2014 8:36 pm

    It works for me. Thanks buddy

    Reply
  • Luis
    March 30, 2014 6:42 am

    Muchas Gracias, Saludo desde Chile lml !
    Thanks…

    Reply
  • Niko
    March 2, 2014 8:11 am

    Great guide, But do you have one for Ubuntu 13.10 ?

    The apache settings loads differently and cant figure it out.

    Reply
  • Leepoff
    January 22, 2014 5:23 am

    Thank you so much, Chris! I’ve been fiddling around with frameworks (Jersey, RoR) and have failed to get them working properly. This one has easily been the most friendly for someone who is still learning about setting up environments from scratch (nice to see what I’ve learned is mirrored in your directions here). I know you talk about how the install docs on the Laravel site are incomplete, but would you say they are plenty sufficient for someone who knows more of what they are doing in dev environment setups? It seems fairly common that they assume a lot which usually leaves me lost on where to go next.

    Cheers

    Reply
  • dev
    January 8, 2014 2:22 am

    I’m having a problem with running “curl -sS https://getcomposer.org/installer | php” it says The json extension is missing. Install it or recompile php without –disable-json

    Reply
    • jenniffer
      February 22, 2014 10:23 pm

      sudo apt-get install php5-json

      Reply
  • Ramasamy K
    January 7, 2014 10:21 am

    Yaa its very help full. I fixed my issue, when its happens by followed official site.

    Reply
  • Vaibhav Nadgonde
    December 21, 2013 3:56 pm

    Hi,

    I tried the way you said and it works well at the first attempt, but then I restart my pc and after that when I am trying to access my localhost it is blank.

    what goes wrong ? can you throw some light on it.

    vaibhav

    Reply
  • Joe Privett
    December 16, 2013 2:21 am

    This guide is great! It’s weird that 9 times out of 10, the developers/owners of products cannot explain properly to all levels of users – they always assume that readers are at the same level as they are – very frustrating.

    Reply
  • Kukuh Nova Putra
    December 13, 2013 7:11 pm

    Hi Chris.

    I am newbie on laravel framework and ubuntu. I have been follow your tutorial, but I’m stuck on “sudo chmod -R 777 app/storage” because there not running and show “No such file or directory”.
    Could you help me?
    Thank you.

    Reply
    • Chris
      December 13, 2013 7:38 pm

      Hey, sorry these are the absolute basics of web development. Go to the folder where app/storage is in and do the command. If you are stuck with this, then Laravel might be too much for you.

      Reply
      • Kukuh Nova Putra
        December 13, 2013 8:00 pm

        Thank you Crish, it’s work now.
        Basicly i’m on web design and front-end.
        Well, I’ll still learn this framework :)

        Reply
  • Manoj
    December 9, 2013 8:54 am

    Thank u…

    Reply
  • Ahmad Ashril Rizal
    December 7, 2013 4:31 am

    When I am Run the installation with Composer by “composer install”, I got error message.
    And then I am try “sudo composer install”, it work..
    I love this tutorial..
    Thank You…

    Reply
    • Chris
      December 7, 2013 5:15 am

      Thanks! I’ll add this to the article (but it’s possible to run composer install without sudo, simply because composer is just 100% php, not a real unix script afaik)

      Reply
  • Luís Pinto
    December 3, 2013 12:04 pm

    Thank you for this tutorial, really helped me.

    Reply

Leave A Comment Cancel reply

hiphop php

PHP’s HipHop outperforms PHP 5.5 with Zend OPCache and Nginx by 15-20 times

A very interesting benchmark on www.alexfu.it shows excellent comparisons of plain PHP on Nginx (PHP 5.3 I think) PHP on

forbes 30 under 30

Need motivation ? Check out these 2 awesome “FORBES 30 under 30” lists (web, UI, games)

The FORBES magazine has just published the new “30 under 30” lists, and they are really really interesting! Lots of

php

Somebody is writing a compiler for PHP, compiles down to machine code, outperforms HHVM

Yes, that’s right. Recki-CT compiles PHP down to machine code. It’s unbelievable what’s going on in the PHP world in

Beautiful, minimal WordPress theme ZUKI by Elmastudio (with 30% discount)

First a little disclaimer: I’m not affiliated with the company, don’t get money (or anything else) for saying this and

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

Hacked french TV channel exposed passwords in TV interview (video, screenshots, links)

This week a major french TV networks was hacked (Article on CNN #1, #2), resulting in 11 channels being completely

Joshua Davis – my hero of Flash – in two excellent interviews (audio, video)

Joshua Davis is the reason why I’ve started to code. Seriously. Back in the late 90ies, the internet was a

How to show the available version of a package (before doing apt-get install)

To show the version of the package that will be installed with apt-get install, do apt-cache policy packagename. To show

php

How to install PHP curl extension (in 5 seconds)

It’s a common wordpress problem: PHP’s curl extension is not installed! No need to mess around in config files etc,

phpstorm-8

Ignore .idea folder from git in PHPStorm

By default (?) PHPStorm will create a hidden folder named .idea directly within your project, containing user-specific stuff like chosen

1/4

Categories

Search

php
How to install PHP 7.0 on Ubuntu 14.04 LTS
hearthbleed-ssl-bug
A quick guideline on how to fix the Hearthbleed bug (and update OpenSSL) on Ubuntu
october cms
[Link] How To Install October CMS on a VPS running Ubuntu 14.04
laracon-2014-eu-amsterdam
Laracon 2013 – Kapil Verma: Engineering Complex Applications with Laravel 4 (40min video)
phpstorm 7.0 php
PHPStorm 7 has been released!
microsoft-windows-azure-cloud-hosting
Microsoft’s Azure platform gives away high money prizes for “testing out” their cloud services
First look on Gitter, the chat for GitHub
vagrant
How to copy Vagrant boxes (or duplicate them)
phpstorm-github-code-color-syntax-theme
Get Github’s code colors in PHPStorm (2014 style)
phpstorm-8
Killer-feature in PHPStorm: Search everywhere
hack-php
The first micro framework written in Hack is there: hack-mvc !
the-php-login-project
How to install php-login-one-file on Ubuntu 12.04 LTS
php
How to install/setup latest version of PHP 5.5 on Debian Wheezy 7.0/7.1/7.2 (and how to fix the GPG key error)
hearthbleed-ssl-bug
The SSL Heartbleed bug explained in 30 seconds
You made a mess with Git ? Here’s a flowchart guideline on how to fix

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
 
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT