Mastering Web Paths in Laravel: Installation Guide on Windows and Linux for CTF Enthusiasts

While attempting to exploit a vulnerable machine on VulnHub, I encountered a significant challenge. Up until now, I had no prior knowledge of the Laravel web framework. As a result, I struggled to identify the crucial directories and files within the framework that could provide me with valuable information. This information would be pivotal in aiding my exploitation of the targeted vulnerable machine, which is susceptible to a Local File Inclusion (LFI) vulnerability. I am determined to delve deeper into the Laravel framework to comprehend its essential components and better understand how to exploit the LFI vulnerability effectively.

Hello, everyone! I extend a warm welcome to each and every one of you to this fresh Article. Today, we have an exciting journey ahead as we delve into the world of the Laravel web framework. Our focus will be on installing Laravel on both Windows and Linux platforms. Furthermore, we'll delve into the significance of its key files, shedding light on their importance and functionality. So, let’s get started.


Let's start by addressing the question that's probably on your mind: 


What exactly is Laravel, and why do people use it?

Laravel is like a free toolkit for building websites and web applications using the PHP programming language. It's kind of like having a set of tools that make building websites easier and more organized. 

One of the cool things about Laravel is that it follows a design pattern called MVC, which helps keep everything organized and makes it easier to manage different parts of a website.

MVC Design Pattern

Imagine you're building a house. Instead of starting from scratch and doing everything on your own, you have a set of tools and plans to follow. Laravel is like those tools and plans, but for building websites. It helps with things like figuring out how different parts of a website should communicate, managing information from a database, and making sure everything runs smoothly.

So, in a nutshell, Laravel is a special helper that makes building websites faster, more efficient, and less complicated. It's like having a handy guide that shows you the best way to put all the pieces together.

Once you've wrapped your head around what Laravel is, let's dive into the next exciting phase: the installation process. 

And guess what? Laravel can work its magic on both Windows and Linux systems.

Let's zoom in on the installation steps. 


Install Laravel on Windows

If you're setting up Laravel on a Windows computer, You must have a local server. Think of it as the engine that powers your website. XAMPP and WAMP are two popular choices. 

For this walkthrough, we'll roll with XAMPP. I've got a detailed guide on how to get XAMPP up and running on my blog, so make sure to check that out.


How to Install XAMPP on Your PC

This guide provides step-by-step instructions on how to install XAMPP, a popular software package that allows you to set up a local web server environment on your computer. XAMPP is commonly used for web development and testing.


You can find out the XAMPP control panel (if installed) by Searching on Windows:

To build a Laraval Project, you need to install Composer.


Let's install Composer?

Alright, next up on our installation adventure is Composer

Composer is like a super handy toolkit that helps bring Laravel to life on your computer. 

Here's what you need to do: head over to https://getcomposer.org/download/ to grab the Composer installer designed for Windows. 


Composer - Dependency Management for PHP

Composer is a popular dependency management tool for PHP that simplifies the process of managing libraries and packages in your PHP projects. It allows you to declare the libraries your project depends on and manages the installation process.


Once downloaded, run the installer.

Now, just follow the on-screen instruction steps on your screen. 

Pay attention and don't forget to pick the option that adds Composer to your computer's PATH system. It's like giving Composer a VIP pass to smoothly collaborate with Laravel during the installation process.

Trust me, this small step ensures that Composer and Laravel are on the same wavelength, working together like a dream. 

And just like that, you're all set to dive into the exciting world of Laravel!


Creating a Brand-new Laraval Project

Now, let's roll up our sleeves and start creating a brand-new Laravel Project. The journey begins by finding your chosen destination folder where you want this project to take shape. In my case, I'll be crafting it within the `/htdocs` directory of "/xampp".

Alright, let's open the Command Prompt on your Windows machine. This is where the real magic happens. 

With a swift command, Composer, our trusty sidekick, will be at our service. Here's the command to remember: 

composer create-project --prefer-dist laravel/laravel <Your-project-name>

Just replace `<your-project-name>` with the name you want for your project. The composer will automatically create a Laravel project. 

Type 'Y' when prompted to confirm the plugin installation in the "composer.json" file. 

With this process completed successfully, you've now built your very own Laravel web framework:

Finally, we successfully build a Laraval project with the "/htdocs" of the/xampp folder.

