How to Install Laravel 11 on Ubuntu 24.04 (Beginner-Friendly Guide)
Installing Laravel on Ubuntu is one of the first steps when starting modern PHP web development. Laravel is an open-source framework built on the MVC (Model-View-Controller) architecture and powered by Symfony. It helps developers build clean, secure, and scalable web applications with less effort.
This time, Linux Simplify will guide you through the process of installing Laravel 11 on Ubuntu 24.04 using a clear and structured approach. This guide is written for beginners, so each step is explained in a simple and practical way. By the end of this tutorial, Laravel will be fully installed and ready for development.
Read More: How to Install Python on Ubuntu (Step-by-Step Guide)
Prepare Ubuntu 24.04 Before Installing Laravel
Before installing Laravel, your Ubuntu system must be properly prepared. This step ensures that all required packages and dependencies are available, preventing errors during installation.
Update System Packages
Start by updating the package list to make sure your system is using the latest available packages:
sudo apt update
Install PHP and Required Extensions
Laravel 11 requires PHP 8.3 or newer. Ubuntu 24.04 already includes PHP 8.3 by default, so you can install PHP along with the extensions needed by Laravel:
sudo apt install php php-curl php-bcmath php-json php-mysql php-mbstring php-xml php-tokenizer php-zip git -y
After installation, verify the PHP version:
php -v
If you see PHP 8.3.x or higher, PHP is correctly installed.
Install Composer
Composer is a dependency manager for PHP and is required to install Laravel. Install Composer globally using the following command:
sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
Check that Composer is installed correctly:
composer -v
Optional: Firewall and Database Setup
If your server uses UFW firewall and you plan to access Laravel through a browser, allow HTTP traffic:
sudo ufw allow 80/tcp
sudo ufw reload
Most Laravel applications require a database. If you plan to use MySQL, install it with:
sudo apt install mysql-server -y
At this point, Ubuntu 24.04 is ready for Laravel installation.
How to Install Laravel 11 on Ubuntu 24.04
Once the system is prepared, you can begin installing Laravel.
Create a New Laravel Project
Move to the directory where your web projects are stored. A common location is /var/www:
cd /var/www
Create a new Laravel 11 project using Composer:
composer create-project --prefer-dist laravel/laravel laravel-app "11.*"
This command downloads Laravel and creates a new directory named laravel-app containing all required files.
Set Proper File Permissions
Enter the project directory and set the correct ownership so Laravel can write cache and log files:
cd laravel-app
sudo chown -R www-data:www-data storage bootstrap/cache
Configure the Environment File
Copy the example environment file:
cp .env.example .env
Generate the application key required by Laravel:
php artisan key:generate
Open the .env file and configure your database connection:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
Laravel 11 is now installed on Ubuntu 24.04.
Create and Configure the Laravel Project
In some server environments, especially VPS or production servers, you may want a cleaner directory structure.
Create Required Directories
Create the necessary directories under /var/www:
sudo mkdir -p /var/www/{.cache,.config,laravelapp}
Set proper ownership for these directories:
sudo chown -R www-data:www-data /var/www/{.cache,.config,laravelapp}
Navigate to the Laravel project directory and create the project as the web server user:
cd /var/www/laravelapp/
sudo -u www-data composer create-project laravel/laravel .
Configure Laravel Environment
Edit the .env file:
sudo nano .env
Update the application URL and database settings:
APP_URL=http://your-domain.com
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password
Generate the application key if it does not exist:
php artisan key:generate
Run database migrations to create the default tables:
sudo -u www-data php artisan migrate
Your Laravel 11 project is now fully configured and ready to use.
Conclusion
In this guide, Linux Simplify walked you through the complete process of installing Laravel 11 on Ubuntu 24.04. Starting from system preparation, PHP and Composer installation, to creating and configuring a Laravel project, every step was explained clearly and practically.
With Laravel successfully installed, you can now focus on building your application instead of dealing with setup issues. Laravel’s clean structure and powerful features make it an excellent choice for modern web development.
The installation process may feel long at first, but it only needs to be done once. After that, developing with Laravel becomes much more enjoyable and efficient.
Hopefully, this guide helps you get started with Laravel on Ubuntu 24.04. Happy coding and enjoy building with Laravel.




Post a Comment for "How to Install Laravel 11 on Ubuntu 24.04 (Beginner-Friendly Guide)"
Post a Comment