How to Install Laravel on Ubuntu
Laravel is one of the most popular PHP frameworks for building web applications. If you’re using Ubuntu, this guide will help you install and set up Laravel on your system.
✅ What You’ll Learn:
✔️ Install PHP, Composer, and Laravel
✔️ Set up a web server (Apache or Nginx)
✔️ Configure Laravel and database
✔️ Run Laravel on Ubuntu
Step 1: Update Your System
Before installing Laravel, update your system packages:
Step 2: Install PHP and Required Extensions
Laravel requires PHP 8.1+. Install PHP and the necessary extensions:
Verify the PHP installation:
Step 3: Install Composer
Laravel uses Composer to manage dependencies. Install Composer with:
Check if Composer is installed:
Step 4: Install MySQL and Configure the Database
If you haven't installed MySQL, install it with:
Secure your MySQL installation:
Log in to MySQL and create a database for Laravel:
Run the following SQL commands:
Step 5: Install Laravel
Navigate to your web directory:
Use Composer to install Laravel:
Set proper ownership and permissions:
Step 6: Configure Apache or Nginx for Laravel
For Apache:
Enable required modules:
Create a new virtual host file:
Paste the following configuration:
Enable the site and restart Apache:
For Nginx:
Create a new configuration file:
Paste the following configuration:
Save and enable the site:
Step 7: Configure Laravel Environment
Navigate to your Laravel project directory:
Edit the .env
file to update database credentials:
Modify these lines:
Run database migrations:
Step 8: Run Laravel
Start the Laravel development server:
Now, open your browser and visit:
Step 9: Optimize Laravel Performance
Run these optimization commands:
Set correct permissions:
Conclusion
🎉 Congratulations! You have successfully installed Laravel on Ubuntu. Now, you can start building amazing web applications! 🚀
💬 Have any questions? Let us know in the comments!