Setup Guides

XAMPP Setup: PHP and MySQL Locally

We explain how to set up an Apache, PHP and MySQL environment on your computer with XAMPP, open your first PHP page and fix common port and startup errors.

Aurora YazılımEditorial team 6 min read
XAMPP Setup: PHP and MySQL Locally
How do you install XAMPP?

For XAMPP installation, download the installer for your operating system from apachefriends.org and install it to the C:\xampp folder on Windows. Start Apache and MySQL from the XAMPP Control Panel and open http://localhost in your browser. When you put your files in the htdocs folder, your PHP pages run locally; if Apache won't start, the problem is usually that port 80 is being used by another program.

What Is XAMPP and What Is It For?

XAMPP is a free package that puts the Apache web server, PHP, the MariaDB database and the phpMyAdmin admin panel on your computer in a single installation. The goal is to run a PHP site on your own computer, that is, on localhost, before putting it on the internet.

The package's name comes from its contents: X (cross-platform), Apache, MariaDB/MySQL, PHP and Perl. Current XAMPP versions ship MariaDB as the database; MariaDB is largely compatible with MySQL and still appears under the MySQL name in the control panel.

XAMPP is ideal for learning, small experiments and getting a project up quickly. If you need different PHP versions for several projects, or want an environment identical to the live server, a container-based setup is more flexible; we covered that in our Docker installation guide.

ComponentPurposeDefault port
ApacheServes web pages80 (HTTP), 443 (HTTPS)
MariaDB (MySQL)Database server3306
PHPRuns server-side codeThrough Apache
phpMyAdminDatabase management from the browserlocalhost/phpmyadmin

Before You Install

Download XAMPP only from the official address, apachefriends.org. The site lists several versions; the main difference between them is the PHP version they include. Choose the package closest to the PHP version your project requires.

On Windows, install to a folder close to the root directory such as C:\xampp. The Program Files folder causes write-permission problems because of Windows User Account Control (UAC); the installer also shows a warning about this.

  • If you also have a separate MySQL service or IIS installed on your computer, you may run into port conflicts; see the error section below.
  • Antivirus or firewall software may ask for permission for Apache and MySQL on first launch; allow access for private networks only.
  • XAMPP is for development purposes; with its default settings it should not be used as a live server.

Installing XAMPP on Windows

The Windows installation has a few screens, and the default choices are enough for most users.

  1. Run the installer you downloaded as administrator; read the UAC warning and continue.
  2. On the components screen, make sure Apache, MySQL, PHP and phpMyAdmin are selected; clear components like FileZilla, Mercury and Tomcat if you don't need them.
  3. Choose C:\xampp as the installation folder.
  4. When the installation finishes, open the XAMPP Control Panel and click the Start buttons on the Apache and MySQL rows.
  5. When both rows turn green, open http://localhost in your browser; the XAMPP welcome page should appear.

XAMPP on Linux and macOS

The Linux version comes as an installer with a .run extension and installs to /opt/lampp. You only need to make the installer executable and start it with administrator rights. After installation, services are managed with the lampp script; web files live in the /opt/lampp/htdocs folder.

A package is also offered for macOS, but among Mac users, PHP and MariaDB installed separately with Homebrew, or Docker, are more common. Whichever way you choose, the logic is the same: the web server, PHP and the database work together.

bashLinux installation
chmod +x xampp-linux-*-installer.run
sudo ./xampp-linux-*-installer.run

# Managing services
sudo /opt/lampp/lampp start
sudo /opt/lampp/lampp status
sudo /opt/lampp/lampp stop

Running Your First PHP Page

Apache serves the files in the htdocs folder. On Windows this folder is C:\xampp\htdocs, and on Linux it is /opt/lampp/htdocs. Create a folder named deneme inside it and save the file below as index.php.

When you open http://localhost/deneme/ in your browser, you see a long table showing the PHP version, the loaded extensions and the php.ini location. This table shows the installation is working correctly; delete the file when you're done, because it exposes detailed information about the server.

phphtdocs/deneme/index.php
<?php
phpinfo();

Using PHP from the terminal

