Laravel uses Composer to manage dependencies, so you need to install it first.
Visit Composer's official website and follow the installation instructions for your operating system.
You can verify that Composer is installed correctly by running the following command in the terminal:
bash Copy code composer --versionLaravel requires PHP, usually PHP 8.0 or higher. Ensure that PHP is installed on your machine. You can check by running:
bash Copy code php --version
If PHP is not installed, download and install it from PHP's official website, or use a package manager like Homebrew (macOS), apt (Ubuntu), or XAMPP/WAMP (Windows).
Laravel provides a command-line tool called the Laravel Installer. You can install it globally using Composer:
bash Copy code composer global require laravel/installer
Ensure the Composer global bin directory is in your system's PATH to run laravel commands from the terminal.
To verify the installation:
bash Copy code laravel --version
Now, you can create a new Laravel project. There are two ways to do this:
bash Copy code laravel new project-name
bash Copy code composer create-project --prefer-dist laravel/laravel project-name
This command will create a new Laravel project named project-name in the current directory.
Go to your newly created Laravel project folder:
bash Copy code cd project-name
Laravel uses an .env file for environment-specific configurations like database settings, mail services, and others.
Copy the .env.example file to .env:
bash Copy code cp .env.example .envYou can now configure the settings in the .env file, like database connections and application key.
Laravel requires an application key for encryption and security. Generate it by running the following command:
bash Copy code php artisan key:generate
This will set the APP_KEY in your .env file.
If your project uses a database (such as MySQL, SQLite, etc.), you need to configure it in the .env file.
For example, for MySQL:
ini Copy code DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=your_database_name DB_USERNAME=your_username DB_PASSWORD=your_password
Make sure to create the database first if it doesn’t exist.
If your project includes database migrations, you can run them with the following command:
bash Copy code php artisan migrate
Laravel comes with a built-in development server. To start the server and access your project, run:
bash Copy code php artisan serve
By default, the server will run at http://localhost:8000.
If you're working with frontend tools (like Vue, React, or Tailwind CSS), you can use Laravel Mix. Install the necessary Node.js dependencies:
bash Copy code npm install
Then you can compile assets by running:
bash Copy code npm run dev
For production, you can use:
bash Copy code npm run production
At this point, your Laravel environment is ready, and you can start building your application!
This guide covers the basics of getting Laravel up and running. For more advanced setup and customization, refer to the Laravel documentation.