Laravel is one of the most popular PHP frameworks used for building modern web applications. If you're just getting started, this guide will walk you through setting up a Laravel project from scratch, explain its folder structure, configure the .env file, and connect your project to a database using phpMyAdmin. Weโll use XAMPP on Ubuntu as the local server environment.
โ Step 1: Install Laravel on Ubuntu
First, make sure your system is ready with the required tools:
๐ฆ 1. Install PHP and Composer
sudo apt update
sudo apt install php php-cli php-mbstring unzip curl php-xml composer
๐ฆ 2. Install Laravel Installer (Optional)
composer global require laravel/installer
Make sure the global composer vendor/bin directory is in your PATH. You can add this to your ~/.bashrc or ~/.zshrc:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
โ Step 2: Create a New Laravel Project
There are two ways to create a Laravel project:
๐น Using the Laravel Installer:
laravel new myproject
๐น Using Composer (if you didnโt install the Laravel installer):
composer create-project laravel/laravel myproject
This will create a new directory called myproject with all Laravel files.
โ Step 3: Understand Laravel Project Structure
Hereโs a quick overview of the main folders:
app/ โ Contains your application logic, models, and controllers.
bootstrap/ โ Starts the Laravel framework.
config/ โ Holds configuration files.
database/ โ Migrations, seeders, and database-related stuff.
public/ โ The entry point for the app (index.php). Place your frontend assets here.
resources/ โ Views, assets (CSS, JS), and localization files.
routes/ โ All route definitions (web.php, api.php, etc).
storage/ โ Log files, compiled views, and file uploads.
tests/ โ Automated test files.
.env โ Environment configuration file (we'll talk about this next).
โ Step 4: Configure .env File
The .env file stores environment-specific settings. Open .env inside your project folder and update the following lines for database configuration:
APP_NAME=Laravel
APP_URL=http://localhost/myproject/public
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=
Note: The DB_PASSWORD is empty by default for XAMPP.
โ Step 5: Set Up XAMPP and phpMyAdmin on Ubuntu
๐ฅ Install XAMPP:
Go to https://www.apachefriends.org/index.html and download the Linux installer.
Run these commands:
cd ~/Downloads
chmod +x xampp-linux-x64-*.run
sudo ./xampp-linux-x64-*.run
๐ Start XAMPP:
sudo /opt/lampp/lampp start
Access phpMyAdmin at:
http://localhost/phpmyadmin
๐งฑ Create a Database
Visit phpMyAdmin.
Click New.
Create a database named laravel_db (or anything you used in .env).
โ Step 6: Serve Your Laravel Project
Inside your project folder, run:
php artisan serve
Youโll see something like:
Starting Laravel development server: http://127.0.0.1:8000
If you want to use XAMPPโs Apache instead, move the Laravel project to /opt/lampp/htdocs:
sudo mv ~/myproject /opt/lampp/htdocs/
Then access it via:
http://localhost/myproject/public
โ Bonus Tips
๐ Permissions
If you face permission errors on storage/ or bootstrap/cache/, fix it with:
sudo chmod -R 775 storage bootstrap/cache
๐ You're Ready to Build with Laravel!
You now have a fully working Laravel environment on Ubuntu using XAMPP and phpMyAdmin. From here, you can start creating routes, controllers, models, and build your dream web application.
Leave a Reply