How to Install Laravel with XAMPP

How to Install Laravel with XAMPP

Installing Laravel with XAMPP

This guide provides a detailed, step-by-step approach to installing Laravel, one of the most popular PHP frameworks, using XAMPP (Apache, MySQL, and PHP). This setup allows you to develop and test your Laravel applications in a local environment.

Prerequisites

Before you begin, ensure you have the following installed on your machine:

  • XAMPP: A free and open-source cross-platform web server solution stack package that includes Apache HTTP Server, MariaDB (a fork of MySQL), and interpreters for scripts written in the PHP and Perl programming languages.
  • Composer: A dependency manager for PHP essential for managing Laravel's libraries and dependencies.

Step 1: Download and Install XAMPP

  1. Download XAMPP:

    • Go to the XAMPP official website.
    • Choose the version compatible with your operating system (Windows, macOS, or Linux) and download the installer.
  2. Install XAMPP:

    • Run the installer by double-clicking on it.
    • If prompted by a security warning, click "Run."
    • In the XAMPP setup wizard, click "Next."
    • Select the components to install. Ensure Apache and MySQL are checked. You can also include PHP and phpMyAdmin if desired.
    • Click "Next."
    • Choose the installation directory (default is usually C:\xampp). Click "Next."
    • Select your preferred language (English is default). Click "Next."
    • Click "Next" again to start the installation process.
    • Once the installation is complete, you can choose to start the XAMPP Control Panel immediately. Click "Finish."
  3. Start XAMPP:

    • Open the XAMPP Control Panel from your desktop or start menu.
    • In the control panel, you will see a list of modules. Click the "Start" button next to Apache and MySQL. Ensure both services are running (indicated by green highlights).

Step 2: Install Composer

Composer is essential for managing Laravel's dependencies. Here’s how to install it:

  1. Download Composer:

  2. Install Composer:

    • Run the downloaded Composer-Setup.exe file.
    • Follow the installation prompts. When asked to set up the PHP path, browse to your XAMPP installation directory and select php.exe, typically found in C:\xampp\php\php.exe.
    • Complete the installation process.
  3. Verify Composer Installation:

    • Open the Command Prompt by pressing Win + R, typing cmd, and hitting Enter.
    • Type the following command to check if Composer was installed correctly:
      composer -V
    • If installed successfully, you will see the Composer version displayed.

Step 3: Create a New Laravel Project

Now that Composer is installed, you can create a new Laravel project.

  1. Open Command Prompt:

    • Press Win + R, type cmd, and hit Enter to open the Command Prompt.
  2. Navigate to the XAMPP htdocs Directory:

    • Type the following command to change the directory to the htdocs folder where XAMPP serves files:
      cd C:\xampp\htdocs
  3. Create a New Laravel Project:

    • Use Composer to create a new Laravel project (replace myproject with your desired project name):
      composer create-project --prefer-dist laravel/laravel myproject
    • This command will download and install a new Laravel application in a folder named myproject.

Step 4: Configure Environment

  1. Set Up Environment Variables:

    • Change to your project directory:
      cd myproject
    • Copy the example environment file to create a new .env file:
      copy .env.example .env
  2. Generate Application Key:

    • Run the following command to generate an application key:
      php artisan key:generate
    • This key is essential for securing user sessions and other encrypted data.
  3. Configure Database:

    • Open the .env file in a text editor (like Notepad or Visual Studio Code).
    • Find the database configuration section and update it to match your database settings:
      DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=mydatabase // Replace with your actual database name DB_USERNAME=root DB_PASSWORD=
    • Note: Before proceeding, create a new database in phpMyAdmin:
      • Open your web browser and go to http://localhost/phpmyadmin.
      • Click on Databases at the top.
      • Enter the name of your database (e.g., mydatabase) and click Create.

Step 5: Run the Laravel Development Server

  1. Start Laravel Development Server:
    • In the Command Prompt, while still in your Laravel project directory, run:
      php artisan serve
    • This will start the Laravel development server. You will see a message indicating that the server is running, typically at http://localhost:8000.

Step 6: Access Your Laravel Application

  • Open your web browser and navigate to http://localhost:8000 to view your Laravel application. You should see the Laravel welcome page, indicating that everything is set up correctly.

Step 7: Additional Configuration (Optional)

If you want to access your Laravel project via XAMPP’s localhost (e.g., http://localhost/myproject), you can set up a virtual host.

  1. Open Apache Configuration File:

    • In XAMPP Control Panel, click on the Config button next to Apache and select httpd-vhosts.conf.
    • Add the following lines to define your virtual host (adjust paths accordingly):
      <VirtualHost *:80> DocumentRoot "C:/xampp/htdocs/myproject/public" ServerName myproject.local <Directory "C:/xampp/htdocs/myproject/public"> AllowOverride All Require all granted </Directory> </VirtualHost>
  2. Edit Hosts File:

    • Open the hosts file as an administrator. Navigate to C:\Windows\System32\drivers\etc\hosts.
    • Add the following line to map the virtual host:
      127.0.0.1 myproject.local
  3. Restart Apache:

    • Go back to the XAMPP Control Panel and restart Apache for the changes to take effect.

Step 8: Access Your Laravel Application via Virtual Host

  • Open your web browser and type http://myproject.local to access your Laravel application through the virtual host.

Troubleshooting Tips

  • Apache Not Starting:

    • If Apache doesn’t start, check if another application (like Skype) is using port 80. You can change Apache’s port in the XAMPP Control Panel by clicking the Config button next to Apache and selecting httpd.conf. Look for the line Listen 80 and change it to Listen 8080. Then, access your site at http://localhost:8080.
  • Database Connection Issues:

    • If you encounter issues connecting to the database, double-check your .env file for accuracy and ensure the database exists in phpMyAdmin.
  • Permission Issues (Linux/Mac):

    • If you’re on Linux or macOS, you might encounter permission issues. You can resolve this by running:

    • sudo chmod -R 775 storage sudo chmod -R 775 bootstrap/cache

Conclusion

You have successfully installed Laravel using XAMPP! You can now start building your web applications with Laravel in a local development environment. This setup provides a powerful framework for developing robust and scalable web applications. If you have any further questions or encounter any issues, please ask for assistance!

Souy Soeng

Souy Soeng

Our website teaches and reads PHP, Framework Laravel, and how to download Admin template sample source code free. Thank you for being so supportive!

Github

Post a Comment

CAN FEEDBACK
close