The answer to the above question needs to cover a lot of points. Laravel projects are easier to handle and some common features used in the majority of web applications are preloaded with Laravel itself.
It is used to create scalable web applications in less time and we can deliver this project to our clients with much confidence. The Model-View-Controller architecture and well-arranged file structure of a Laravel project make it easier for a web developer to handle his/her project.
We also need to discuss the importance of the Debian operating system in this guide. Majority of the Linux users are using Ubuntu and Mint. But Debian always has it’s space because it is available in almost all cloud service providers. It also gives importance to free software other than proprietary. It is also stable compared to other Linux distributions.
Here we are going to install and set up Laravel 5.8 on our Debian 10 Buster Operating System.
Follow the steps below to install and set up Laravel 5.8 on Debian 10 Buster:
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.
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
This permission allows all users to change read/write and change the directory structure of our Laravel application. So it needs to change before deploying 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;
One of the alternative ways of creating a database on our system is using phpMyAdmin.
- On our browser enter this URL https://localhost/phpmyadmin and proceed with the username and password of our phpMyAdmin (phpMyAdmin username and password we have created on step 5).
- Click on the New tab
- Enter a database name(awesome-project-db)
- Press Create
10. Edit .ENV
Now enter our project directory and open .env file.
If there is no .env file in the project, we have to create a file and paste all the contents from sampe.env to it and save with the .env filename.
Now replace the credentials in .env file with ours.
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
We can run our Laravel application using the below command.
php artisan serv
It will open a new tab on our browser with the address below.
If we wanted to open the app on another port,
php artisan serv --port=[port-number]
php artisan serv --port=9000
It will open the app in the below URL
Have a nice code!