Now, to witness this project's digital playground, we'll need to bring XAMPP into the spotlight. Go back to the XAMPP Control Panel and start the engines: Apache and MySQL. They'll be the powerhouse behind your project.

To see what's inside your Laravel project, go to your web browser and type "localhost" in the address bar. After that, add the name of your project and include "/public". Press Enter.

localhost/<your-project-name>/public

Voila! You're now on the main page of your Laravel project.

Here's a little bonus tip: If you're feeling fancy and want to set up a virtual host, you can! It's like giving your project a unique address. 

To do this, open up the `httpd-vhosts.conf`file tucked away in `C:\xampp\apache\conf\extra`. 

Drop in a few lines at the end, telling Apache where your project will reside. 

<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/your-project-name/public"
    ServerName your-project-name.local
</VirtualHost>

Change the red marked line, and paste it on Notepad, and Don't forget to save the file.


Edit the `/hosts` file

First, open Notepad as an administrator. To do this, search for "Notepad" in your computer's search bar, right-click on it, and choose "Run as administrator." 

Once Notepad is open, click on "File" in the top left corner, and then select "Open." 

You need to navigate to the location of the `/hosts` file, which can be found at  `C:\Windows\System32\drivers\etc`. 

This is where we'll tell your computer to associate your project's special address with localhost. A simple line of code is all it takes. Remember to save the file.

Hold on, we're almost there! It's time to unveil your creation. Open your web browser and type in the address: 

http://<your-project-name>.local

Take a look at your screen - there it is, the special welcome page of your Laravel project, waving its digital flag high! This means your very own creation has come to life and is ready to roll. 

Now, it's your time to jump in and get creative. Start crafting something incredible and let your imagination run wild!

 

Install Laravel on Linux

Now, let's walk through the process of setting it up on Linux. 

Linux Lite

To get Laravel up and running on a Linux system, there are a few prerequisites that you need to have in place.

Before you dive in, it's a good idea to make sure you have the latest versions of software packages. To do this, simply open a terminal and enter the following command:

 linuxlite  sudo apt update
[sudo] password for linuxlite: 
Hit:1 http://archive.canonical.com/ubuntu jammy InRelease                                                        
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]                                        
Hit:3 http://repo.linuxliteos.com/linuxlite fluorite InRelease                                                                      
Hit:4 https://dl.google.com/linux/chrome/deb stable InRelease                                                                       
Hit:5 http://us.archive.ubuntu.com/ubuntu jammy InRelease                                                                           
Get:6 http://us.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]                                                          
Get:7 http://us.archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]                                                        
Fetched 338 kB in 14s (25.0 kB/s)                                                                                                   
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
420 packages can be upgraded. Run 'apt list --upgradable' to see them.
 linuxlite   

Once the update is done, the next step involves installing apache2 and MySQL. These components are essential for Laravel, as, it relies on a web server and a database. You can install them by entering, the following command.

 linuxlite  ~  sudo apt install apache2 mysql-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libevent-core-2.1-7
  libevent-pthreads-2.1-7 libhtml-template-perl libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
  mysql-client-core-8.0 mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom ufw libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libevent-core-2.1-7
  libevent-pthreads-2.1-7 libhtml-template-perl libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0
  mysql-client-core-8.0 mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 20 newly installed, 0 to remove and 420 not upgraded.
Need to get 30.7 MB of archives.
After this operation, 248 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Type 'y' to continue to download the apache2 and MySQL:

Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libapr1 amd64 1.7.0-8ubuntu0.22.04.1 [108 kB]
<SNIP>
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.service → /lib/systemd/system/apache-htcacheclean.ser
vice.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
 linuxlite  

After completing the installation, it's important to ensure that the apache2 and MySQL services are up and running. 

To start the apache2 service, use the following command: 

 linuxlite  ~  sudo service apache2 start
 linuxlite  ~

You can check the status of the service by entering the following command: 

 linuxlite  ~  sudo service apache2 status
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-08-10 21:06:55 IST; 5s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 5082 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 5086 (apache2)
      Tasks: 55 (limit: 1617)
     Memory: 4.8M
        CPU: 36ms
     CGroup: /system.slice/apache2.service
             ├─5086 /usr/sbin/apache2 -k start
             ├─5090 /usr/sbin/apache2 -k start
             └─5091 /usr/sbin/apache2 -k start

