Install laravel 5 on Ubuntu 16.04

Solution 1:

How to install Laravel in Ubuntu 16.04

Update: Laravel 5.4

Because of great interest for this question I have decided to update it and create a small bash script to install everything you need to work with Laravel (this one is with the NGINX)

https://github.com/emilas44/laravel-5.4-on-Ubuntu/blob/master/script.sh

You can simply copy it and edit it as you please...maybe you already have some components installed which are inside the script, if so, you can freely delete the parts which you don't need.


Laravel 5.2 is down below:

basic stuff install (optional)

sudo apt-get install git
sudo apt-get install zip

LAMP

sudo apt-get install tasksel
sudo tasksel install lamp-server

CURL

sudo apt-get install curl php-curl php-mcrypt php-mbstring php-gettext

enable mods

sudo phpenmod mcrypt
sudo phpenmod mbstring
sudo a2enmod rewrite
sudo systemctl restart apache2

Composer

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

install phpmyadmin

sudo apt-get install phpmyadmin     

later accessible through localhost/phpmyadmin

Creating Laravel Project

cd /var/www/html/
sudo composer create-project laravel/laravel work --prefer-dist
sudo chmod -R 777 work (do not set 777 on "live" server!)

Creating Virtual Host work.com

sudo gedit /etc/apache2/sites-available/work.com.conf

and paste this inside that document


#/etc/apache2/sites-available/work.com.conf contains following lines
<VirtualHost *:80>
        ServerName work.com
        DocumentRoot /var/www/html/work/public

        <Directory /var/www/html/work/public>
            AllowOverride All
            Require all granted
        </Directory>
</VirtualHost>

enable that site

sudo a2ensite work.com
service apache2 reload

fix hosts file so you can access it through web browser

sudo gedit /etc/hosts //space between gedit and destination!

        #/etc/hosts contents following lines                                
        127.0.0.1       work.com

or use this command

sudo -- sh -c "echo '\n127.0.0.1 \twork.com'>> /etc/hosts"

That's it laravel is installed!

I have made a tutorial on youtube how to make it right....With all the things you need to work with laravel. Here is the link: https://www.youtube.com/watch?v=A6TdaRIsG6g

Solution 2:

I had upgraded php 5.6.11 to 5.6.21.

So, in my case I had to run:

sudo apt-get install php5.6-mbstring

PS: How I upgraded from 5.6.11 to 5.6.21 following:

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php 
sudo apt-get update 
sudo apt-get install php5.6

Reason for upgrade: zend_mm_heap corrupted during composer update.

Solution 3:

These are the steps I had to take to install Laravel 5 on Ubuntu Server 16.04 after a fresh upgrade

First I had to completely remove all of PHP, so as Mohammad Barhoush stated:

  • sudo apt-get -y purge php.*

Then I reinstalled PHP with:

  • sudo apt install php libapache2-mod-php
  • sudo apt install php-cli
  • sudo apt install php-mysql

After reinstalling PHP ver.7.0 I installed the additional related packages that Mohhammad recommended:

  • sudo apt-get install curl php-curl php-mcrypt php-mbstring php-gettext php-gd

And enabled the mods

  • sudo phpenmod mcrypt

  • sudo phpenmod mbstring

    And finally after all this composer was still being a pain complaining it did not have the zip extension for a composer update so I installed the following:

  • sudo apt-get install php7.0-zip

After that it ran just fine with no errors!

These were the steps required for me to get laravel 5 functioning coming from the previous LTS version of Ubuntu Server. Hope this helped! Best regards :)

-Derick

Solution 4:

PHP mbstring extension now resides in a separate package, so you need to do:

apt-get install php-mbstring

Solution 5:

oerdnj 's solution works, after installing mbstring you should enable it in php.ini before run composer install. In my case laravel requires ext-mbstring and ext-dom:
apt-get install php-dom