Prerequisites
- XAMPP Installed: Ensure XAMPP is installed and running on your system. Download it from Apache Friends.
- Composer Installed: Install Composer, the dependency manager for PHP. Download it from getcomposer.org.
- PHP Installed: XAMPP usually comes with PHP. Verify the PHP version is compatible with the Laravel version you intend to install.
Step-by-Step Guide
1. Start XAMPP Services
- Open the XAMPP Control Panel.
- Start Apache and MySQL.
2. Set Up a Database
- Open phpMyAdmin in your browser by visiting:
http://localhost/phpmyadmin
. - Create a new database:
- Click on New in the sidebar.
- Name the database (e.g.,
laravel_db
) and click Create.
3. Install Laravel Using Composer
- Open Command Prompt or PowerShell.
- Navigate to your XAMPP’s
htdocs
directory:bashCopycd C:\xampp\htdocs
- Create a new Laravel project:bashCopy
composer create-project --prefer-dist laravel/laravel laravel-app
Replacelaravel-app
with your desired project folder name.
4. Configure .env
File
- Navigate to your Laravel project directory:bashCopy
cd laravel-app
- Open the
.env
file in a text editor. - Update the database configuration:envCopy
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_db DB_USERNAME=root DB_PASSWORD= # Leave blank if no password is set for MySQL.
5. Serve the Laravel Application
- Run the Laravel development server:bashCopy
php artisan serve
- Access the application in your browser:arduinoCopy
http://127.0.0.1:8000
6. Configure Apache (Optional)
If you prefer to access the Laravel project via http://localhost/laravel-app
:
- Open the XAMPP httpd-vhosts.conf file:makefileCopy
C:\xampp\apache\conf\extra\httpd-vhosts.conf
- Add the following configuration:apacheCopy
<VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/laravel-app/public" ServerName laravel-app.test </VirtualHost>
- Add the domain to your
hosts
file:- Open
C:\Windows\System32\drivers\etc\hosts
as an administrator. - Add this line:Copy
127.0.0.1 laravel-app.test
- Open
- Restart Apache in the XAMPP Control Panel.
- Access the application via
http://laravel-app.test
.
7. Run Database Migrations
- Run the following command to set up tables in your database:bashCopy
php artisan migrate
Troubleshooting
- If Composer is not recognized, ensure it’s added to your system’s PATH.
- If the development server doesn’t start, ensure PHP is correctly configured in XAMPP.
You’re now set up to develop your Laravel project using XAMPP!