This guide will walk you through setting up a Laravel project from scratch. Let’s dive in!
1️⃣ Install Laravel
To start, we need to create a new Laravel project. Go to the directory where you want to create your Laravel project. Use the following command to create a project with a project name for example laravel-app
:
composer create-project laravel/laravel laravel-app
This will generate the necessary project structure and files for Laravel.
2️⃣ Configure the .env
File
Laravel uses the .env
file to manage environment-specific configurations. Update the database credentials in the .env file as per your setup.
Example configuration:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_laravel_app
DB_USERNAME=root
DB_PASSWORD=yourpassword
📝 Note: Ensure that your database db_laravel_app
exists before proceeding.
3️⃣ Run Migrations
Laravel provides built-in migrations to handle database schema. To create the default tables (users, migrations, etc.), run:
php artisan migrate
This will apply the default migration files and set up your database tables.
The tables below will create
4️⃣ Start the Development Server
Finally, start Laravel's built-in development server to test your setup:
php artisan serve
Once started, visit http://127.0.0.1:8000 in your browser to see your Laravel application in action!
☠️ Facing SQLSTATE[42000] During Migrations? Here's the Fix!
Encountered the SQLSTATE[42000] error while running Laravel migrations? You're not alone! This common issue, caused by key length limitations in MySQL, can be frustrating. Check out my detailed blog where I explain the root cause of this error and walk you through step-by-step solutions to resolve it efficiently. Don't let this error slow you down—get back to building your Laravel application!
Conclusion
With this setup, you’re ready to start building features into your Laravel project. This step-by-step process provides the foundation for developing a robust and scalable application.
Happy coding! 🚀
Have questions or tips to share about Laravel setup? Drop them in the comments below!
Top comments (0)