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 with Apache, PHP, and Composer.
Prerequisites
Before you begin, ensure that you have the following:
- A with administrative privileges.
- Windows VPSServer 2016 or later, or Windows VPS10/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:
- Download and install Apache HTTP Server.
- Download and install PHP from Windows VPSPHP Downloads.
- Ensure PHP is properly integrated with Apache by configuring the
httpd.conffile with the correctLoadModuleandPHPIniDirdirectives. - Install Composer by downloading the installer from the official Composer website.
- 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:
- Open a command prompt or PowerShell window.
- Navigate to the directory where you want to install Laravel, for example:
cd C:\wamp\www
- Run the following command to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel your-project-name
- 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:
- Open the Apache configuration file, typically located at
C:\Apache24\conf\httpd.conf. - Ensure that the
mod_rewritemodule is enabled by checking that the following line is not commented out:LoadModule rewrite_module modules/mod_rewrite.so
- Configure the
DocumentRootto 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>
- Restart Apache to apply the changes.
Step 4: Set Up Environment Variables for Laravel
Ensure that you configure your Laravel environment settings:
- Navigate to the Laravel project directory and copy the
.env.examplefile to.env:cd your-project-name
copy .env.example .env
- Generate the application key by running the following command:
php artisan key:generate
- Update the
.envfile 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:
- Install MySQL or MariaDB on your if you haven’t already done so.
- Create a new database for your Laravel application:
CREATE DATABASE laravel_db;
- Update the
DB_DATABASE,DB_USERNAME, andDB_PASSWORDfields in your.envfile 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://localhostorhttp://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 . You can now start building your web applications with Laravel’s powerful features.