How to Set Up Laravel on Ubuntu
Laravel is a powerful PHP framework that simplifies web development. If you’re using Ubuntu, this guide will walk you through installing and setting up Laravel on your server.
✅ What You’ll Learn:
✔️ Install PHP, Composer, and Laravel
✔️ Set up a web server (Nginx or Apache)
✔️ Configure Laravel permissions and database
✔️ Run Laravel on Ubuntu
Step 1: Update Your System
Before installing anything, ensure your system is up to date:
Step 2: Install PHP and Required Extensions
Laravel requires PHP 8.1+. Install PHP and necessary extensions:
Verify PHP version:
Step 3: Install Composer (PHP Dependency Manager)
Laravel uses Composer to manage dependencies. Install it using:
Check the version:
Step 4: Install MySQL and Configure Database
If you haven’t installed MySQL yet, do so with:
Secure MySQL installation:
Then, log in and create a Laravel database:
Inside MySQL:
Step 5: Install Laravel
To install a new Laravel project, navigate to your web directory:
Set proper ownership:
Step 6: Configure Apache or Nginx for Laravel
For Apache:
Enable required modules:
Create a new Laravel virtual host:
Paste the following configuration:
Save and enable the site:
For Nginx:
Create a new Nginx configuration:
Paste the following:
Save the file and enable the site:
Step 7: Configure .env File
Go to your Laravel project folder:
Edit the .env
file to update the database credentials:
Modify these lines:
Run the migration:
Step 8: Run Laravel
Start the Laravel development server:
Now, open your browser and visit:
If you’re using a domain, it should work as well.
Step 9: Setup Permissions & Optimize Laravel
Make sure the necessary folders have the correct permissions:
Run Laravel optimization commands:
Conclusion
🎉 Congratulations! You’ve successfully installed Laravel on Ubuntu. Now, you can start building amazing web applications! 🚀
💬 Have questions or issues? Drop a comment below!