Have you ever wished you could mess around with WordPress without the trouble or cost of installing it on a web hosting server?
Staging environments are perfectly fine when you need to debug issues or test updates before pushing to a live WordPress website. But what about when you want to:
- Try out new plugins?
- Take a theme for a test spin or build your own?
- Explore a new WordPress feature?
- Experiment with a trending design or coding technique?
- Continue working on a website even when wi-fi connectivity is sparse or non-existent?
In those cases, it’s best to install WordPress locally on your computer. So, today, we’re going to show you how to install WordPress on XAMPP.
How to Install WordPress Locally with XAMPP
Despite making its open-source software readily available for download, WordPress is not something that can be installed on your computer. Not on its own anyway.
If you want to install WordPress on the localhost (i.e. your computer), you’re going to need assistance.
Start here:
Step 1: Choose a Local Server Environment
In order to get a working installation of WordPress going on your computer, you need a local environment with:
- Web server software (usually an Apache server),
- A programming language like PHP or Perl,
- And database management software like MySQL or MariaDB.
XAMPP is the one we’re going to walk you through today. That said, there are other options available, if you prefer:
- WampServer for Windows operating systems
- MAMP for Mac or Windows
- DesktopServer for Mac or Windows
- Local by Flywheel for Mac, Windows, or Linux environments (and is especially useful if you have Flywheel hosting you want to migrate your test site too)
Setup isn’t really complicated with any of these options. However, because XAMPP is a popular dev environment and it’s device-agnostic (Mac, Windows, and Linux compatible), we’re going to focus on that one today.
Step 2: Download XAMPP
Visit the Apache Friends website and download the latest version of XAMPP for your operating system:
The file will automatically start to download.
When it’s done, add XAMPP to your applications and start the loading process.
Depending on your operating system, you may need to accept a number of access permissions before the application fully loads. When it’s ready to go, though, this is the window you will see:
XAMPP is now installed on your computer.
Step 3: Configure Your XAMPP Environment
Click the “Start” button inside your XAMPP app to initialize the setup of the local environment. The Status light will change from red to yellow to green:
XAMPP isn’t the only thing that needs to start. Go to the Services tab and do the same thing for each of the stack services until they turn green:
Next, go to the Network tab. You will need to choose where you want your localhost server to live:
Choose from any of the available options and click “Enable”.
Note: If you plan on turning this into a WordPress Multisite, you can only use ports 80 or 443. If that’s the case, you can create whichever one you want to use now or use the workaround later (more on that at the bottom of this post).
One last thing to do is go to the Volumes tab. Click “Mount”.
This will “stick” the localhost to your desktop (you’ll need this later to modify your website’s files).
Step 4: Create a Database
You have just one more thing to do.
Open a new browser tab and type the name of the localhost you enabled. For instance:
You’ll be taken to a welcome page for XAMPP:
To add a new database, click on the phpMyAdmin button in the top-right corner of this page. phpMyAdmin will automatically launch:
Before we add WordPress to the local server, we first need a database for it. Go to the Databases tab at the top of the page.
Give your database a name (use all lowercase letters and underscores instead of spaces). Then, update the drop-down menu from utf8 to Collation. Click the “Create” button when you’re done.
Step 5: Download WordPress
To retrieve the latest version of WordPress, go to the WordPress.org website. Click “Get WordPress” in the top-right corner of the page:
You can download the zip file from the next page:
Step 6: Update the wp-config.php File
Unzip your WordPress files and locate wp-config-sample.php.
This file contains key information about your WordPress website and is what enables WordPress software to store information in the MariaDB (or MySQL) database you just created. However, there’s placeholder information in here we need to update.
Open the file using a text editor.
The following lines need to be edited:
Database Name
Locate this line:
define( 'DB_NAME', 'database_name_here' );
If you don’t remember what you named your database in phpMyAdmin, you can find it here:
Then, replace “database_name_here” with your database’s name. In our example, the line would become:
define( 'DB_NAME', 'my_database' );
Username and Password
Next, locate these two lines:
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
Replace “username_here” with “root” and leave “password_here” empty. So, the lines should now read:
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', '' );
When you’re done, save the file and rename it as wp-config.php. Make sure it’s inside the original WordPress file folder.
Step 7: Install WordPress on the Localhost
To install WordPress locally, you need to move your downloaded files (unzipped) — including the new wp-config.php file — to XAMPP’s htdocs folder.
You’ll find it here:
Rename the folder if you’d like it to be called something other than “wordpress”. A temporary domain name will do.
To access your new WordPress install, go to the original localhost address you used in the beginning, followed by your new WordPress folder name. Add “/wp-admin/” to the end.
For example:
http://localhost:800/mytestwebsite/wp-admin/
You’ll then see this installation page:
Fill in all of the details — including your admin username and password — and complete the installation. When you’re done, you’ll be taken here:
And that’s it. You’ve now successfully installed WordPress locally with XAMPP.
To access your local site in the future, load the XAMPP app and “Start” the local server. Then go to your localhost web address and log back in. (So, make sure to bookmark it.)
How to Install WordPress Multisite on Localhost
If you want to test things out on a WordPress Multisite network, you can do this with XAMPP as well.
Steps 1-7: Install WordPress Locally
To activate Multisite, you’ll need to complete Steps 1 through 7 first.
Step 8: Activate WordPress Multisite
Open the wp-config.php file once more from the htdocs folder.
Find the line:
/* That's all, stop editing! Happy publishing. */
Just above it, insert the following Multisite activation string:
define('WP_ALLOW_MULTISITE', true);
Save the file.
Log out of your local WordPress site and log back in again. Go to Tools > Network Setup.
As noted earlier, WordPress only allows Multisite to run through network ports 80 or 443. If you didn’t originally configure XAMPP through one of those ports, that’s okay. Use this workaround.
Go to your XAMPP folder and locate the following:
/(your website folder name)/wp-admin/includes/network.php
Inside this file, there’s a line that says:
if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
This is the reason you might see an error when trying to access Network Setup in WordPress. To fix this, add the port you ended up using to the code. For example:
if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ,':8080') ) ) ) {
Save the file and return to Network Setup in WordPress.
You’ll be asked to give your network of websites a name and designate an admin user.
Then, you’ll see these instructions:
You’ll need to update both your wp-config.php and .htaccess files. If you can’t find the .htaccess file, you’ll have to create it from scratch. Open your text editor, insert the code snippet, and save it to the folder.
Once you’ve saved both of those files, log out of WordPress once more. When you log back in again, you’ll see that WordPress Multisite has been installed locally.
Wrap-Up
It’s never a good idea to build, experiment, or troubleshoot on a live WordPress installation.
In cases where the work you do needs to be pushed to a live site, it makes more sense to use a staging server or subdomain. However, if you’re testing new features, design techniques, or tools, working locally is a better idea. (It’s cheaper, too.)
Thanks to XAMPP, all it takes is 7 steps and no more than 15 minutes to install WordPress locally.
yash
i did this exact same procedure. it worked thanks to you. now when i try to install a theme it says ,”Installation failed: Could not create directory”. what should i do?
Nick Schäferhoff
That sounds like you have the wrong permission level for your directories. You can find a solution here: https://superuser.com/questions/256449/xampp-mac-unable-to-create-directory-error
Sahiba Saluja
Hi! Thank you for these instructions. Everything seemed to go fine till I got stuck at step 4. When I clicked on phpMyAdmin, it didn’t automatically launch but prompted me for a username and password. I don’t remember creating one so now I am stuck at this step.
I went into the documentation to see if I could find something but I am not a developer so hard for me to understand.
Any help will be appreciated!
Thanks,
Sahiba
WebsiteSetup Editorial
Hi Sahiba, it shouldn’t be asking you to log in, but try “root” as the username and leave the password field blank.
Kris
Hi! Thanks for this. The instructions were so helpful, however, I received an error at Step 6 (changing database name and user in the php file). I changed the name accordingly exactly as was shown, but I received “Warning: Use of undefined constant” errors on both of these lines in the php code and could not progress to the WordPress Installation step. I tried removing the single quotes (”) on either sides of the database and user input names and then the WordPress Installation page showed up and allowed me to install WordPress successfully, but the “Warning: Use of undefined constant” errors remain hanging at the top of the website that is now installed on my local.
Do you have any idea how I could solve this? I’ve tried Googling, but I’m technically not a coder so I don’t really understand the jargon.
Nick Schäferhoff
Hey Kris, the single quotes definitely have to be there. You should only change the text inside them. What I would advise you to do is the following:
1. Move your wp-config.php file somewhere else. Make a copy of wp-config-sample.php inside your WordPress installation and rename it to wp-config.php. Then, redo the process of inputting your database name, user, password, and hostname without changing anything else. Save and try if that solved the problem.
2. Alternatively, simply remove wp-config.php from the WordPress installation (don’t delete it right away, just move it somewhere else). Access your local URL, this should trigger the installation process once more. Run through it, giving your database credentials. Don’t worry, your content will not be affected by this.
3. If neither of this solves the issue, make a copy of your entire local installation. Then, delete everything inside the active installation except for .htaccess, wp-config.php, and the wp-content directory. Download a fresh copy of WordPress from WordPress.org and copy and paste all files from there except for the ones you left inside your local installation. If the problem still persists, run though 2. again.
Let me know if the issue persists.
Marc Freed
Suzanne – Thank you for this excellent set of instructions. It worked as you intended it. I would have appreciated a few additional instructions. I am a regular user of the Terminal and I had already been running both XAMPP and mySQL on my Macs for several years. I was unable to locate the local host URL (192.168.64.3 in my case) in the Volumes directory so I had to drag the WordPress files from the Downloads folder into their own folder in the lampp/htdocs folder. I would have preferred to “mv” them but for some reason that I could not identify, it remained invisible to me. Also, I had to start WordPress by using the actual URL (http://192.168.64.3/wp.remoteed.dev/wp-admin/index.php) instead of localhost:8080 where phpMyAdmin opened up from the Apache home page. In the end, it all worked out fine.
Nick Schäferhoff
Thanks for the additional comments, Marc. Glad it all worked out in the end.