l2t

Laravel Installation

What is laravel? How to setup laravel project?

I have been working with different kinds of php frameworks however I personally like laravel. It is very easy to use and comes with lots of cool features that makes your development much easier and you write smaller amount of code.

Why Laravel framework?

Laravel is a web application framework written in php language to create web or mobile apps. Some of the advantages of using laravel framework is shown below:

  • Easy to use and simple working concept.
  • Clean and elegant sytax.
  • Authentication works out of box and easy to implement
  • It supports mail, caching, job queues, background jobs, console commands etc.
  • It protects against sql injection, xss attacks, cross site scripting etc. out of the box
  • It works on MVC concept
  • In build cron management
  • Event handling, logging, migrations etc..

What needs to be installed before you start installing laravel?

In order to install laravel on your development of prod environment you first need to meet following server requirements: You must have following installed before you work with laravel.

  • PHP >= 7.2.0
  • BCMath PHP Extension
  • Ctype PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Installing laravel via composer

In order to install laravel you first need to install composer on your operating system.

To install composer please checkout my tutorial on how to install composer?

Once you have composer installed globally on your operating system run following commands:

# install laravel installer
composer global require laravel/installer

# run following commands to install laravel installer
# globally on your macOS or linux
sudo nano /etc/paths

# add following line and save the editor and exit MacOS or Linux only
$HOME/.composer/vendor/bin

# close the terminal and re-open and run following command
laravel new projectName

# if some reason above command does not work try this
$HOME/.composer/vendor/bin/laravel new projectName​

Alternatively, you may also install Laravel by issuing the Composer create-project command in your terminal:

composer create-project --prefer-dist laravel/laravel projectName​

How to add proper permission to your project?

Once you have newly created project you need to assign proper folder permissions to prevent any errors related to storage or logs folder.

Run following commands to setup correct project permissions:

# Using ACL on a System that Supports chmod +a (macOS)
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" storage
sudo chmod +a "$(whoami) allow delete,write,append,file_inherit,directory_inherit" storage

# Using ACL on a System that Supports setfacl (Linux/BSD)
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX storage
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX storage

Running newly installed laravel project

If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command.

php artisan serve

That is it. Hope you like my tutorial thank you for reading this article.