Aug 10 21:06:54 linuxlite systemd[1]: Starting The Apache HTTP Server...
Aug 10 21:06:54 linuxlite apachectl[5085]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, >
Aug 10 21:06:55 linuxlite systemd[1]: Started The Apache HTTP Server.
lines 1-17/17 (END)

To confirm that apache2 is working correctly, open a web browser and type in "localhost" as the URL. This will allow you to see the contents served by the apache2 service and verify its proper operation.

Similarly, to start the MySQL service, use the command using the following command: 

 linuxlite  SIGINT  sudo service mysql start
 linuxlite  ~  

You can check the status of the service by entering `sudo service apache2 status`. 

 linuxlite  ~  sudo service mysql status
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-08-10 21:03:22 IST; 6min ago
   Main PID: 4168 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 1617)
     Memory: 354.1M
        CPU: 4.251s
     CGroup: /system.slice/mysql.service
             └─4168 /usr/sbin/mysqld

Aug 10 21:03:21 linuxlite systemd[1]: Starting MySQL Community Server...
Aug 10 21:03:22 linuxlite systemd[1]: Started MySQL Community Server.

Now that your server setup is ready, let's move on to installing Laravel. But before that, ensure that your system has PHP, Composer, and the required dependencies. To install these, simply open a terminal and run the following command on the terminal.

 linuxlite  ~  sudo apt install php php-cli php-mbstring php-xml php-zip unzip composer
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
unzip is already the newest version (6.0-26ubuntu3.1).
The following additional packages will be installed:
  git git-man jsonlint libapache2-mod-php8.1 liberror-perl libonig5 libzip4 php-common php-composer-ca-bundle
  php-composer-metadata-minifier php-composer-pcre php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler
  php-intl php-json-schema php-psr-container php-psr-log php-react-promise php-symfony-console php-symfony-deprecation-contracts
  php-symfony-filesystem php-symfony-finder php-symfony-polyfill-php80 php-symfony-process php-symfony-service-contracts
  php-symfony-string php8.1 php8.1-cli php8.1-common php8.1-intl php8.1-mbstring php8.1-opcache php8.1-readline php8.1-xml
  php8.1-zip
Suggested packages:
  fossil mercurial subversion git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb git-cvs git-mediawiki
  git-svn php-pear php-symfony-event-dispatcher php-symfony-lock php-symfony-service-implementation
The following NEW packages will be installed:
  composer git git-man jsonlint libapache2-mod-php8.1 liberror-perl libonig5 libzip4 php php-cli php-common php-composer-ca-bundle
  php-composer-metadata-minifier php-composer-pcre php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler
  php-intl php-json-schema php-mbstring php-psr-container php-psr-log php-react-promise php-symfony-console
  php-symfony-deprecation-contracts php-symfony-filesystem php-symfony-finder php-symfony-polyfill-php80 php-symfony-process
  php-symfony-service-contracts php-symfony-string php-xml php-zip php8.1 php8.1-cli php8.1-common php8.1-intl php8.1-mbstring
  php8.1-opcache php8.1-readline php8.1-xml php8.1-zip
0 upgraded, 42 newly installed, 0 to remove and 420 not upgraded.
Need to get 11.1 MB of archives.
After this operation, 50.0 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Type "y" to continue:

Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 php-common all 2:92ubuntu1 [12.4 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 php8.1-common amd64 8.1.2-1ubuntu2.13 [1,125 kB]
<SNIP>

Once you've got the necessary prerequisites set up, you're ready to create your new Laravel project using Composer. 


Create a New Laraval Project

Start by choosing the directory where you want your project to reside. In my case, I'll be creating it in the /var/www directory. 

 linuxlite  cd /var/www
 linuxlite  / | var | www  

To begin, execute the following command:

composer create-project --prefer-dist laravel/laravel <Your-project-name>

Replace '<your-project-name>' and run it with "sudo" the terminal:

 linuxlite  / | var | www  1  sudo composer create-project --prefer-dist laravel/laravel myproject
[sudo] password for linuxlite: 
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 

When prompted, type "yes" to proceed as the root user.

Continue as root/super user [yes]? yes
Creating a "laravel/laravel" project at "./myproject"
Installing laravel/laravel (v10.2.5)
  - Installing laravel/laravel (v10.2.5): Extracting archive
Created project in /var/www/myproject
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
https://repo.packagist.org could not be fully loaded (The "https://repo.packagist.org/p2/spatie/laravel-ignition.json" file could not be downloaded: Failed to enable crypto
Failed to open stream: operation failed), package information was loaded from the local cache and may be out of date
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
<SNIP>

