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
55

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

55 Comments

  • Paul Brown
    February 22, 2023 1:11 am

    Excellent, what a webpage it is! This weblog provides valuable facts to us, keep it up.

    Reply
  • Nora Tenorio
    February 5, 2023 6:09 am

    Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You definitely know what youre talking about, why waste your intelligence on just posting videos to your weblog when you could be giving us something enlightening to read

    Reply
  • Jayme Silvestri
    August 24, 2022 11:13 am

    Excellent site you have here but I was curious if you knew of any forumsthat cover the same topics discussed here? I’d really love to be a part of community where I can get suggestions from other experienced individuals that share the same interest.

    Reply
  • 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

Frontend Ops Conf 2014 – Paul Irish: Delivering The Goods In Under 1000ms (40min video)

This article was written quite a while ago (8 years), please keep this in mind when using the information written

Bézier Curves – Under the Hood (4min video)

Take a peek under the hood to see how computers draw cubic Bézier curves, as used in design and motion

php uk conference

Profiling PHP Applications by Bastian Hofmann (video from PHP UK Conference 2014)

The title says it all: Profiling PHP applications.   This article was written quite a while ago (9 years), please

How to hack time (KUNG FURY promo campaign)

:) Finally, KUNG FURY is out! No need for further words, unless you lived in a cave for the last

Soundcloud’s “VP of Engineering” about using SSDs

Excellent [german] statement from Alexander Grosse (Soundcloud’s Vice President of Engineering) about using SSDs for the main application (music data

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

java vs php

Switching from Java to PHP. Seriously. A very interesting and pre-judice-free talk with Ph.D. Aris Zakinthinos

Ph.D. Aris Zakinthinos, CTO of achievers.com, a well-scalability-experienced guy and former IT employee of the military, has just delivered one

Serious hard-to-fix bug in OAuth and OpenID discovered, lots of major sites affected

Just a short notice rather than a real article, full story later (I need to check the facts): Several sources

Quick fix for 404 error in WordPress category / tag page

Just a quick fix for a common problem: Sometimes, especially after switching themes, wordpress will generate 404 errors on the

phpstorm 7.0 php

How to setup and use XDEBUG with PHPStorm 6/7 (locally in Windows 7/8 and Mac OS X)

Real debugging is probably one of the most coolest things that are possible in software development: Remember the times where

1/4

Categories

Search

This is an experimental advertisement
How to hack time (KUNG FURY promo campaign)
css3-chrome-font
Google rolls out Chrome 37, finally fixes horrible font-rendering
phpstorm-8
PHPStorm 8 (early access version) released – for free
“Fuck you. Pay Me.” How to deal with clients, the professional way. An excellent talk with Mike Monteiro.
php
“Belt” adds very clever everyday functions to PHP, comes with JavaScript naming styles and eventually solves the needle/haystack problem
microsoft-windows-azure-cloud-hosting
Microsoft’s Azure platform gives away high money prizes for “testing out” their cloud services
sass
New features in SASS 3.3 (a talk by SASS-creator Chris Eppstein)
css3-chrome-font
[Link] Retinafy your Site / Device by Nijiko Yonskai
Quick fix for 404 error in WordPress category / tag page
phpstorm-8
Ignore .idea folder from git in PHPStorm
composer
[Link] How to require versions of PHP, HHVM / HipHop, GD, curl, openssl etc. with Composer
bitdeli git github stats
Get visitor stats for your GitHub repo with BitDeli
8 awesome pure CSS spinner / loader
october cms
[Link] How To Install October CMS on a VPS running Ubuntu 14.04

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”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
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