Setting up WordPress on localhost

Before getting started with WordPress, you will need to learn how to install it on your own machine. This is known as working “locally” as you will be hosting the website and it’s system on localhost.

PHP and MAMP

WordPress is built with PHP, which means all your standard page files will need the .php file extension. Normal html can still be used in PHP files, so you can still write your HTML the same way you would in a .html file.

PHP is a server-side language, so in order to view these files in your browser, you’ll need a server. When building a WordPress site I use MAMP, which allows you to simulate a server environment on your own machine.

If you’re not already familiar with using MAMP, I suggest having a go before beginning to build with WordPress. Once you’ve got PHP files opening in your browser with MAMP, then you’re ready to move to the next stage - installing WordPress.

Installing WordPress Locally

Download the latest version of WordPress from here, place the .zip in your MAMP root folder and extract it. You can find the root folder by going to MAMP preferences > Web Server tab.

Once this is done you should be able to view the standard WordPress setup-config in your browser, the address should be something like this: http://localhost/wordpress/. Choose your language and click continue, you will then be asked to get the following information to link your WordPress install with a database:

  1. Database name
  2. Database username
  3. Database password
  4. Database host
  5. Table prefix

Unlike a static website, the content of your pages will be fetched from a database. Every WordPress install has a corresponding database, this is where the content of your site will be stored stored. In a new tab, open the database handler phpMyAdmin, the address for this is usually http://localhost/phpMyAdmin. From here you can create a new database by clicking “New” in the column to the left. Give your database a name using lowercase letters, numbers or _’s instead of spaces.

You can now go back to the WordPress setup page and enter the database name, the username and password for a local install should both be “root” and the host should be “localhost” (this can also be found on the MAMP start page at localhost/MAMP). Once the database is linked up you can run the install, name your site and set up your WordPress admin user, which you will use to log in to the CMS (Tip: Always avoid using “admin” as your username).

You should now have a working local install of WordPress on your machine! At this point your dashboard login should be available a url like this: localhost/wordpress/wp-admin and your site should be viewable at http://localhost/wordpress/ running the current default WordPress theme.

Thanks for reading, I hope this helps someone out. Let me know on twitter if you found this useful.