If you encounter another error related to a missing dependency, such as php-curl, you can quickly fix it by running, sudo apt install php-curl

 linuxlite  / | var | www  2  sudo apt install php-curl
[sudo] password for linuxlite: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  php8.1-curl
The following NEW packages will be installed:
  php-curl php8.1-curl
0 upgraded, 2 newly installed, 0 to remove and 420 not upgraded.
Need to get 40.6 kB of archives.
After this operation, 162 kB of additional disk space will be used.
Do you want to continue? [Y/n] y        # Type "Y" to continue.
Get:1 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 php8.1-curl amd64 8.1.2-1ubuntu2.13 [38.8 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 php-curl all 2:8.1+92ubuntu1 [1,834 B]
Fetched 40.6 kB in 4s (10.9 kB/s)
<SNIP>

After installing the missing dependency, retry the Composer command to install Laravel. I run into an issue, which indicates that I might need to remove previously generated project files before proceeding.

 linuxlite  / | var | www  1  ls -al
total 16
drwxr-xr-x  4 root root 4096 Aug 10 21:31 .
drwxr-xr-x 13 root root 4096 Aug 10 21:02 ..
drwxr-xr-x  3 root root 4096 Aug 10 21:23 html
drwxr-xr-x 11 root root 4096 Aug 10 21:31 myproject
 linuxlite  / | var | www  sudo rm -rf myproject/    # Firstly, remove the previously generated Project Directory
[sudo] password for linuxlite: 
 linuxlite  / | var | www  sudo composer create-project --prefer-dist laravel/laravel myproject
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Creating a "laravel/laravel" project at "./myproject"
Info from https://repo.packagist.org: #StandWithUkraine
Installing laravel/laravel (v10.2.5)
  - Installing laravel/laravel (v10.2.5): Extracting archive
Created project in /var/www/myproject
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 109 installs, 0 updates, 0 removals
.......
<SNIP>
.......
48 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   INFO  Discovering packages.  

  laravel/sail ............................................................................................................... DONE
  laravel/sanctum ............................................................................................................ DONE
  laravel/tinker ............................................................................................................. DONE
  nesbot/carbon .............................................................................................................. DONE
  nunomaduro/collision ....................................................................................................... DONE
  nunomaduro/termwind ........................................................................................................ DONE
  spatie/laravel-ignition .................................................................................................... DONE

82 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

> @php artisan key:generate --ansi

   INFO  Application key set successfully.  

 linuxlite  / | var | www  

Once Laravel is successfully installed, you'll be able to navigate within the project directory.

 linuxlite  / | var | www  ls -al
total 16
drwxr-xr-x  4 root root 4096 Aug 10 21:38 .
drwxr-xr-x 13 root root 4096 Aug 10 21:02 ..
drwxr-xr-x  3 root root 4096 Aug 10 21:23 html
drwxr-xr-x 12 root root 4096 Aug 10 21:38 myproject
 linuxlite  / | var | www  cd myproject/        # Change the directory to the Project directory
 linuxlite  / | var | www | myproject  ls -al    # List all hidden files and directories
total 384
drwxr-xr-x 12 root root   4096 Aug 10 21:38 .
drwxr-xr-x  4 root root   4096 Aug 10 21:38 ..
drwxr-xr-x  7 root root   4096 Jun 30 20:48 app
-rwxr-xr-x  1 root root   1686 Jun 30 20:48 artisan
drwxr-xr-x  3 root root   4096 Jun 30 20:48 bootstrap
-rw-r--r--  1 root root   1882 Jun 30 20:48 composer.json
-rw-r--r--  1 root root 293268 Aug 10 21:38 composer.lock
drwxr-xr-x  2 root root   4096 Jun 30 20:48 config
drwxr-xr-x  5 root root   4096 Jun 30 20:48 database
-rw-r--r--  1 root root    258 Jun 30 20:48 .editorconfig
-rw-r--r--  1 root root   1148 Aug 10 21:44 .env
-rw-r--r--  1 root root   1097 Jun 30 20:48 .env.example
-rw-r--r--  1 root root    186 Jun 30 20:48 .gitattributes
-rw-r--r--  1 root root    243 Jun 30 20:48 .gitignore
-rw-r--r--  1 root root    248 Jun 30 20:48 package.json
-rw-r--r--  1 root root   1084 Jun 30 20:48 phpunit.xml
drwxr-xr-x  2 root root   4096 Jun 30 20:48 public
-rw-r--r--  1 root root   4158 Jun 30 20:48 README.md
drwxr-xr-x  5 root root   4096 Jun 30 20:48 resources
drwxr-xr-x  2 root root   4096 Jun 30 20:48 routes
drwxr-xr-x  5 root root   4096 Jun 30 20:48 storage
drwxr-xr-x  4 root root   4096 Jun 30 20:48 tests
drwxr-xr-x 39 root root   4096 Aug 10 21:44 vendor
-rw-r--r--  1 root root    263 Jun 30 20:48 vite.config.js
 linuxlite  / | var | www | myproject

Depending on our system's settings, we may need to adjust file and directory permissions to ensure Laravel functions correctly. To achieve this, navigate to your project directory and execute the following command:

 linuxlite  / | var | www | myproject  sudo chown -R www-data:www-data .
 linuxlite  / | var | www | myproject  

This command ensures that the web server user, known as "www-data," gains control over the current directory and everything inside it. The "www-data" user is closely linked to the web server's operations, which enables it to interact with and manage files within the directory. This change of ownership guarantees that the web server possesses the essential permissions to read, write, and execute files present in the project directory.

You can verify this change by using the "ls -al" command, which will display the directory's contents along with their ownership and permissions.

 linuxlite  / | var | www | myproject  ls -al
total 384
drwxr-xr-x 12 www-data www-data   4096 Aug 10 21:38 .
drwxr-xr-x  4 root     root       4096 Aug 10 21:38 ..
drwxr-xr-x  7 www-data www-data   4096 Jun 30 20:48 app
-rwxr-xr-x  1 www-data www-data   1686 Jun 30 20:48 artisan
drwxr-xr-x  3 www-data www-data   4096 Jun 30 20:48 bootstrap
-rw-r--r--  1 www-data www-data   1882 Jun 30 20:48 composer.json
-rw-r--r--  1 www-data www-data 293268 Aug 10 21:38 composer.lock
drwxr-xr-x  2 www-data www-data   4096 Jun 30 20:48 config
drwxr-xr-x  5 www-data www-data   4096 Jun 30 20:48 database
-rw-r--r--  1 www-data www-data    258 Jun 30 20:48 .editorconfig
-rw-r--r--  1 www-data www-data   1148 Aug 10 21:44 .env
-rw-r--r--  1 www-data www-data   1097 Jun 30 20:48 .env.example
-rw-r--r--  1 www-data www-data    186 Jun 30 20:48 .gitattributes
-rw-r--r--  1 www-data www-data    243 Jun 30 20:48 .gitignore
-rw-r--r--  1 www-data www-data    248 Jun 30 20:48 package.json
-rw-r--r--  1 www-data www-data   1084 Jun 30 20:48 phpunit.xml
drwxr-xr-x  2 www-data www-data   4096 Jun 30 20:48 public
-rw-r--r--  1 www-data www-data   4158 Jun 30 20:48 README.md
drwxr-xr-x  5 www-data www-data   4096 Jun 30 20:48 resources
drwxr-xr-x  2 www-data www-data   4096 Jun 30 20:48 routes
drwxr-xr-x  5 www-data www-data   4096 Jun 30 20:48 storage
drwxr-xr-x  4 www-data www-data   4096 Jun 30 20:48 tests
drwxr-xr-x 39 www-data www-data   4096 Aug 10 21:44 vendor
-rw-r--r--  1 www-data www-data    263 Jun 30 20:48 vite.config.js
 linuxlite  / | var | www | myproject  

Next, run the following command:

 linuxlite  / | var | www | myproject  sudo chmod -R 755 storage/
 linuxlite  / | var | www | myproject  

Similarly, the following command adjusts the permissions of the "/storage" directory and its contents. The "chmod" command is responsible for altering file permissions. The permission code "755" grants the file owner the ability to read, write, and execute files. However, other users (group and others) are restricted to reading and executing files only. The "/storage" directory typically stores cached files, session data, and other temporary information used by the application. This permission setup allows the webserver to both read and write data in this directory while maintaining a secure environment.

Again, you can verify this change by using the "ls -al" command to observe the updated permissions and ownership.

 linuxlite  / | var | www | myproject  ls -al storage/
total 20
drwxr-xr-x  5 www-data www-data 4096 Jun 30 20:48 .
drwxr-xr-x 12 www-data www-data 4096 Aug 10 21:38 ..
drwxr-xr-x  3 www-data www-data 4096 Jun 30 20:48 app
drwxr-xr-x  6 www-data www-data 4096 Jun 30 20:48 framework
drwxr-xr-x  2 www-data www-data 4096 Jun 30 20:48 logs
 linuxlite  / | var | www | myproject  

As Apache2 has a default page, we need to configure a VirtualHost for our Laravel project. Start by creating a new virtual host configuration file.

 linuxlite  / | var | www | myproject  sudo nano /etc/apache2/sites-available/laravel.conf

Drop in a few lines at the end, telling Apache where your project will reside. 

<VirtualHost *:80>
    ServerName <Your-project>.local
    DocumentRoot /var/www/<project-name>/public

    <Directory /var/www/<project-name>/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Replace the red mark and Save it using CTRL + X.

Now, enable the virtual host configuration and reload Apache. 

 linuxlite  / | var | www | myproject  sudo a2ensite laravel.conf 
Enabling site laravel.
To activate the new configuration, you need to run:
  systemctl reload apache2
 linuxlite  / | var | www | myproject  sudo systemctl reload apache2
 linuxlite  / | var | www | myproject  

Let me visit the URL address. 

http://<Your-given-name>.local

But, once we encounter an issue accessing the URL in your web browser. We can fix this by disabling the default Apache configuration, and restarting the Apache web server to apply the changes.

 linuxlite  / | var | www | myproject  sudo a2dissite 000-default.conf
Site 000-default disabled.
To activate the new configuration, you need to run:
  systemctl reload apache2
 linuxlite  / | var | www | myproject  sudo service apache2 restart
 linuxlite  / | var | www | myproject  

 Still, it needs to be fixed.

So, we have to add the chosen domain, in this case, myproject.local, to /etc/hosts file. 

 linuxlite  / | var | www | myproject  sudo nano /etc/hosts

After making these adjustments, we can now access the Laravel project by navigating to the URL again in the web browser.

Now that we have successfully set up the Laravel web framework on both Windows and Linux, let's take a closer look at the essential files that play a crucial role within the framework. 


Essential Files within Framework

These key files hold significant importance as they define the structure and behavior of your Laravel applications.

let's break down the files and directories in the Laravel project:

  • app: This directory contains the core application code, including Controllers, Models, Services, and more, defining the business logic and functionality.
  • artisan: This file is the command-line tool for Laravel, used to perform various tasks like running migrations, generating code, and more.
  • bootstrap: This directory contains files responsible for bootstrapping and initializing the Laravel application.
  • composer.json: This file defines your project's dependencies and settings required by Composer, a PHP package manager.
  • composer.lock: This file is generated by Composer and contains the exact versions of installed packages, ensuring consistency across different environments.
  • config: This directory holds configuration files that define settings for different aspects of your application.
  • database: This directory contains files related to database management, including migrations, seeders, and factory definitions.
  • public: The web server's document root, containing the entry point (index.php) and assets like CSS, JavaScript, and images.
  • README.md: A text file providing essential information about the project and its usage.
  • resources: This directory stores assets like views, styles, and language files used by your application.
  • routes: Contains route definition files that determine how your application responds to HTTP requests.
  • storage: Holds temporary files, logs, cache, and other data used by the application.
  • tests: Contains automated tests for your application.
  • vendor: This directory contains the packages and libraries installed by Composer.
  • .env: A configuration file containing environment-specific settings like database connection details and application secrets.
  • .env.example: A template for the .env file, showing the expected variables without sensitive data.
  • .gitignore: A file specifying which files and directories should be ignored by version control (Git).
  • package.json: Used to manage JavaScript dependencies for your application.
  • phpunit.xml: Configuration file for PHPUnit, a unit testing framework for PHP.
  •  vite.config.js: Configuration file for Vite, a build tool for modern web projects.

Each of these files and directories serves a specific purpose in organizing and controlling different aspects of your Laravel project. Understanding their roles is crucial for effective development and troubleshooting.

By understanding the roles and functionalities of these files, we gain valuable insights that can aid in exploring and potentially exploiting vulnerable web applications built on the Laravel framework. Gaining familiarity with these files is pivotal for identifying potential security vulnerabilities and weaknesses present in such applications.


/public

Laravel organizes its structure in a way that the homepage or primary website content is stored within the "/public" directory. 

This directory serves as the document root for the web server. It houses essential files like "index.php," along with assets such as CSS, JavaScript, and images.

  • index.php: This is the entry point of your Laravel application. It receives all incoming HTTP requests and routes them to the appropriate parts of your application.
  • .htaccess: This file contains Apache server configuration rules that control how URLs are rewritten and managed within your application. It's used to enable "pretty" URLs.
  • web.config: This file is used when hosting Laravel applications on Windows-based servers running IIS (Internet Information Services). It serves a similar purpose as the .htaccess file for Apache.
  • favicon.ico: The website's icon is displayed in the browser tab and bookmarks.
  • robots.txt: A text file used to provide instructions to search engine bots on which pages or sections of your site should not be crawled or indexed.
  • css: This directory contains cascading style sheets (CSS) files used to style the web pages of your application.
  • js: Contains JavaScript files that provide client-side interactivity and functionality for your application.
  • img: This directory stores image files used on your website.


/composer.json

One of the most crucial files within a Laravel project is "/composer.json." 

This file plays a vital role as it outlines the project's dependencies and other settings that Composer requires to function effectively.


"/app" Directory

However, the heart of the Laravel application resides within the "/app" directory. 

Here, you'll find core application components like Controllers, Models, and Services. These components define the essential business logic and functionality that empower your application.

  • /app/Http: This directory contains files related to handling HTTP requests and responses, including routes, controllers, middleware, and form requests.
  • /app/Providers: Contains service provider classes that define the application's various services and bindings.
  • /app/Console: This directory houses command-line commands, extending the Laravel Artisan command-line tool's functionality.
  • /app/Exceptions: Contains exception classes that handle different types of exceptions that can occur during application execution.
  • /app/Models: This directory holds the Eloquent model classes, representing database tables and allowing interaction with data.

The console directory in a Laravel project does not typically contain any files or directories by default. 

In older versions of Laravel (prior to Laravel 5), the “/console” directory is used to house the commands for the Laravel Artisan command-line tool

Artisan commands are used to perform various tasks related to your Laravel application, such as database migrations, creating controllers, generating models, and more.

 

/app/Exception

In the "/Exception" directory, Laravel keeps exception classes that handle different types of errors that might arise during your application's execution. 


These exceptions offer a more organized and controlled way of managing errors and unexpected situations.


/app/Http

Meanwhile, the "/app/Http" directory plays a pivotal role in handling HTTP requests and responses. It's central to defining routes, controllers, middleware, and other elements that shape your web application.

  • Controllers: The Controllers directory contains your application's controller classes. Controllers handle the logic for processing incoming HTTP requests and generating responses. They are responsible for fetching data, performing actions, and returning appropriate views or JSON responses. Controllers help you keep your application's logic organized and maintainable.
  • Middleware: The Middleware directory contains middleware classes that allow you to perform actions before or after an HTTP request is handled by a controller. Middleware can be used for tasks such as authentication, authorization, logging, and modifying request or response data. Middleware provides a way to inject additional functionality into the request/response lifecycle.
  • Requests: The Requests directory holds request classes that handle input validation and data processing for incoming requests. These classes define rules and validation logic to ensure that the data sent to your application is valid and secure. Laravel's request classes help you handle user input effectively and securely.
  • Resources/views: This directory is where you store your Blade templates, which are used to generate HTML output for your views. The blade is Laravel's templating engine that allows you to create dynamic and reusable views. Blade templates can contain PHP code, directives, and control structures that make it easy to build complex UI elements.
  • Routes: The Routes directory contains the web.php and api.php files. These files define the routes for your application. In the web.php file, you define routes that handle web requests and are typically associated with user interfaces. In the api.php file, you define routes for API endpoints that return data to external clients.
  • Kernel.php: The Kernel.php file is responsible for managing and defining your application's middleware stack. Middleware can be grouped and applied globally or to specific routes. The Kernel class also manages other application-level tasks, such as scheduling commands and performing background tasks.
  • HttpServiceProvider.php: This service provider is responsible for registering various services related to HTTP handling. It's used to bootstrap and configure the HTTP-related components of your application.


/bootstrap

The "/bootstrap" directory contains essential files and scripts responsible for initializing and bootstrapping the Laravel application. 

This step ensures the proper configuration and environment setup before the application starts running.


/config

The config directory in a Laravel project contains configuration files that define various settings and options for different aspects of your application. 

These files play a critical role in customizing and fine-tuning the behavior of your Laravel application. 

  • app.php: The app.php configuration file is a central place for defining application-level settings. It includes options like the application name, environment, timezone, locale, and more. You can also specify which service providers and aliases are loaded for your application.
  • auth.php: The auth.php configuration file is used to configure authentication and authorization settings for your application. You can define authentication guards, user providers, and password reset options. This file allows you to tailor your authentication system to match your application's needs.
  • broadcasting.php: The broadcasting.php configuration file defines settings related to broadcasting events to various broadcasting services. Laravel supports broadcasting events using various drivers, such as Pusher, Redis, and more. This file lets you configure broadcasting options and connection details.
  • cache.php: The cache.php configuration file contains settings for the caching system in your application. You can specify default cache drivers, cache stores, and related options. Caching helps improve performance by storing frequently used data in fast-access storage.
  • database.php: The database.php configuration file is used to configure database connections and related settings. You can define connections for different database engines (e.g., MySQL, PostgreSQL), set up connection parameters, and configure query logging and other database-related options.
  • filesystems.php: The filesystems.php configuration file allows you to configure different disk drivers for file storage. You can define disks for local storage, cloud storage (e.g., Amazon S3), and more. This file specifies how your application interacts with various file storage systems.
  • logging.php: The logging.php configuration file defines settings for the logging system in your application. You can configure log channels, log levels, and other logging-related options. Laravel provides support for logging to different destinations, such as files, databases, and third-party services.
  • mail.php: The mail.php configuration file is used to configure email-sending settings for your application. You can define mail drivers, SMTP configurations, and related options. This file helps you set up email delivery for various email services.
  • queue.php: The queue.php configuration file allows you to configure queue connections and related settings. Laravel supports queueing tasks for later processing, and this file defines queue drivers, connection parameters, and queue-related options.
  • services.php: The services.php configuration file is used to configure third-party services and their integration with your application. You can specify settings for services like Facebook, Twitter, Google, and more.

It is important to remember that the config file is now a separate directory on the Latest version. But previously, it is found in the app directory on old versions.


/config/database.php

An influential file within this directory is "database.php." 

The database.php configuration file is used to configure database connections and related settings. You can define connections for different database engines, (that are, MySQL, PostgreSQL), set up connection parameters, and configure query logging and other database-related options.


/database

The "database" directory serves as a repository for managing databases. 

It houses migration files, seeders, and factory definitions, facilitating proper database management within your Laravel project.

  • migrations: The migrations directory contains database migration files. Migrations are used to manage changes to the database schema over time. Each migration file defines a set of changes, such as creating or modifying tables, indexes, and columns. Migrations help keep your database schema in sync with your codebase.
  • seeders: The seeders directory contains seeder files. Seeders allow you to populate your database with sample or default data. Seeders are useful for setting up consistent test data or populating initial data when deploying a new application.
  • factories: The factories directory is used to define factory files that generate fake data for your application's models. Factories are used in combination with seeders to create test data for your application. They provide an easy way to generate data for testing and development purposes.
  • DatabaseServiceProvider.php: The DatabaseServiceProvider.php file is a service provider that registers database-related services and features. It's responsible for bootstrapping the database-related components of your application.

While there are additional directories and files in a Laravel project, not all of them are essential to know. Understanding each one in detail isn't crucial. I hope, you now have a foundational understanding of the key components that we've covered in this article. 

If you have any questions related to the content, feel free to ask in the comments section below the video.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!