How to install a new Laravel project

Laravel is powerful PHP framework, it could be pretty easy to build a site using it. I’m going to give you some very short steps to install a new Laravel project, this guide is focused on a Ubuntu environment but it could be useful to other operating systems.

First, make sure that you have already installed some basic but necessary things, you need have PHP 5.6 preferably, Apache2 and MySQL running if you don’t have them you must install them before continuing.

1. Install Composer.

You need have installed Composer because it’s going to be necessary to get the Laravel dependencies, you can install it using the following commands:

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

2. Install the Laravel project.

Now we can clone the Laravel project using this:

$ cd /var/www
$ git clone https://github.com/laravel/laravel.git

Then navigate to the project’s root and install the dependencies:

$ cd /var/www/laravel
$ sudo composer install

Only to make sure, we can set minimum permissions required:

$ chown -R www-data.www-data /var/www/laravel
$ chmod -R 755 /var/www/laravel
$ chmod -R 777 /var/www/laravel/app/storage

3. Setting up the encryption key.

To do that we need to be in the project’s root and if doesn't exist create the .env file, even you can copy the .env.example and rename it, now generate the random encryption key using the following command:

$ php artisan key:generate
Image
terminal

It’s important that you update the configuration file in config/app.php add the following line there:

'cipher' => 'AES-128-CBC',

4. Create an Apache virtual host.

Now we’re going to create a new Apache host configuration file:

$ nano /etc/apache2/sites-available/laravel.example.com.conf

It should look like this:

<VirtualHost *:80>
       ServerName laravel.example.com
       DocumentRoot /var/www/laravel/public
       <Directory />
               Options FollowSymLinks
               AllowOverride None
       </Directory>
       <Directory /var/www/laravel>
               AllowOverride All
       </Directory>
       ErrorLog ${APACHE_LOG_DIR}/error.log
       LogLevel warn
       CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

After that you must enable it and restart Apache:

$ a2ensite laravel.example.com
$ sudo service apache2 reload

5. Add it to the host file.

$ sudo nano /etc/hosts

Finally, add the new host to the file /etc/hosts and then you should be able to see the Laravel site on your browser.

 

References:

https://www.howtoforge.com/tutorial/install-laravel-on-ubuntu-for-apache/

https://laravel.com/