Introduction
Laravel is one of the most popular PHP frameworks, known for its elegance, simplicity, and ability to handle complex applications with ease. If you’re new to Laravel and want to get your first project up and running, this guide is for you. We’ll walk you through each step, ensuring you have a solid foundation to build on.
If you’re not familiar with Laravel yet, consider reading our introduction to Laravel before diving into this setup guide.
Prerequisites
Before setting up your Laravel project, make sure you have the following installed on your machine:
- PHP (version 7.3 or higher)
- Composer (Dependency Manager for PHP)
- A web server like Apache or Nginx (though Laravel’s built-in server is sufficient for development)
For more details on the prerequisites, check out our preparation guide for Laravel development.
Step 1: Install Composer
Composer is a dependency manager for PHP that you’ll use to install Laravel and manage its dependencies. If you don’t have Composer installed, download it from getcomposer.org and follow the installation instructions.
Step 2: Install Laravel
With Composer installed, you can now install Laravel. Open your terminal and run the following command:
composer global require laravel/installer
This command installs the Laravel installer globally, making it accessible from anywhere on your system.
Step 3: Create a New Laravel Project
Now that Laravel is installed, it’s time to create your first project. In the terminal, navigate to the directory where you want your new project to reside. Then, run:
laravel new my-first-laravel-app
This command will create a new Laravel project in a directory named my-first-laravel-app
. It will also install all the necessary dependencies.
Step 4: Configuring Environment Settings
Laravel comes with an .env
file where you can configure environment-specific settings like database connections and application keys. To start, simply copy the .env.example
file provided and rename it to .env
:
cp .env.example .env
Next, generate an application key:
php artisan key:generate
This command sets the APP_KEY
in your .env
file, which is crucial for securing your application.
For more detailed information about environment settings, you can refer to our guide on configuring Laravel environments.
Step 5: Serve Your Laravel Application
With everything set up, you can now serve your Laravel application. In your project directory, run:
php artisan serve
This command will start a development server, and you can access your application by visiting http://localhost:8000
in your web browser.
You should see the default Laravel welcome page, confirming that your setup is successful!
Next Steps
Now that you’ve successfully set up your first Laravel project, you’re ready to start building! In our upcoming posts, we’ll cover topics like routing in Laravel, creating controllers, and using Blade templates to help you get the most out of this powerful framework.
If you want to dive deeper right away, check out our Laravel directory structure guide to better understand how your project is organized.
Conclusion
Setting up a Laravel project is a straightforward process, but it opens the door to a powerful and flexible framework. By following this guide, you’ve laid a solid foundation for your future Laravel projects. Stay tuned for more tutorials that will take your Laravel skills to the next level.