XAMPP

指南 & Troubleshooting

分步解决方案、配置指南和最佳实践,以充分利用 XAMPP。

安装指南

1

下载 the Installer

Visit the 下载 page and select the installer for your operating system. Make sure to download from the official SourceForge mirror to ensure file integrity.

2

Run the Installer

Double-click the downloaded file. On Windows, you may see a User Account Control prompt - click "Yes." On macOS, drag the XAMPP icon to your Applications folder. On Linux, extract the tar.gz and run the setup script.

3

Select Components

During installation, choose the components you need. By default, Apache, MariaDB, PHP, and phpMyAdmin are selected. You can also include FileZilla, Tomcat, Mercury Mail, and Perl depending on your project requirements.

4

Choose Installation Folder

We recommend installing to the default location (C:\xampp on Windows, /opt/lampp on Linux, /Applications/XAMPP on macOS). Avoid paths with spaces or special characters to prevent permission issues.

5

Launch the Control Panel

After installation, open the XAMPP Control Panel. Click "Start" next to Apache and MySQL. Open your browser and navigate to http://localhost to verify everything is working.

Apache 配置

Changing the Apache Port

If port 80 is already in use (common with Skype, IIS, or other web servers), you need to change Apache's listening port.

  1. Open the XAMPP Control Panel and click "Config" next to Apache.
  2. Select httpd.conf.
  3. Find the line Listen 80 and change it to Listen 8080.
  4. Also find ServerName localhost:80 and change to ServerName localhost:8080.
  5. Save the file and restart Apache from the Control Panel.
  6. Access your site at http://localhost:8080.

Setting Up Virtual Hosts

Virtual hosts allow you to run multiple local websites with custom domain names like myproject.local.

  1. Edit C:\Windows\System32\drivers\etc\hosts (run Notepad as Administrator).
  2. Add a line: 127.0.0.1 myproject.local.
  3. Open httpd-vhosts.conf from the Apache config menu.
  4. Add your virtual host block with DocumentRoot and ServerName.
  5. Restart Apache and visit http://myproject.local.

Database Setup & Management

Accessing phpMyAdmin

phpMyAdmin is the web-based interface for managing your MariaDB databases. After starting MySQL from the Control Panel, click the "Admin" button next to MySQL, or visit http://localhost/phpmyadmin in your browser.

Default MySQL user: root
Default password: (empty / none)

Securing MySQL Root Password

By default, the MySQL root user has no password. For local development this is acceptable, but if you want to set one:

  1. Open phpMyAdmin and click the "User accounts" tab.
  2. Click "Edit privileges" next to the root user.
  3. Click "Change password" and enter a secure password.
  4. Update the config.inc.php file in phpMyAdmin to match the new password.

Importing & Exporting Databases

To import a database, open phpMyAdmin, select your database (or create one), click the "Import" tab, choose your .sql file, and click "Go." To export, select the database, click "Export," choose your format (usually SQL), and click "Go."

PHP 配置

Editing php.ini

The php.ini file controls PHP behavior. Common changes include increasing upload limits, memory limits, and enabling extensions.

  1. Click "Config" next to Apache in the Control Panel.
  2. Select PHP (php.ini).
  3. Find and modify settings like:
    • upload_max_filesize = 128M
    • post_max_size = 128M
    • memory_limit = 512M
    • max_execution_time = 300
  4. Save and restart Apache for changes to take effect.

Enabling PHP Extensions

Most common extensions are enabled by default. To enable additional ones, open php.ini, find the extension list, and uncomment (remove the semicolon from) the extensions you need. Common extensions include extension=gd, extension=intl, and extension=imap. Restart Apache after making changes.

修复端口冲突

Port conflicts are the most common issue when starting XAMPP services. Here's how to diagnose and fix them.

Apache Won't Start (Port 80 in Use)

Common culprits include Skype, Microsoft IIS, World Wide Web Publishing Service, or another Apache installation.

  • 1.Check the Control Panel logs for the specific error message.
  • 2.On Windows, open Services (services.msc) and stop "World Wide Web Publishing Service."
  • 3.In Skype, go to Tools > Options > Advanced > Connection and uncheck "Use port 80 and 443."
  • 4.Alternatively, change Apache to use ports 8080 and 4433 as described in the Apache guide above.

MySQL Won't Start (Port 3306 in Use)

Another MySQL or MariaDB instance may already be running on your system.

  • 1.Open Task Manager and look for mysqld.exe processes. End any that aren't XAMPP.
  • 2.Stop any other database services from the Services panel.
  • 3.Or change MySQL port in my.ini from 3306 to 3307.

Antivirus Warnings & False Positives

Some antivirus and security software may flag XAMPP or its components as suspicious. This happens because XAMPP includes server software that opens network ports and administrative tools that can modify system files - behavior that heuristic scanners sometimes misidentify as malicious.

Important: XAMPP contains no malware, adware, or spyware.

Every release is built from publicly available source code and distributed through trusted channels. If your antivirus flags XAMPP, it is a false positive.

Recommended Actions

  • Add your XAMPP installation folder to your antivirus exclusion list.
  • Temporarily disable real-time protection during installation if necessary.
  • Always download XAMPP from official sources to ensure file integrity.
  • Verify SHA-256 checksums after downloading to confirm authenticity.

最佳实践

Keep XAMPP Updated

Regularly check for new versions to get security patches, PHP updates, and Apache improvements. Subscribe to the Apache Friends newsletter or monitor the SourceForge project page.

Use Virtual Hosts

Instead of dumping all projects in htdocs, create a virtual host for each project. This mimics production environments and makes URLs cleaner.

Backup Your Databases

Use phpMyAdmin's export feature regularly to create SQL backups of your databases. Store these backups outside the XAMPP folder in case you need to reinstall.

Never Use XAMPP on Public Networks

XAMPP is designed for local development. Default security settings are intentionally minimal. Do not expose XAMPP services to the internet without proper hardening.

Secure phpMyAdmin

If multiple users access your machine, set a MySQL root password and consider enabling authentication for phpMyAdmin via the config.inc.php settings.

Check Logs First

When something goes wrong, always check the Apache and MySQL error logs in the Control Panel before searching online. The answer is usually right there.

下载