How to install Laravel in Ubuntu 16.04

Basic stuff

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



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



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


Install Composer

cd ~ 
curl -sS -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer


Composer (test installation)


Composer (optional)

composer install

If composer.lock exists, composer installs exactly what is in the composer.lock

 composer update

Installs dependencies from composer.json and creates or updates composer.lock


Install phpmyadmin

sudo apt-get install phpmyadmin


Permission issue

Ensure your user is able to write to your ~/.composer and /var/www/ directory

sudo usermod -aG www-data kim
sudo chown -R www-data:www-data /var/www/
sudo chmod 775 /var/www/

Creating Laravel Project

cd /var/www/html/
composer create-project laravel/laravel work --prefer-dist
sudo chmod -R 777 work


Creating Virtual Host

sudo gedit/etc/apache2/sites-available/
<VirtualHost *:80>
DocumentRoot /var/www/html/work/public

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


Enable that site

sudo a2ensite
service apache2 reload

Common artisan operations

#Clear view
php artisan view:clear

#Clear cache
php artisan cache:clear

#Make controller
php artisan make:controller CardsController

#Create database table cards & notes
php artisan make:migration create_cards_table --create=cards
php artisan make:migration create_notes_table --create=notes
php artisan make:migration create_users_table --create=users

php artisan migrate

#Make model
php artisan make:model Note

# listen to sql query
DB::listen(function($query) {var_dump($query->sql);});


Model relationship example

 Card has many notes

class Card extends Model
public function notes(){

return $this->hasMany(Note::class);

Notes belong to Card

class Note extends Model
public function card(){

return $this->belongsTo(Card::class);

Leave a Comment

Your email address will not be published. Required fields are marked *