In this tutorial, we will see how to install Composer and Laravel on Ubuntu 20.04 to build our projects with this popular PHP framework. We will use a LAMP server for this tutorial, so we will need to have the following installed:
- Apache2
- PHP 7
- MariaDB
Update the system
The first thing we will do is update the repositories and install the packages needed to install Composer correctly:
# apt update && apt upgrade
Install the required dependencies:
# apt install php-gd php-mbstring hhvm phpunit
Installing Composer
To install Composer, we just need to run the following:
# curl -sS https://getcomposer.org/installer | php
Once Composer is installed, we need to move the Composer executable into our machine's path:
# mv composer.phar /usr/local/bin/composer
Add execution permissions:
# chmod +x /usr/local/bin/composer
Installing Laravel
We must install Laravel in the path we have configured in our VirtualHost; we will access that path via SSH
# cd /var/www/html
And clone Laravel's GIT:
# git clone https://github.com/laravel/laravel.git
Then we will move the Laravel files into our working directory:
# mv laravel/* . && mv laravel/.* . 2> /dev/null && rmdir laravel
Finally, we will install Laravel using Composer:
# composer install
Once the installation is complete, we will change the permissions:
# chown www-data: -R * && chown www-data: -R .*
Now we will create our encrypted key for our Laravel application and then enter it :
# mv .env.example .env
# php artisan key:generate
This should produce a result similar to this:
Application key [base64:ULQsledeS17HxCAsssA/06qN+aQGbXBPPpXVeZvdRWE=] set successfully.
Edit the config/app.php file and set the KEY section as follows:
'key' => env('APP_KEY', 'base64:7fO0S9TxZu8M2NwBWVEQsjPGRi+D1t6Ws8i0Y2yW/vE='),
'cipher' => 'AES-256-CBC',
Our Laravel application will now work:
For more information, you can always visit the official Laravel documentation, from which the information used to create this tutorial was taken.