Hosting WordPress Locally on macOS for Theme Development

Apple, Coding

Whenever I want to refresh my WordPress website design I like to host the entire site locally on my Mac so I can freely develop things without affecting my live website. It is much faster to modify files locally and instantly see results in a web browser. The alternative is to tweak files locally, upload them, and see how things respond on the live site. That is obviously bad. I don’t update my site too often, and I always seem to forget exactly what I need to do, so I’m going to write down the steps.

Download Everything

I use an FTP program (a very old version of Transmit) to download my entire website to ensure I have all the latest files. This gives me my entire install of WordPress in the “blog” directory. I login to my blog’s admin page and download/export all the data as SQL.

Setup Local Hosting

My machine already has Apache (a free web server, httpd) and mySQL (a database server). If it didn’t, I’d first have to go install those. 

 

At this point I can go to http://localhost and see some page (It Works!).

I open up the config file in vim from the command line with a “sudo vim /etc/apache2/httpd.conf”. The “DocumentRoot” section points to “”/Library/WebServer/Document”.  I comment it out and add a new DocumentRoot AND Document section that points to my local directory. The Document section for my page needs this in order to allow local .htaccess files to work:

 AllowOverride FileInfo

I then “killall httpd” and I can see my local files, but PHP isn’t working. So, this meant uncommenting:

LoadModule php7_module libexec/apache2/libphp7.so

Easy enough, and I can verify it with a simple phpinfo dump. I also use rewrites, so I have to enable:

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

At this point I will start to get database errors on my site when at localhost. So, I need to use phpMyAdmin to setup my database locally and then setup the local copy of WordPress to use the local database server.

phpMyAdmin

phpMyAdmin wasn’t working for me. It gives me php errors locally, and on my server it is returning a blank page.  I downloaded the latest version and that helped me get through these issues.  I could then login to my database with phpMyAdmin.

I used phpMyAdmin to rename my old database. I then created a new with the same name. I used the exported SQL data from my blog to import all the current data into the new database by selecting Import. Of course…this gave me an incorrect format error. It was an XML file, which the blog could import and not phpMyAdmin. So, I had to get phpMyAdmin running on my server and export all the data as a SQL file.  My server setup of phpMyAdmin wasn’t working right, but the Dreamhost site had a way of using theirs. It worked fine to export the database as a SQL file.

Still, I had an Incorrect Format Error. How annoying! These were actually caused by PHP limits on the file upload size. My SQL file was 16MB, but the max upload size was smaller. I had to create a php.ini file in “/etc/php.ini” (copied from the defaults file in the same directory) and edit these two values:

upload_max_filesize and post-max-size

After that, I could upload my file and get it in the database.

Local WordPress Tweaks

Next, wp-config.php to point to my local database.  After that was done, I was seeing content!

Redirect My Domain

The next problem is that it was still fetching a lot of stuff from my domain (corbinstreehouse.com). I needed it to fetch stuff locally, so I edited /etc/hosts to have 127.0.0.1 point to www.corbinstreehouse.com. Then stuff worked! I verified it with a peek at my access logs: open -t /private/var/log/apache2/access_log.

I also had some issues with uploading test files because my ‘uploads’ directory wasn’t writable by the web server. That was easy to solve with:

sudo chown -R www uploads/

When I’m Done

My TODO list to restore my machine back to normal:

  * Fix /etc/hosts to not redirect
  * Make sure my wp-config.php is correct; this is only necessary if I upload it again.
  * Turn off mySQL in System Prefs



Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Subscribe to new posts:

You'll get an email whenever a I publish a new post to my blog and nothing more. -- Corbin

As an Amazon Associate I earn from qualifying purchases.

(c) 2008-2024 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

69 queries. 0.186 seconds.

Log in