Setting up Wordpress locally from scratch on OSX El Capitan

Kevin Salter
Kevin Salter’s Blog
3 min readAug 24, 2016

This post is a note to self more than anything, but if you’re like me and find yourself in the situation where you need to stand up a local Wordpress site (for one reason or another) roughly once a year, these notes should help to alleviate some of the pain.

1. Create a ~/Sites folder.

2. Download Wordpress https://en-ca.wordpress.org/download/ into ~/Sites, unzip the file and rename the folder from wordpress to my-wp-site (or whatever your project is named). Or, if you have a pre-existing Wordpress site, put it in this folder.

3. You can create an .htaccess file in the root of the project and add this content:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ — [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

4. Open /etc/apache2/httpd.conf and make sure the following lines are uncommented:

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so

…then find <Directory /> and add:

<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>

…then find this block that begins with <IfModule unixd_module> and add your username (type whoami on the command line if you’re unsure of your username) and comment out the defaults.

<IfModule unixd_module>
#User _www
#Group _www
User yourusername
Group staff
</IfModule>

5. Create a virtual host by opening /etc/apache2/extra/httpd-vhosts.conf and add this near the bottom:

<VirtualHost *:80>
DocumentRoot /Users/username/Sites/my-wp-site
ServerName my-wordpress-site.dev
</VirtualHost>

6. Update /etc/hosts by adding this line to the end of the file:

127.0.0.1 your-wordpress-site.dev

7. Restart Apache so that our changes take effect by running this from the command line:

sudo apachectl restart

8. Visit my-wordpress-site.dev in your browser and you should see a message saying Error establishing a database connection.

9. Create your wp-config.php file and add the correct info:

define('DB_NAME', 'name_of_your_wp_database');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your-password');
define('DB_HOST', '127.0.0.1');

10. There are a number of ways to set up MySQL, but here’s how I’m doing it these days. Download and install Docker https://docs.docker.com/docker-for-mac/

11. Install and run a MySQL container and create a database user with this long command.

docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=some_password_for_root_user -e MYSQL_DATABASE=name_of_your_wp_database -e MYSQL_USER=your_username -e MYSQL_PASSWORD=you_password -d mysql:5.6

If you’re curious about some of these flags, run:

docker run --help

Check that the container is running with:

docker ps

You can log into mysql from the command line with this command if you want to manually do some admin work to the users or databases, or if you want to import an existing database, etc.

mysql -u your_username -p

12. While in the root of your project, use the local server that ships with PHP and run this from the command line:

php -S localhost:8000

Finally, refresh the page, do a dance, and thank the universe that this is over (until next year?) 🎉

--

--