XAMPP

Download

XAMPP Tutorial: How to Set Up and Use XAMPP for Local Web Development

XAMPP is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB (formerly MySQL), and interpreters for scripts written in PHP and Perl. This tutorial will guide you through downloading, installing, and using XAMPP to create a local development environment.


Part 1: Installing XAMPP

Step 1: Download XAMPP

  1. Go to the official XAMPP website: https://www.apachefriends.org.
  2. Choose the version of XAMPP you want to install (there are versions with different versions of PHP).
  3. Download the XAMPP installer for your operating system (Windows, macOS, or Linux).

Step 2: Install XAMPP

  1. Run the installer you just downloaded.
  2. You will see a list of components to install. By default, the essential components (Apache, MySQL/MariaDB, PHP, Perl) are already selected. Leave them as is unless you have specific needs.
  3. Click Next, choose the installation location (default is usually fine), and click Next again.
  4. XAMPP will install all the necessary files. Once the installation is complete, click Finish.

Part 2: Starting XAMPP and Running the Control Panel

Step 1: Open XAMPP Control Panel

  1. After installation, launch the XAMPP Control Panel. If you don’t see it immediately, search for “XAMPP” on your computer and open it.
  2. The XAMPP Control Panel is where you can manage the various services (Apache, MySQL, FileZilla, Mercury, Tomcat) that XAMPP provides.

Step 2: Start Apache and MySQL

  1. In the control panel, click Start next to Apache to start the web server.
  2. Click Start next to MySQL (or MariaDB, depending on your version) to start the database server.
  3. If both services start successfully, they will turn green, and you will see “Running” next to them.

Part 3: Setting Up Your Local Web Server

Step 1: Accessing the Local Server

  1. Once Apache is running, open your browser and type http://localhost in the address bar.
  2. You should see the XAMPP dashboard, which means your local web server is working correctly.

Step 2: Setting Up Your Local Website

  1. The default location for your local web files is in the htdocs folder within the XAMPP installation directory (e.g., C:\xampp\htdocs on Windows).
  2. Create a new folder inside the htdocs directory (e.g., C:\xampp\htdocs\mywebsite).
  3. In this folder, create a basic index.php file to test your setup:
    <?php
    echo "Hello, World!";
    ?>
    
  4. Save the file and open your browser. Type http://localhost/mywebsite in the address bar, and you should see the “Hello, World!” message.

Part 4: Managing Databases with phpMyAdmin

Step 1: Access phpMyAdmin

  1. With XAMPP running, go to http://localhost/phpmyadmin in your browser.
  2. phpMyAdmin is the interface you will use to manage your MySQL/MariaDB databases.

Step 2: Create a New Database

  1. In phpMyAdmin, click on the Databases tab at the top.
  2. Enter a name for your new database and click Create.
  3. Your database is now created, and you can begin adding tables and data.

Step 3: Connecting to the Database from PHP

  1. In your PHP code, you can connect to your MySQL database using the following script:
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
    ?>
    
  2. Save this file in your web directory (e.g., C:\xampp\htdocs\mywebsite\connect.php).
  3. Open http://localhost/mywebsite/connect.php in your browser to see if the connection is successful.

Part 5: Configuring XAMPP for Different Ports (Optional)

If another service (like Skype or another server) is using port 80, Apache might not start. You can configure Apache to use a different port.

Step 1: Changing Apache’s Port Number

  1. In the XAMPP Control Panel, click Config next to Apache.
  2. Select Apache (httpd.conf) from the dropdown menu.
  3. In the file, search for the line Listen 80 and change 80 to another available port (e.g., 8080).
  4. Also, search for ServerName localhost:80 and change 80 to 8080.
  5. Save and close the file, then restart Apache.

Step 2: Accessing Apache on a Different Port

  1. After changing the port, open your browser and type http://localhost:8080 to access your server.

Part 6: Stopping XAMPP Services

Step 1: Stop Services

  1. In the XAMPP Control Panel, click Stop next to the services (Apache, MySQL) you wish to stop.
  2. It’s good practice to stop services when you’re not using them, to free up resources.

Part 7: Troubleshooting

Common Issues and Fixes:

  1. Apache not starting: If Apache won’t start, make sure no other application is using port 80 (e.g., Skype). You can change Apache’s port as shown in Part 5.
  2. Database connection errors: Double-check your database name, username, and password. By default, the MySQL/MariaDB username is root, and there is no password (it can be set later if needed).

Conclusion

XAMPP is a powerful tool for local web development, allowing you to run Apache, PHP, and MySQL (or MariaDB) on your computer without needing an internet connection. This tutorial covers the basics of setting up XAMPP, starting services, setting up a local website, managing databases with phpMyAdmin, and troubleshooting common issues.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.