Introduction

Laravel is a popular PHP framework for developing web applications. In this guide, we will show you how to install and configure Laravel on a Windows VPS with Apache, PHP, and Composer.

Prerequisites

Before you begin, ensure that you have the following:

  • A Windows VPS with administrative privileges.
  • Windows Server 2016 or later, or Windows 10/11 installed.
  • Apache Web Server installed and running.
  • PHP 7.4 or later installed (preferably PHP 8.x for optimal performance).
  • Composer installed on your server for managing PHP dependencies.
  • Basic knowledge of using the command line interface (CLI).

Step 1: Install Apache, PHP, and Composer

If you don’t have Apache, PHP, and Composer installed, follow these steps:

  1. Download and install Apache HTTP Server.
  2. Download and install PHP from Windows PHP Downloads.
  3. Ensure PHP is properly integrated with Apache by configuring the httpd.conf file with the correct LoadModule and PHPIniDir directives.
  4. Install Composer by downloading the installer from the official Composer website.
  5. Verify PHP, Apache, and Composer installation by checking their versions:
    php -v
    composer -v

Step 2: Install Laravel Using Composer

Now that you have Composer installed, you can easily install Laravel:

  1. Open a command prompt or PowerShell window.
  2. Navigate to the directory where you want to install Laravel, for example:
    cd C:\wamp\www
  3. Run the following command to create a new Laravel project:
    composer create-project --prefer-dist laravel/laravel your-project-name
  4. This will download and install Laravel and its dependencies in a folder named your-project-name.

Step 3: Configure Apache for Laravel

Next, configure Apache to serve your Laravel application:

  1. Open the Apache configuration file, typically located at C:\Apache24\conf\httpd.conf.
  2. Ensure that the mod_rewrite module is enabled by checking that the following line is not commented out:
    LoadModule rewrite_module modules/mod_rewrite.so
  3. Configure the DocumentRoot to point to the public directory inside the Laravel project folder. For example:
    DocumentRoot "C:/wamp/www/your-project-name/public"
    <Directory "C:/wamp/www/your-project-name/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
  4. Restart Apache to apply the changes.

Step 4: Set Up Environment Variables for Laravel

Ensure that you configure your Laravel environment settings:

  1. Navigate to the Laravel project directory and copy the .env.example file to .env:
    cd your-project-name
    copy .env.example .env
  2. Generate the application key by running the following command:
    php artisan key:generate
  3. Update the .env file with your database connection and other application settings.

Step 5: Set Up Database for Laravel

Laravel uses a database to store application data. If you haven’t set up a database yet, follow these steps:

    1. Install MySQL or MariaDB on your Windows VPS if you haven’t already done so.
    2. Create a new database for your Laravel application:
CREATE DATABASE laravel_db;
  1. Update the DB_DATABASE, DB_USERNAME, and DB_PASSWORD fields in your .env file to reflect the database you just created.

Step 6: Verify Laravel Installation

Finally, verify that Laravel is working by visiting your server’s IP address or localhost in a browser. For example, visit:

  • http://localhost or http://your-server-ip.

If everything is set up correctly, you should see the Laravel welcome page.

Conclusion

Congratulations! You have successfully installed Laravel on your Windows VPS. You can now start building your web applications with Laravel’s powerful features.

© 2024 Your Company. All rights reserved.