How to Install Laravel on CentOS 8
Laravel is a powerful PHP framework used for web development. If you're using CentOS 8, this guide will help you install and set up Laravel step by step.
✅ What You’ll Learn:
✔️ Install PHP, Composer, and Laravel
✔️ Set up a web server (Apache or Nginx)
✔️ Configure Laravel and database
✔️ Run Laravel on CentOS 8
Step 1: Update Your System
Before installing Laravel, update your system:
Step 2: Install PHP and Required Extensions
Laravel requires PHP 8.1+. Enable the Remi repository and install PHP:
Verify the PHP installation:
Step 3: Install Composer
Laravel uses Composer for dependency management. Install it using:
Check if Composer is installed:
Step 4: Install MySQL and Configure the Database
If MySQL is not installed, install it using:
Start and enable MySQL:
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:
Restart Apache:
For Nginx:
Install Nginx and PHP-FPM:
Create a new Nginx configuration:
Paste the following configuration:
Restart Nginx:
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 CentOS 8. Now, you can start building amazing web applications! 🚀
💬 Have any questions? Let us know in the comments!