# Installing Laravel 11: A Step-by-Step Guide

jsandaruwan

J-Sandaruwan

Posted on July 13, 2024

# Installing Laravel 11: A Step-by-Step Guide

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.

Verify the installation by running:

php -v
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Composer

Composer is a dependency manager for PHP. Download and install Composer from the official Composer website.

Verify the installation by running:

composer -v
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Laravel 11

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

composer create-project --prefer-dist laravel/laravel laravel11-app "11.*"
Enter fullscreen mode Exit fullscreen mode

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

Step 4: Configure Environment

Navigate to your project directory:

cd laravel11-app
Enter fullscreen mode Exit fullscreen mode

Copy the .env.example file to .env:

cp .env.example .env
Enter fullscreen mode Exit fullscreen mode

Generate a new application key:

php artisan key:generate
Enter fullscreen mode Exit fullscreen mode

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:

php artisan serve
Enter fullscreen mode Exit fullscreen mode

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:

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;
    }
}
Enter fullscreen mode Exit fullscreen mode

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:

composer require predis/predis
Enter fullscreen mode Exit fullscreen mode

Step 7: Run Migrations

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

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

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.

Happy coding!

Thank you,
J-Sandaruwan.
linkedin

💖 💪 🙅 🚩
jsandaruwan
J-Sandaruwan

Posted on July 13, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related