# Installing Laravel 11: A Step-by-Step Guide
Tags: webdev, beginners, programming, laravel
Published: 2024-07-13 19:34:12

Laravel 11 is a powerful PHP framework that helps developers build robust and scalable web applications. This guide will walk you through the installation process and outline the dependencies required to get your Laravel 11 application up and running.

## Prerequisites

Before you install Laravel 11, ensure you have the following prerequisites installed on your machine:

1. **PHP**: Laravel 11 requires PHP 8.1 or higher.
2. **Composer**: Laravel uses Composer to manage its dependencies.
3. **Web Server**: Apache or Nginx is recommended.
4. **Database**: MySQL, PostgreSQL, SQLite, or SQL Server.

## Step 1: Install PHP

Make sure you have PHP 8.1 or higher installed. You can download the latest version of PHP from the [official PHP website](https://www.php.net/downloads).

Verify the installation by running:

```bash
php -v
```

## Step 2: Install Composer

Composer is a dependency manager for PHP. Download and install Composer from the [official Composer website](https://getcomposer.org/download/).

Verify the installation by running:

```bash
composer -v
```

## Step 3: Install Laravel 11

With PHP and Composer installed, you can now install Laravel 11. Open your terminal and run the following command:

```bash
composer create-project --prefer-dist laravel/laravel laravel11-app "11.*"
```

This command will create a new Laravel 11 project in a directory named `laravel11-app`.

## Step 4: Configure Environment

Navigate to your project directory:

```bash
cd laravel11-app
```

Copy the `.env.example` file to `.env`:

```bash
cp .env.example .env
```

Generate a new application key:

```bash
php artisan key:generate
```

Update your `.env` file with your database credentials and other necessary configurations.

## Step 5: Set Up a Web Server

### Using Artisan Serve (Development Only)

For development purposes, you can use Laravel's built-in server:

```bash
php artisan serve
```

Visit `http://localhost:8000` in your browser to see your Laravel application.

### Using Apache or Nginx (Production)

For production, configure your web server to serve your Laravel application. Below is a basic Nginx configuration:

```nginx
server {
    listen 80;
    server_name yourdomain.com;
    root /path/to/laravel11-app/public;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
```

Replace `/path/to/laravel11-app` with the actual path to your Laravel application.

## Step 6: Install Dependencies

Laravel 11 comes with several dependencies pre-installed. However, you may need to install additional packages depending on your application's requirements. Here are some common dependencies:

- **Database**: Install the database driver for your chosen database (e.g., `pdo_mysql` for MySQL).
- **Cache**: For caching, you might want to install a Redis or Memcached driver.
- **Queue**: For job queues, you might use Redis, Beanstalkd, or Amazon SQS.

You can install additional packages using Composer. For example, to install the Redis driver, run:

```bash
composer require predis/predis
```

## Step 7: Run Migrations

Laravel uses migrations to manage the database schema. Run the following command to create the necessary tables:

```bash
php artisan migrate
```

## Conclusion

You have successfully installed Laravel 11 and set up your development environment. You can now start building your application. For more information on using Laravel, refer to the [official Laravel documentation](https://laravel.com/docs/11.x).

Happy coding!

Thank you,
J-Sandaruwan.
[linkedin](https://www.linkedin.com/in/j-sandaruwan/)