Skip to main content

How To Install Laravel Latest Version

How To Install Laravel Latest Version

Laravel is one of the most popular PHP frameworks for building modern web applications. It provides an elegant syntax, robust features, and a smooth developer experience. Installing the latest version of Laravel is straightforward if you follow the right steps.

This article will guide you through the process of installing Laravel's latest version on various platforms, from macOS to Windows and Linux. We’ll also explore different installation methods, such as using Composer and Docker.


01. Prerequisites for Installing Laravel

Before diving into the installation process, ensure that you have the following installed on your system:

  • PHP (version 8.1 or higher): Laravel requires PHP to run. You can check your PHP version by running php -v in your terminal.
  • Composer: Laravel uses Composer to manage its dependencies. Install Composer globally on your system if you haven't already.
  • A database: You can use MySQL, SQLite, or PostgreSQL with Laravel, but MySQL or MariaDB is most commonly used.
  • Node.js and NPM: Laravel uses Node.js for frontend dependencies and assets compilation.
  • Docker (optional): If you prefer to use Docker for Laravel development, this article will show you how to install and configure Docker as well.

02. Installation Methods

There are two primary ways to install Laravel: through Composer and Docker. Let’s go over each method.

02.1 Installation Using Composer

Step 1: Install Composer

If you don’t have Composer installed, follow these steps to install it:

  • macOS/Linux: Run the following command in your terminal:

    curl -sS https://getcomposer.org/installer | php

    After that, move the Composer binary to a directory in your PATH:

    sudo mv composer.phar /usr/local/bin/composer
  • Windows: Download and run the Composer installer from the official Composer website: Composer Setup.

You can check if Composer was successfully installed by running composer -v in your terminal.

Step 2: Install Laravel

To install the latest version of Laravel, run the following command:

composer create-project --prefer-dist laravel/laravel my-laravel-app

This command will create a new directory named my-laravel-app and install the latest stable version of Laravel in it.

Step 3: Configure the Environment

Navigate to the newly created directory:

cd my-laravel-app

Laravel uses an .env file to manage environment settings. If you want to configure your database, cache, or mail settings, you can modify the .env file.


02.2 Installation Using Docker (Laravel Sail)

Laravel Sail is a lightweight command-line interface for Docker that allows you to quickly spin up a development environment for Laravel using Docker containers.

Step 1: Install Docker

  • macOS/Linux: You can install Docker by following the instructions on the official Docker website: Docker Installation.

  • Windows: Download and install Docker Desktop from the official site: Docker Desktop.

After installation, verify that Docker is running by executing docker --version.

Step 2: Install Laravel Sail

To install Laravel Sail, you can use the following command:

curl -s https://laravel.build/my-laravel-app | bash

Replace my-laravel-app with your preferred project name.

This command will create a new directory for your Laravel project and install the necessary Docker containers, including services like MySQL, Redis, and Laravel.

Step 3: Start the Docker Containers

Once the project is created, navigate to your project directory and run:

cd my-laravel-app
./vendor/bin/sail up

This will start the Docker containers for your Laravel application.

To access your Laravel project in your browser, go to http://localhost.

Step 4: Additional Configuration (Optional)

If you need to add more services to your Laravel Sail configuration (such as PostgreSQL or Mailhog), you can modify the docker-compose.yml file in the root directory of your project.


03. Post-Installation Steps

Once Laravel is installed, there are some basic steps you should follow to get started with development:

03.1 Generate Application Key

Laravel requires an application key to secure user sessions and other encrypted data. You can generate this key by running the following Artisan command:

php artisan key:generate

This command will generate a unique key and update the .env file with it.

03.2 Database Configuration

To configure your database connection, update the .env file with the appropriate database credentials. For example, for MySQL:

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

03.3 Migrate the Database

Laravel includes a powerful migration system that allows you to version control your database schema. To run the default migrations, use the following command:

php artisan migrate

03.4 Start the Development Server

You can start a local development server using the Artisan command:

php artisan serve

By default, the application will be available at http://localhost:8000.


04. Troubleshooting Common Issues

04.1 Permissions Issues

If you encounter any permission errors during installation or while running the application, you may need to set proper permissions on your project’s directories:

sudo chmod -R 777 storage bootstrap/cache

04.2 PHP Version Compatibility

Laravel requires PHP 8.1 or higher. If you are using an older version, you can update your PHP version via your package manager (on Linux) or download a newer version (on macOS and Windows).

04.3 Missing Extensions

Laravel may require certain PHP extensions, such as pdo, mbstring, tokenizer, and openssl. Ensure that these extensions are installed and enabled on your system.


05. Conclusion

Laravel is a powerful framework for building modern web applications, and the installation process is relatively straightforward. Whether you choose to install Laravel via Composer or Docker (Laravel Sail), the setup process ensures that you have all the tools you need to start building web applications.

If you're new to Laravel, consider checking out the official documentation, and explore further topics like routing, controllers, migrations, and Eloquent ORM. Laravel's ecosystem is vast, and there’s always more to learn and explore!

Comments