To use XAMPP's PHP from the command line and with Composer, add the C:\xampp\php folder to PATH. Then run php -v in a new terminal. We covered dependency management step by step in our Composer installation guide.

powershell
C:\xampp\php\php.exe -v

XAMPP MySQL and phpMyAdmin Settings

You can manage your databases by opening http://localhost/phpmyadmin in your browser. Create a database with the New option in the left menu and choose utf8mb4_unicode_ci or another collation from the utf8mb4 family as the character set; special characters and emoji are stored without problems.

In XAMPP, the database root user's password is empty by default. Even if you only work on your own computer, it is a good habit to set a password and create separate users for your projects. After changing the password, you also need to update the password line in the config.inc.php file so that phpMyAdmin can connect.

  • On Windows, the phpMyAdmin password setting is in the C:\xampp\phpMyAdmin\config.inc.php file.
  • For details on users, privileges and SQL commands, see our MySQL installation guide.
sqlA project-specific user (phpMyAdmin SQL tab)
CREATE DATABASE proje CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'proje_kullanici'@'localhost' IDENTIFIED BY 'guclu-bir-sifre';
GRANT ALL PRIVILEGES ON proje.* TO 'proje_kullanici'@'localhost';
FLUSH PRIVILEGES;

Apache Startup Errors and Port Problems

XAMPP's best-known problem is that when you click Apache's Start button, it turns green briefly and then shuts down again. The log window at the bottom of the control panel usually states the cause: Port 80 in use or Port 443 in use. This means another program is holding the port; IIS, another web server or some virtualization and communication programs can cause it.

Finding out who is using the port

Open Command Prompt as administrator and run the commands below. The first shows the process ID (PID) of the process using the port, the second shows that process's name.

powershell
netstat -ano | findstr :80
tasklist /FI "PID eq 1234"

Changing the Apache port

If you can't close the conflicting program, run Apache on a different port. Open the httpd.conf file from the Config button on the Apache row in the Control Panel and change the lines below; then open the site at http://localhost:8080. If 443 is conflicting, do the same in the httpd-ssl.conf file.

apachehttpd.conf
Listen 8080
ServerName localhost:8080
apachehttpd-ssl.conf (if needed)
Listen 4433
<VirtualHost _default_:4433>

MySQL won't start

Port 3306 may be in use by a separate MySQL service installed on the computer; stop that service or change the port value in the my.ini file to something like 3307. For a "MySQL shutdown unexpectedly" error, first back up the mysql\data folder and read the error log; deleting data files at random can permanently corrupt your databases.

From Local to Live Site

A site that runs on XAMPP can behave differently when moved to a live server: the PHP version, extensions, file permissions and database settings change. That is why, before going live, it is important to use the server's PHP version locally too, and to keep database connection details in a configuration file separate from the code.

On a live site, settings like caching, compression and image optimization determine page speed; we cover these topics in our speed and performance optimization service. When you move from local experiments to building a professional corporate website or e-commerce platform, leaving the server and security side to an expert team saves time.

For other local development guides, browse the setup guides category.

Frequently Asked Questions

01What is the difference between XAMPP, WAMP and Laragon?

All of them aim to run a web server, PHP and a database locally. XAMPP stands out for being cross-platform and widely used; the other packages offer Windows-specific conveniences or different version-switching options. The choice mostly depends on habit and your project's requirements.

02Can I change the PHP version in XAMPP?

The official way is to install the XAMPP package that contains the PHP version you want into a separate folder. Swapping the PHP folder by hand is possible, but incompatibilities with the Apache module and extensions may appear; if you often need different versions, Docker is more practical.

03Can I use XAMPP as a live server?

It is not recommended. XAMPP is configured for development convenience; defaults such as an empty root password and exposed admin panels create a serious security risk on an internet-facing server.

XAMPP is the fastest way to start working with PHP and MySQL: install it, start Apache and MySQL, put your files in htdocs, and solve port conflicts with a few settings. If you'd like to turn your local experiments into a secure, fast system built for your business, explore the custom software solutions from Aurora Yazılım or get in touch with us.