How to Install Laravel 12 All OS

How to Install Laravel 12 All OS

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:

php -v

If PHP is not installed or is outdated, follow the instructions below to install it.

Windows Users:

  1. Download PHP from windows.php.net.
  2. Extract it and add it to your system environment variables.
  3. Install XAMPP or WAMP if you prefer an all-in-one solution.

Mac Users:

Install PHP using Homebrew:

brew install php

Linux (Ubuntu/Debian) Users:

Run the following commands:

sudo apt update sudo apt install php-cli php-mbstring php-xml php-bcmath php-curl php-zip unzip

Verify installation:

php -v

Step 2: Install Composer

Composer is a PHP dependency manager used to install Laravel.

Install Composer on Windows:

  1. Download Composer Setup from getcomposer.org.
  2. Run the installer and follow the instructions.

Install Composer on macOS/Linux:

Run this command in the terminal:

curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer

Verify installation:

composer --version

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:

composer global require laravel/installer

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:

    export PATH="$HOME/.composer/vendor/bin:$PATH"

After this, create a new Laravel project:

laravel new project-name

Method 2: Using Composer Directly

If you don’t want to install the Laravel installer, you can use Composer directly:

composer create-project --prefer-dist laravel/laravel project-name

Replace project-name with your desired project folder name.

Step 4: Set Up Your Laravel Project

Navigate into your Laravel project directory:

cd project-name

Generate an application key:

php artisan key:generate

Step 5: Run the Laravel Development Server

To start the built-in Laravel server, run:

php artisan serve

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:

DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_database_user DB_PASSWORD=your_database_password

Apply the changes:

php artisan config:clear php artisan migrate

Step 7: Set Up Permissions

Ensure the storage and bootstrap/cache directories are writable:

chmod -R 775 storage bootstrap/cache

For servers, use:

chown -R www-data:www-data storage bootstrap/cache

Step 8: Using a Web Server (Optional)

If you want to use Apache or Nginx, configure your virtual host:

Apache Configuration (Virtual Host)

<VirtualHost *:80> ServerName yourdomain.com DocumentRoot "/path/to/your/project/public" <Directory "/path/to/your/project/public"> AllowOverride All Require all granted </Directory> </VirtualHost>

Enable mod_rewrite and restart Apache:

sudo a2enmod rewrite sudo systemctl restart apache2

Nginx Configuration

server { listen 80; server_name yourdomain.com; root /path/to/your/project/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; } }

Restart Nginx:

sudo systemctl 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:

php artisan serve --port=8080

3. Database connection issues

Ensure MySQL is running and your .env file has the correct credentials.

4. Permission errors

Run:

chmod -R 775 storage bootstrap/cache

For Linux/macOS servers, run:

sudo chown -R www-data:www-data storage bootstrap/cache

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!

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close