Laravel Pre-Development Configuration

Laravel Pre-Development Configuration

Before you start coding, properly setting up your Laravel 12 development environment is crucial. This guide covers every essential step, with clear explanations and commands, to get your Laravel project ready for development.

1. Install Prerequisites

What you need:

  • PHP 8.2 or later (Laravel 12 requires PHP 8.2 minimum)

  • Composer (dependency manager for PHP)

  • Database Server (MySQL, PostgreSQL, SQLite, or SQL Server — most common is MySQL/MariaDB)

  • Node.js & npm (for compiling CSS/JS assets with Vite)

Verify installations

Run the following commands in your terminal:

php -v # Check PHP version (>= 8.2 required) composer --version mysql --version node -v npm -v

👉 If something is missing, install from the official sites:

2. Create a New Laravel 12 Project

Option 1: Using Composer

composer create-project laravel/laravel myproject

Option 2: Using Laravel Installer

If you have the Laravel installer installed globally:

laravel new myproject

Navigate into the project folder:

cd myproject

3. Configure Environment Variables (.env file)

Laravel uses a .env file for environment-specific configuration.

Copy the example file:

cp .env.example .env

Update the .env file:

APP_NAME=MyProject APP_ENV=local APP_KEY= # Will be generated later APP_DEBUG=true APP_URL=http://localhost DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=myproject_db DB_USERNAME=root DB_PASSWORD=your_db_password

📌 Notes:

  • APP_DEBUG=true enables detailed error messages (development only).

  • Ensure your database settings match your local configuration.

4. Generate Application Key

Run the following command to generate an application key:

php artisan key:generate

This updates the APP_KEY in your .env file automatically.

5. Create a Database

Example (MySQL):

CREATE DATABASE myproject_db;

Make sure the name matches the DB_DATABASE in your .env file.

6. Run Database Migrations

Run Laravel’s default migrations:

php artisan migrate

This will create essential tables like users, password_resets, and more.

7. Set File Permissions (Linux/macOS Only)

Laravel requires write access to certain folders:

chmod -R 775 storage bootstrap/cache

If your web server user is different:

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

(Windows users usually don’t need this step.)

8. Create a Storage Symlink

To make uploaded files accessible via the browser:

php artisan storage:link

This links public/storagestorage/app/public.

9. Install Node Modules & Compile Assets

Install Node.js dependencies:

npm install

Compile assets for development:

npm run dev

Compile for production (optimized and minified):

npm run build

📌 Laravel 12 uses Vite (instead of Laravel Mix).

10. Run Laravel Development Server

Start the server:

php artisan serve

Now open your browser and visit:

http://localhost:8000

👉 You should see Laravel’s default welcome page 🎉

✅ Conclusion

You’ve now completed the pre-development setup for Laravel 12. Your environment is ready, your database is connected, and your project is fully configured. From here, you can begin building your Laravel 12 application with confidence. 🚀

Souy Soeng

Souy Soeng

Hi there 👋, I’m Soeng Souy (StarCode Kh)
-------------------------------------------
🌱 I’m currently creating a sample Laravel and React Vue Livewire
👯 I’m looking to collaborate on open-source PHP & JavaScript projects
💬 Ask me about Laravel, MySQL, or Flutter
⚡ Fun fact: I love turning ☕️ into code!

Post a Comment

CAN FEEDBACK
close