Below is the system requirements for the installation of latest Laravel application on your system.
PHP >= 7.2 OpenSSL PHP Extension PDO PHP Extension Mbstring PHP Extension Tokenizer PHP Extension XML PHP Extension Ctype PHP Extension JSON PHP Extension BCMath PHP Extension
Step 1 – Install LAMP
To start with Laravel, we first need to set up a running LAMP server. If you have already running LAMP stack skip this step else use followings commands to set up the lamp on Ubuntu system.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.2 php7.2-mcrypt php7.2-gd php7.2-mbstring php7.2-xml
Install PHP Mcrypt Extension & Install Apache2
sudo apt-get install apache2 libapache2-mod-php7.2
Install MySQL
sudo apt-get install mysql-server php7.2-mysql
Step 2 – Install Composer
The composer is required for installing Laravel dependencies. So use below commands to download and use as a command in our system.
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer sudo chmod +x /usr/local/bin/composer
Step 3 – Install Laravel
Download the latest version of Laravel from the official git repository. Use the below command to clone the master branch of the Laravel from GitHub.
cd /var/www git clone https://github.com/laravel/laravel.git
Navigate to Laravel code directory and use composer to install all dependencies required for Laravel framework.
cd /var/www/laravel sudo composer install
The dependencies installation may take some time as per your network speed. After successfully installing all dependencies, set the proper permissions on all files.
chown -R www-data.www-data /var/www/laravel chmod -R 755 /var/www/laravel chmod -R 777 /var/www/laravel/storage
Step 4 – Setup Encryption Key
Now, rename the .evn.example file to .env in projects main directory. This will use to setup application environment for the project.
mv .env.example .env
Now generate base64 random number encryption key, which used by the Illuminate encrypter service.
php artisan key:generate Application key set successfully.
Edit the .env configuration file and update the required settings. Also, make sure APP_KEY is properly set as generated in above command.
vi .env
APP_NAME=Laravel APP_ENV=local APP_KEY=base64:HFdS7c9rhDp+AeHu7kc2OLBPuxHqq2BQ/1gfFWEpoAk= APP_DEBUG=true APP_URL=http://localhost ...
Step 5 – Create Database for Laravel (Optional)
You may also require creating a database for your Laravel application. Login to your MySQL server and create MySQL database and user.
mysql> CREATE DATABASE laravel; mysql> GRANT ALL ON laravel.* to 'laravel'@'localhost' IDENTIFIED BY 'secret'; mysql> FLUSH PRIVILEGES; mysql> quit
Now edit the .env file and update database settings.
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=laravel DB_PASSWORD=secret
Step 6 – Apache Configuration
Edit Apache default virtual host configuration file 000-default.conf and update DocumentRoot to Laravel public directory as below:
vim /etc/apache2/sites-enabled/000-default.conf
also add some more configuration.
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/laravel/public <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/laravel> AllowOverride All </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Reload Apache configuration changes by restarting service using below command
sudo service apache2 restart
Step 7 – Access Laravel Application
You have successfully configured the Laravel 5 PHP framework on your system. Access Laravel application in your favorite web browser. Let’s start building an awesome application using Laravel 5 PHP Framework. Thanks.