Setting Up Laravel Development Environment on Debian 10

29/12/2020
Chưa phân loại
In this article, I am going to show you how to install composer on Debian 10, install Laravel installer with composer and set up a Laravel development environment. So, let’s get started.

Updating APT Package Repository Cache:

First, update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Installing and Configuring MySQL/MariaDB:

Now, install MariaDB from the official package repository of Debian 10 with the following command:

$ sudo apt install mariadb-server mariadb-client

Now, press Y and then press <Enter> to confirm the installation.

MariaDB should be installed.

Now, check whether mariadb service is running with the following command:

$ sudo systemctl status mariadb

As you can see, mariadb service is running and it’s also enabled to start on system boot.

If the mariadb service is not running in any case, run the following command to start it.

$ sudo systemctl start mariadb

Now, to set up a root password, run the following command:

$ sudo mysql_secure_installation

Now, press <Enter>.

Now, press Y and then press <Enter>.

Type in a new root password and press <Enter>.

Type in the root password again and press <Enter>.

Press Y and then press <Enter> to remove anonymous users.

If you don’t want to allow root login remotely, press Y. Otherwise, press N. Then, press <Enter>.

Now, press Y and press <Enter> to remove test database.

Now, press Y and then press <Enter> to reload the privilege table.

MariaDB should be configured.

Creating New MySQL/MariaDB Users and Databases:

Now, you have to create a new user and a database for your Laravel web application.

Login to the MariDB shell as root with the following command:

$ sudo mysql -u root -p

Now, type in the MariaDB root password that you’ve just set and press <Enter>.

You should be logged in.

Now, create a database laravel_app1 with the following SQL statement:

CREATE DATABASE laravel_app1;

 

Now, create a new user laravel, set a password for the user (let’s say 123) and grant the user permission to use the database laravel_app1 with the following SQL statement:

GRANT ALL PRIVILEGES ON  laravel_app1.* TO ‘laravel’@‘localhost’
IDENTIFIED BY ‘123’;

Now, for the changes to take effect run the following SQL statement:

FLUSH PRIVILEGES;

Now, exit out of the MariaDB shell as follows:

q

Installing PHP and Required PHP Libraries:

Now, install Apache 2 web server, PHP and all the required PHP libraries with the following command:

$ sudo apt install php php-bcmath php-json php-mbstring php-mysql
 php-tokenizer php-xml php-zip

Now, press Y and then press <Enter> to confirm the installation.

Apache 2 web server, PHP and required PHP libraries should be installed.

Installing Composer:

Now, install Composer from the official Debian package repository with the following command:

$ sudo apt install composer

Now, press Y and then press <Enter> to confirm the installation.

Composer should be installed.

Now, run the following command check whether Composer is installed correctly.

$ composer –version

Composer is working correctly.

 

Installing Laravel Installer with Composer:

Now, install Laravel installer using Composer with the following command:

$ composer global require laravel/installer

Laravel installer should be installed.

Now, add the composer binary path to the PATH environment variable with the following command:

$ echo "export PATH=$PATH:~/.config/composer/vendor/bin" >>
 ~/.bashrc

Now, close your Terminal and open a new one. Then, run the following command to check whether laravel command is accessible.

$ laravel –version

As you can see, the laravel command is working just fine.

Creating a Laravel Project:

First, navigate to your project directory as follows

$ cd ~/Projects

Now, to create a new laravel project app1, run the following command

$ laravel new app1

Laravel installer will download and install all the required files and packages. It will take a while to complete.

At this point, the project should be set up.

A new directory with the name of the project (app1 in this case) should be created as you can see in the screenshot below.

Navigate to the app1/ directory as follows:

$ cd app1

The Laravel project files should be here.

To configure Laravel to use the MariaDB database that we have created earlier, edit the config/database.php configuration file.

$ nano config/database.php

Now, find the mysql section as marked in the screenshot below.

Now, change the database name, username and password fields as marked in the screenshot below. Once you’re done, save the file by pressing <Ctrl> + X followed by Y and <Enter>.

Now, start the PHP built in web server with the following command:

$ php artisan serve

Now, the Laravel web app should be accessible on port 8000.

Now, open a browser and visit http://127.0.0.1:8000 or http://localhost:8000

You should see the default Laravel page as you can see in the screenshot below.

To learn more about Laravel, take a look at the official Laravel Documentation.

So, that’s how you set up a Laravel development environment on Debian 10 Buster. Thanks for reading this article.

Sandclock IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, Sandclock IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

What Is a Boot Loader?

Although boot loaders tend to be very small and relatively simple, they play a critical role in the boot process. Visit...
28/12/2020

How to use curl command in Linux

The command curl function is to ease file transference between devices through protocols DICT, FILE, FTP, FTPS, GOPHER,...
29/12/2020

List Files Sorted by Size in a Directory Tree on Linux

Most file systems sort the files in alphabetical order of names. A user might, however, have some other preferences and...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Hướng dẫn chuyển đổi windows server windows evaluation to standard và active windows server 2008 + 2012 + 2016 + 2019
26/10/2021

How to Update Ubuntu Linux
24/10/2021

Squid Proxy Manager cài đặt và quản lý Proxy Squid tự động trên ubuntu
20/10/2021

Hướng dẫn cài đặt Apache CloudStack 4.15.2.0
19/10/2021

Hướng dẫn ký file PDF bằng chữ ký số (chữ ký điện tử) và sửa lỗi mới nhất 2021 foxit reader
19/10/2021