Skip to content

Laravel - Installation

Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.

Ensure your server meets the following requirements (refer to the official Laravel documentation for the specific version you intend to install, as these can change):

  • PHP (e.g., >= 8.1 for Laravel 10, >= 8.2 for Laravel 11)
  • Required PHP Extensions: Ctype, cURL, DOM, Fileinfo, Filter, Hash, Mbstring, OpenSSL, PCRE, PDO, Session, Tokenizer, XML, JSON, Sodium (if using certain encryption features).

If you don’t have Composer, download and install it from the official website: https://getcomposer.org/download/

After installation, verify it by opening your terminal or command prompt and typing:

composer --version

This should display the installed Composer version.

You can create a new Laravel project using the Composer create-project command. Open your terminal, navigate to the directory where you want to create your project, and run:

composer create-project laravel/laravel example-app

Replace example-app with the desired name for your project directory. This command will download Laravel and its dependencies into a new example-app directory.

Alternatively, you can use the Laravel Installer if you have it globally installed:

composer global require laravel/installer
laravel new example-app

During the installation, Composer will download many packages. You’ll see output similar to this (abbreviated):

Installing laravel/laravel (v10.x.x)
- Downloading laravel/laravel (v10.x.x)
- Installing laravel/laravel (v10.x.x): Extracting archive
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: ... installs, ... updates, ... removals
- Downloading ...
- Installing ...
Generating optimized autoload files
...

Once completed, you’ll typically see messages about discovering packages and publishing assets, followed by:

Application key set successfully.
Thank you! We hope you build something incredible. Dive in with: cd example-app && php artisan serve

Laravel includes a local development server that you can use to serve your application. Navigate into your project directory:

cd example-app

Then, start the Artisan development server:

php artisan serve

You should see output like this:

INFO Server running on [http://127.0.0.1:8000].
Press Ctrl+C to stop the server

Open your web browser and navigate to http://127.0.0.1:8000 (or the URL shown by the php artisan serve command).

If the installation was successful, you should see the default Laravel welcome page. This page typically displays the Laravel version and links to documentation.

Alternative: Laravel Sail (Docker Environment)

Section titled “Alternative: Laravel Sail (Docker Environment)”

Laravel Sail is a light-weight command-line interface for interacting with Laravel’s default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, Redis, and more, without requiring prior Docker experience.

If you chose to install Sail when creating your project (it’s often an option or can be added later), you would typically use commands like ./vendor/bin/sail up to start the Docker containers and ./vendor/bin/sail artisan serve (though often unnecessary as the web server runs in a container).

Consult the Laravel Sail documentation for more details: https://laravel.com/docs/sail

With Laravel installed, you can start exploring its features:

  • Configuration: Review the .env file and config directory.
  • Routing: Define routes in routes/web.php.
  • Controllers: Create controllers to handle requests.
  • Views: Design your UI using Blade templates in resources/views.
  • Database: Set up migrations and models to interact with your database.
  • PHP Version Mismatch: Ensure your CLI PHP version meets Laravel’s requirements.
  • Missing PHP Extensions: The composer create-project command usually checks for required extensions. If you encounter errors, check your php.ini to enable them.
  • Permissions: The storage and bootstrap/cache directories need to be writable by your web server/PHP process.