How to Install Laravel 12
Laravel is one of the most popular PHP frameworks, known for its elegant syntax, powerful features, and developer-friendly tools. With Laravel 12, new improvements in performance, security, and modern development practices have been introduced.
In this guide, we’ll walk you through the complete process of installing Laravel 12 on your local system, from setting up PHP and Composer to running your first Laravel project.
System Requirements
Before installing Laravel 12, ensure your system meets the following requirements:
- PHP 8.2 or higher
- Composer (PHP dependency manager)
- Database (MySQL, PostgreSQL, SQLite, or SQL Server)
- Web Server (Apache, Nginx, or Laravel’s built-in server)
Step 1: Install PHP and Required Extensions
Laravel 12 requires PHP 8.2 or higher. Check your PHP version with:
If PHP is not installed or is outdated, follow the instructions below to install it.
Windows Users:
- Download PHP from windows.php.net.
- Extract it and add it to your system environment variables.
- Install XAMPP or WAMP if you prefer an all-in-one solution.
Mac Users:
Install PHP using Homebrew:
Linux (Ubuntu/Debian) Users:
Run the following commands:
Verify installation:
Step 2: Install Composer
Composer is a PHP dependency manager used to install Laravel.
Install Composer on Windows:
- Download Composer Setup from getcomposer.org.
- Run the installer and follow the instructions.
Install Composer on macOS/Linux:
Run this command in the terminal:
Verify installation:
Step 3: Install Laravel 12
Now, you have two methods to install Laravel 12:
Method 1: Using Laravel Installer (Recommended)
First, install the Laravel installer globally:
Make sure your system’s PATH includes Composer’s global vendor bin directory.
Windows: Add
C:\Users\YourUser\AppData\Roaming\Composer\vendor\bin
to system variables.macOS/Linux: Add this to your
~/.bashrc
or~/.zshrc
:
After this, create a new Laravel project:
Method 2: Using Composer Directly
If you don’t want to install the Laravel installer, you can use Composer directly:
Replace project-name
with your desired project folder name.
Step 4: Set Up Your Laravel Project
Navigate into your Laravel project directory:
Generate an application key:
Step 5: Run the Laravel Development Server
To start the built-in Laravel server, run:
By default, Laravel runs on http://127.0.0.1:8000. Open this URL in your browser to see the Laravel welcome page.
Step 6: Configure Your Environment
Laravel stores settings in a .env
file. Open it and configure your database connection:
Apply the changes:
Step 7: Set Up Permissions
Ensure the storage
and bootstrap/cache
directories are writable:
For servers, use:
Step 8: Using a Web Server (Optional)
If you want to use Apache or Nginx, configure your virtual host:
Apache Configuration (Virtual Host)
Enable mod_rewrite and restart Apache:
Nginx Configuration
Restart Nginx:
Troubleshooting Common Issues
1. Laravel command not found
If running laravel new project-name
gives a "command not found" error, add Composer's global bin directory to your PATH.
2. php artisan serve
port conflict
If port 8000 is already in use, run Laravel on a different port:
3. Database connection issues
Ensure MySQL is running and your .env
file has the correct credentials.
4. Permission errors
Run:
For Linux/macOS servers, run:
Conclusion
Congratulations! 🎉 You have successfully installed Laravel 12. Now, you can start developing your web application using Laravel’s powerful features.
If you found this guide helpful, share it with other developers! 🚀 Happy coding!