Laravel - Installation
Laravel - Installation
Section titled “Laravel - Installation”Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.
System Requirements:
Section titled “System Requirements:”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).
Step 1: Install Composer
Section titled “Step 1: Install Composer”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 --versionThis should display the installed Composer version.
Step 2: Create a New Laravel Project
Section titled “Step 2: Create a New Laravel Project”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-appReplace 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/installerlaravel new example-appDuring 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 archiveInstalling dependencies from lock fileVerifying 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 serveStep 3: Running the Development Server
Section titled “Step 3: Running the Development Server”Laravel includes a local development server that you can use to serve your application. Navigate into your project directory:
cd example-appThen, start the Artisan development server:
php artisan serveYou should see output like this:
INFO Server running on [http://127.0.0.1:8000].
Press Ctrl+C to stop the serverStep 4: Access Your Application
Section titled “Step 4: Access Your Application”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
Next Steps
Section titled “Next Steps”With Laravel installed, you can start exploring its features:
- Configuration: Review the
.envfile andconfigdirectory. - 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.
Common Installation Issues:
Section titled “Common Installation Issues:”- PHP Version Mismatch: Ensure your CLI PHP version meets Laravel’s requirements.
- Missing PHP Extensions: The
composer create-projectcommand usually checks for required extensions. If you encounter errors, check yourphp.inito enable them. - Permissions: The
storageandbootstrap/cachedirectories need to be writable by your web server/PHP process.