In this guide, we look at how to install Laravel framework on Ubuntu 18.04 server. Laravel is a free and open source PHP web framework. It was created in 2011 by Taylor Otwell and has since been used for development of robust mobile applications using the MVC model.
Let’s dive in and see how we can install Laravel framework on Ubuntu 18.04 LTS Server.
Before we install Laravel framework, let’s first install the prerequisite packages that will be required.
Table of Contents
System prerequisites
Your system will need to satisfy the requirements below before proceeding.
- Apache Web server
- PHP >= 7.1.3 with OpenSSL, PDO, Mbstring, Tokenizer, XML, Ctype and JSON PHP Extensions.
- Composer – an application-level package manager for the PHP
1. Install Apache Web server and PHP 7.2
We are going to add a third party PHP repository. Even though Ubuntu’s own repository has its own PHP, a third party repository is very much recommended because it gets more frequently updated.
To add the repository execute the command:
$ sudo add-apt-repository ppa:ondrej/php
Sample Output
Next, update your system’s repositories.
$ sudo apt update
Sample Output
Next, install Apache and PHP 7.2 alongside other prerequisites.
$ sudo apt-get install apache2 libapache2-mod-php7.2 php7.2 php7.2-xml php7.2-gd php7.2-opcache php7.2-mbstring
Sample Output
2. Install Composer
Before we embark on the installation, we will first install a few useful tools. These are git version control, curl and unzip packages.
$ sudo apt install curl git unzip
Sample Output
Next, we need to install composer. The composer is another useful tool that handles dependency management in PHP and allows you to package the required libraries associated with a package as one. Composer will download and install all the packages required to run the Laravel framework.
To install Composer, execute the following commands
$ cd /opt
$ curl -sS https://getcomposer.org/installer | php
Sample Output
The curl command downloads Composer to the /opt
directory. Since we need composer running globally, we must move it to the /usr/local/bin
directory under 'composer'
name.
$ mv composer.phar /usr/local/bin/composer
This will allow us to run composer from anywhere.
3. Install Laravel Framework
Now, let’s navigate to the public_html directory of our Ubuntu System. To install Laravel, we will navigate to the /var/www/html
directory.
cd /var/www/html
Next, we will create a directory “your-project” with Laravel installation. The composer will proceed to use Git to download and install all packages and modules that Laravel requires for functioning.
$ sudo composer create-project laravel/laravel your-project --prefer-dist
Sample Output
4. Configure Apache Web Server for Laravel
The next step is to configure our Apache Web server. We need to assign the necessary permissions to the project directory which will allow access to it from the www-data
group and give it write permissions to the storage directory. To get this done, run the following commands.
# sudo chgrp -R www-data /var/www/html/your-project
# sudo chmod -R 775 /var/www/html/your-project/storage
Now let’s navigate to /etc/apache2/sites-available
directory and run the command below to create a configuration file for our Laravel install.
$ vim /etc/apache2/sites-available/laravel.conf
Add the following content:
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/your-project/public
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Save the file and Exit.
Finally, we are going to enable the newly created laravel.conf
file. But before that, let’s disable the default config file.
$ sudo a2dissite 000-default.conf
Sample Output
Next, enable the Laravel config file.
$ sudo a2ensite laravel.conf
Sample Output
Then enable rewrite mode:
$ sudo a2enmod rewrite
Sample Output
Lastly, restart the Apache service.
$ sudo systemctl restart apache2
To verify that Apache is running execute the command:
systemctl status apache2
Sample Output
5. Test Laravel Website
At this point, You have successfully installed Laravel on your Ubuntu 18.04 LTS System. To confirm that the installation went as expected visit your server’s IP address.
https://server-IP-address
In my case, the server’s IP is https://38.76.11.149
We hope that this guide has been helpful. Feel free to leave your feedback at the comment section.
Just curious …
Is there an IDE like PHPSTORM to make it easier to handle LARAVEL like in WINDOWS platform ?
This framework offers developers to conserve time and also assists decrease planning and thinking to constitute the complete website from the scrape. Furthermore, it is an open-source framework of PHP and pursues the MVC (model-view-controller) architectural design. Apart from this, this framework provides a lot of descriptive and explanatory forums, expert’s opinions and blogs for flawless free coding. for more details you can also visit :-https://thedigizones.com/blog/
we need to install Composer. The composer is another useful tool that handles dependency management in PHP and allows you to package the required libraries associated with a package as one. Composer will download and install all the packages required to run the Laravel framework.
how have ip address server
Thanks a lot, it worked straight forward.