Laravel is a prominent member of a new generation of web frameworks. It is an open-source PHP framework and is getting more attention from developers. It is intended for the development of web applications following the model–view–controller architectural pattern. So, how to install and set up Laravel 7 on our Ubuntu system?
We can develop scalable, feature-rich, and secure web applications using Laravel and can deliver the completed projects within a short period of time. This ensures the long-term relationship between our clients.
The installation of Laravel is also easier using the composer. Here in this article, we install Laravel 7 on Ubuntu 20.04.
1. Install Apache2
Laravel requires a webserver to run. The commonly used web servers today are, Apache2 and NGINX. In this guide, we are using Apache2. We can install Apache2 with the below command.
sudo apt-get install apache2
2. Install PHP and It’s Extensions
Laravel is made with PHP and is necessary to install PHP and PHP extensions on our system.
sudo add-apt-repository ppa:ondrej/php sudo apt-get update
sudo apt install php7.3-common php7.3-cli php7.3-gd php7.3-mysql php7.3-curl php7.3-intl php7.3-mbstring php7.3-bcmath php7.3-imap php7.3-xml php7.3-zip
3. Install MySQL
Magento also needs a database server. Most using database with PHP is Mysql.
sudo apt-get install mysql-server mysql-client
When prompted, answer the questions below by following the guide.
Enter current password for root (enter for none): (Press Enter) Set root password? [Y/n]: Y New password: (Enter password for mysql DB) Re-enter new password: (Repeat password) Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
4. Install phpMyAdmin
phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySql over the Web. It can be installed using the command below.
sudo apt-get install phpmyadmin
It will ask for the MySQL credentials and we have to give it properly.
We can access the phpMyAdmin panel using the link below.
Note:- if it is giving an error “The requested URL /phpmyadmin was not found on this server”, do the below steps.
- Open apache2.conf file using nano editor.
sudo -H nano /etc/apache2/apache2.conf
- Paste the following line to the end of the file.
- Restart apache server
5. Install Composer
The composer is an application-level package manager for PHP that provides a standard format for managing dependencies of PHP software and required libraries. It helps us installing/updating various requirements/components for our app. The composer can be installed with the below command.
sudo apt-get install composer
6. Choosing the Project Destination
We need to choose /var/www/html as the project destination because it is the default root folder of the webserver of our ubuntu system.
So, direct to /var/www/html .
7. Creating a New Application
Now we can create our Laravel application using composer. AwesomeProject is the name I have chosen for my project.
composer create-project laravel/laravel AwesomeProject --prefer-dist
If the above command is failing use the below command.
sudo composer create-project laravel/laravel AwesomeProject --prefer-dist
8. Setting Permission For the Project Directory
We must set permissions for working with our project directory because as by default our system may only allow us to change the contents in our project directory as root.
sudo chmod 777 -R /var/www/html/AwesomeProject
Note:- This permission allows all users to read/write and change the directory structure of our Laravel application. So change it before deploying this Laravel app to the server.
9. Creating Database
So we have created our Laravel application. Now it needs to create a database for our application on our Mysql server.
This can be done using MySQL commands below.
mysql -u username -p CREATE DATABASE dbname; USE dbname; EXIT;
- Replace the username with the MySQL username we have created on step 4.
- Type the MySQL password when prompted.
- Replace the dbname with the database name we want to use.
mysql -u rahul -p CREATE DATABASE awesome-project-db; USE awesome-project-db; EXIT;
We can alternatively create a database using phpMyAdmin.
- Open the link in the browser. http://localhost/phpmyadmin
- Now Enter username and password(that we set when installing phpMyAdmin in step 4).
Now you can see phpMyAdmin panel where you can manage all the MySQL databases.
To create a database by clicking New from the left menu. Enter the database name and press Create.
- Click on the New tab
- Enter a database name
- Press Create
10. Edit .ENV
Now open our project directory and edit the .env file.
DB_DATABASE=(The database name we have created earlier awesome-project-db) DB_USERNAME=(Your Mysql username.) DB_PASSWORD=(Your Mysql password)
11. Migrate Database
Now we need to migrate the database from our Laravel application to our local system.
php artisan migrate
12. Running the Application
Our application can be run using the command below.
php artisan serv
This will open up a new tab on our browser with the URL below. This is the home page of our Laravel application.
Our app can also be run on another port using the command below.
php artisan serv --port=9000
This will open up our application in the port 9000
So, in this article, we have discussed the steps to install Laravel on an Ubuntu system. These steps are verified by our team and 100% working.
Have a nice code!
Be the first to reply