Prerequisites
- PHP: Laravel requires PHP 8.0 or higher.
- Composer: Laravel uses Composer, a PHP dependency manager, to handle packages.
- Web Server: Apache or Nginx is recommended.
Step 1: Install Composer
If you haven’t installed Composer, download and install it from getcomposer.org.
To verify the installation, run:
composer --version
Step 2: Install Laravel
You can install Laravel in two main ways:
- Via Composer (Recommended): Using Composer’s
create-project
command. - Using Laravel Installer: Install the Laravel CLI tool, which lets you create new Laravel projects easily.
Option 1: Install Laravel using Composer’s create-project
command
1. Navigate to the directory where you want to install Laravel:
cd path/to/your/project-directory
2. Run the following command to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel project-name
Replace project-name
with the desired name for your project.
3. Once the installation is complete, navigate to your project directory:
cd project-name
Option 2: Install Laravel using Laravel Installer
1. First, install the Laravel Installer globally:
composer global require laravel/installer
2. Make sure the Composer global vendor directory is added to your system’s PATH
. For most systems, you can add the following line to your shell configuration file (like .bashrc
or .zshrc
):
export PATH="$PATH:$HOME/.composer/vendor/bin"
3. Now, create a new Laravel project with:
laravel new project-name
Step 3: Configure Environment
1. Copy the .env.example
file to .env
:
cp .env.example .env
2. Generate an application key:
php artisan key:generate
3. Open the .env
file and set up your database credentials and any other required environment variables.
Step 4: Start the Laravel Development Server
Now, you can start Laravel’s built-in development server by running:
php artisan serve
This command will start the server at http://localhost:8000
by default. You can open this URL in your browser to see the Laravel welcome page.
Step 5: Verify Installation
If everything is set up correctly, you should see the Laravel welcome page at http://localhost:8000
.
Additional Configuration
- Database: Configure your database connection in the
.env
file. - Storage: Make sure the storage and bootstrap/cache directories are writable by the web server:
chmod -R 775 storage
chmod -R 775 bootstrap/cache
You’re all set! You now have a fully functional Laravel application.