Installing WordPress with Security in Mind

January 14, 2011 — 165 Comments

[This post is part of the Ultimate Guide to Launching a WordPress-Powered Blog series.]

We have to, of course, start at the beginning and as you all know the beginning is just as important as the end!

Installing WordPress has become incredibly easy – in fact, sometimes I believe it’s become too easy because it creates a “path of least resistance” and doesn’t help educate a new user with all of the other options that exist for installing it to maximize security settings and the like.

But it is what it is, right? I’m very thankful that the installation process for the average user is near-dummy proof, especially if you’re hosting provider has a 1-click install process! But, you’re not the “average” user, right? (Or you don’t want to stay an “average” user for very long!)

So let’s get started.

A Few More Assumptions:

Sorry! But, to make it to this point I assume that you have the following:

Of course, if you need any other help the WordPress Codex has nearly all the information that you’d ever want! Check it out here.

TentBlogger’s Secure WordPress Install Process:

For the most part I suggest that people follow the famous “5 Minute Installation” process but with a few more steps that I’ve added for security purposes. It is vital that you keep your installation safe and secure from hackers and malicious bots!

There’s no reason not to do this!

Ready? Here we go:

1. Download WordPress:

Download and unzip the WordPress package, if you haven’t already.

2. Upload WordPress to Server:

What you’ll do next is upload the WordPress folder contents to your domain. You can use any tool you’d like to do this (check out the FTP tools I use here).

There’s a few things to do here to maximize security though:

  1. Put it in a sub-folder instead of the root directory. Name it something somewhat obscure and unrelated to anything “admin”. For example, you could do something like http://tentblogger.com/icecream
  2. Move the index.php and the .htaccess files from the “icecream” folder and into the root.
  3. Open up the index.php file and change the line that says ” require(‘./wp-blog-header.php’); ” to this ” require(‘./icecream/wp-blog-header.php’);
  4. Once you install WordPress then you’ll have to go to your Admin area in the back admin and change the General Settings so that the “WordPress Address (URL) points to http://tentblogger.com/icecream and have the “Blog Address” point to http://tentblogger.com (in this example).

Check out the following screenshots to see what the above 4 bullet points look like:

Example Secure WordPress File Structure

Expand it you’ll see that the folder icecream has the WordPress core files (except index.php and .htaccess):

Expanded view

Changing the index.php line:

Before...

and…

After...

Finally check the General Settings after you install:

Don't forget to do this step!

As a result of all this you’ll have the most secure folder structure available!

In the above example I’d have to login here now: http://tentblogger.com/icecream/wp-admin

Congratulations my friend!

3. Create MySQL Database, Username:

Setting up your MySQL database is entirely dependent on your existing hosting provider. For many it’s a few clicks and you’re done.

Here’s how I do it in MediaTemple (which hosts TentBlogger) as well as Dreamhost (another great and simple hosting provider for new blogs and one that I use for clients):

Media Temple Setup:

Login to MediaTemple:

Heading toward the Control Panel:

Log into Plesk:

Head to the domain that you’re going to install a MySQL database:

Create a new database. Two things to do here to maximize security:

  1. Name it something complex.
  2. Name it something completely unrelated to the domain and URL.

For example, I might name TentBlogger.com’s MySQL database something like “iL1Xtto723″. Pretty hard to guess, right?

Then we can add a username. Make sure you follow the same convention above and make it a bit complex and perhaps unrelated. Of course the caveat is forgetting your unique username and password, but you’ll have to write it down and secure it safely!

If you need a good password get one here.

Now that you’ve created the MySQL database you’ll use this information to install WordPress!

Dreamhost:

Login to Dreamhost:

Create a new MySQL Hostname for the database:

Create the hostname:

And then you can create the username:

Remember the aforementioned thoughts about the naming conventions for your database and your username/password!

4. Run the WordPress Install Script:

Now just head to where you installed the WordPress files (in this case http://tentblogger.com/icecream) and walk through the guided instructions.

Then input your “crazy” information:

And then you’re done! Remember that if you’ve installed it in a different folder then it would look like this:

1
http://example.com/blog/wp-admin/install.php

Finally you’ll want to make sure you do two things:

  • Change the Table Prefix to something other than “wp_” since most hacks will try to attack this prefix because most people don’t change it from the default.
  • Do not use ‘admin’ as the default username. Change this!

Great!

5. Check It Out, Publish Something:

The next step is quite simple – check everything out! Just start clicking around the admin panel after you login and make sure nothing “breaks”. I’ve never had an installation break right out of the box but you don’t want to be using a broken system to it’s worth checking things out.

The next step is also quite simple; publish something! Just go to Posts >> Add New and type in a Title, some random copy in the content area, choose (or add) a category, and then hit the big blue “Publish” button! If anything breaks it’ll break here as well.

Sweet! You’ve got a secure installation of WordPress installed and you’re ready to start customizing it for awesomeness!

[This post is part of the Ultimate Guide to Launching a WordPress-Powered Blog series.]

John

Posts Twitter Facebook

I'm passionate about startups, blogging, and human capital. I love what I do and who I get to work with. I am incredibly blessed.


165 responses to Installing WordPress with Security in Mind

  1. I need to start doing it this way!!!

    One thing, I may have missed something, but dont you create the db first in order to install wp?

  2. (in Toy Story T Rex voice) Ouch!! I have set up three blogs now, and I feel so insecure!

    Well, this was an eye opener about security. At least I installed the security keys in my config file.

    Now I have to go back and change a lot of things, because I am definitely serious about security. I have already had one website compromised to the point the server had to nuke it. Don’t want to repeat that mistake again.

    Thanks John for the warning and good instructions.

    By the way, I have all three blogs on one server. Are there any disadvantages to this?

  3. I’ve read that changing the DB prefix is also a good safety measure. I changed mine for good measure, but still wonder what, if any, security that added. Any insight?

    Also, would you consider ‘localhost’ a bad location for your DB even if the MYSQL port isn’t open?

    Lastly, as Mutant mentioned, the ‘security keys’ in the wp-config file. What exactly do they do?

  4. Another important thing to change is the default username “admin”.

  5. Tried doing this, but all of the images posted are still trying to point to the old directory so I get a fat red X. Is there a fast way to have all images in the posts point to the new directory, or do I have to go in one by one and change it?

    • ben,

      ah. you’re going to have to redirect your images via .htaccess (one possibility).

      you know how to do that?

        • what is your current file structure and what got changed?

          • Current file structure = wp install is in a folder in the root, and I want to move it all one level deeper so that instead of site/wp-content/uploads, it’s site/crazyname/wp-content/uploads.

            Trying to be more secure.

          • Got the redirect going, but I can’t figure out how to keep the URL from displaying my super secret folder…yet.

            • John Saddington January 16, 2011 at 4:10 AM

              ah. what you can do actually is this: you can change the upload point anywhere you’d like and have the images pull from there.

              just goto Settings >> Media

              and specify the folder:

              http://cl.ly/3i1N0Z0a3E1s0E100I1R

              • I’m almost there, I have like 3 or 4 redirects in the .htacces which include images in posts, as well as some of the sidebar images but I can’t get the sharing buttons to hide the “icecream” folder in the url for some reason. I didn’t mean to hijack these comments but I feel like I’m just missing something obvious here.

                • John Saddington January 17, 2011 at 3:26 PM

                  hiding the wp-content folder isn’t an issue from a human perspective.

                  it’s from an auto-bot perspective. if someone wants to find your login they’ll find it. but taking it outside the default saves your butt!

              • Could you show a screenshot with the filed filled in? So that it stores in “icecream/wp-content/…” but only shows the “wp-content/…” Im confused as to what goes where.

                • John Saddington January 20, 2011 at 6:48 AM

                  You must enter a folder relative to your WordPress address (URI) folder.

                  So, not wp-content but something else.

  6. Seems pretty straight forward to do it with a new install. But how big of a headache is it to switch it to the more “secure structure” on a blog already installed with a few years of archives?

  7. So, can you make these changes to existing blogs? Moving files to /icecream and have index and .ht in the root without messing anything up?

  8. I created a sandbox on one of my EC2 servers, and I have one tiny issue. The super-duper-secret ‘icecream’ folder is visible in the source because of all the theme files…is that normal or can that be changed?

  9. There’s a very helpful article in the WordPress codex on Giving WordPress Its Own Directory for those that wish to do this to an existing WordPress installation.

    (Related in codex: Moving WordPress.)

  10. Thanks so much for this series…its really informative.

    Any chance you could do a walk through for adding your database recommendations to an existing blog?

  11. Just did it for a new install. Pretty smooth. Now to figure out the “salt” options. And if I can do all this retroactively on a WP install that’s been in place a while. It is just a matter of moving things to an “icecream” folder and changing the “general settings” and the line in config.php?

    Now with a new install and another that needs an update, time to count my coins to see if Standard Theme is next for me.

  12. I followed the steps of the installation, but wasn’t able to find the .htaccess file… Is it a hidden file, or am I just looking in the wrong place?

    I have the same WordPress version used in the screenshots, and using DreamHost for the hosting…

  13. Maybe that’s my issue. So it gets created when you run the wp-admin/install.php in the browser? Sorry…so many questions. Thanks.

  14. Great installation tutorial, but not too up on security. There really is a lot of things people can easily do to “lock down” their wordpress blog or site without compromising speed or quality. From watching for too many logins to making the most out of .htaccess.

    There are a number of plugins and other ways to secure wordpress very quickly that anyone hosting the software should look into on day 1.

  15. Great site John. Signed up on your social media. Will do your standard theme shortly. I started with your installing WordPress for security, renamed my file folder, but for the life of me, cannot locate any .htaccess file to move back to the root. I”ve done ‘er 3 times. Where is that file hiding? :)

  16. Great article, great series. Not sure if someone covered this in a comment, but

    doesn’t work. These files should be COPIED into the root and left alone in the “icecream” folder.

    Codex reference is here: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

  17. I goofed up on step 4 of part 2 above. In the WordPress admin area I changed BOTH the “WordPress Address” and the “Blog” address. Now I cannot access the admin panel to change it back.

    PLEASE HELP!

    The install directory is http://coveybox.com/birdpress

    I changed both to http://coveybox.com.

    How can I fix this and what should I have done? The goal is for the blog to be displayed at the root url (http://coveybox.com).

  18. Hey I was wondering if it would be possible for you to do this with Site5 hosting?

  19. Taryn Saunders April 26, 2011 at 3:25 AM

    Ok… great admission… but I’m new to all of this. Once I’ve created the mySQL database… how do I go back to check that I set it up securely? (The joys of starting and then having a break to give birth and coming back to things with a VERY fuzzy brain!)

    • Taryn Saunders April 26, 2011 at 5:49 AM

      And now I’ve broken the ENTIRE thing!!! :-( I was following the steps… At #2.4 it all came unstuck as it says it’s all broken! Site won’t display and can’t login to it :-(
      So I backtracked, reversing each step as I went… but it won’t work now either! What have I done???

  20. I am on blogger and bought my domain; but I feel very limited with my template in adding my sponsor buttons, so I think wordpress would be a good switch for me. Do I really need to pay for a host? I am just starting out and not making enough to pay for a host, but I really want to make the switch. What should Id o?

  21. Hey John,

    I’ve done this a couple times now and I have a suggestion. It doesn’t look like .htaccess is included in the WordPress zip file (I’ve looked a couple times and have shown hidden files on my Mac). That really slowed me down the first time, but I’ve just skipped that step and haven’t had any problems. You might just add a line something like this: (if you don’t see an .htaccess file that’s ok, just continue with the rest of the steps below).

    I doubt most first-time installers of WordPress will be dabbling with .htaccess for a long time anyway (I haven’t and I’ve been using WordPress for about 5+ years).

    Just a suggestion.

  22. Thanks so much for this article! I have been a long time reader/lurker on here since the beginning. I finally took the plunge and set up my own wordpress site. Thanks again for your great articles.

  23. Danny De los Reyes July 28, 2011 at 4:16 AM

    I’m having trouble finding the .htaccess file

  24. I am new to word press and using your guide…i am using coda and setting up the security like you outline…in my wordpress folder I downloaded and there is no .htaccess file…I found and moved the index.php but there is no .htaccess file? what am I missing?

  25. sorry i should have just looked at the above post…im a greenback

  26. sorry still not seeing the .htaccess file…im using coda too

  27. I got it all up and running…was gonna just do the easy install on dream host…but said why not set it up manually…Im trying to learn this stuff

  28. yep…now i’m ready to install Standard Theme

  29. I am not able to run the WordPress installation script because I need to create my own wp-config.php. I do not know how to do this :/

    Could you possible help me?

  30. Not sure I understand full how to “hide” the icecream folder as long us the image path still shows it :-) .
    Let’s say I create another folder called myimg in the root directory (public_html) and I want WP to upload my pictures there. What should I put in the Media Settings>Uploading Files settings? There are two fields there: Store uploads in this folder & Full URL path to files…how should I fill in these fields to be able to upload images to http://mywebsite,com/myimg?

  31. Hi John,

    I’ve successfully installed WP but there’s a little cosmetic issue that i hope you can address.

    Whenever I search for mydomain.com I get directed to mydomain.com/icecream

    How do I get rid of the /icecream ?

    I’ve look through the WP forum and tried several suggestions (plugins ,etc) but nothing works.

    Pls advise.

    Thanks Andrew

  32. I’ve messed things up. I went ahead and changed the WordPress URL before I uploaded the new folder. So now when I try and login from either my orginal “theminnesotaman.com/wp-login.php” or from the new one “theminnesotaman.com/coreyspooner/wp-login.php” it fails to work. And I can no longer get into my settings to change it back. Is there any way to save the situation or do I need to create a whole new database?

  33. Any chance you can explain using site5

  34. what do you mean specifically?

  35. I currently have a development directory set up as I build out my wordpress site. I have a live site at http://www.myurl.com and the dev site is in another directory at dev.myurl.com.

    I was just planning on changing the WordPress Address (URL), and Site Address (URL) in the General Settings from http://dev.myurl.com to http://www.myurl.com and have the host point to the new directory.

    Are there any issues with this set up before I start messing around with moving the wp-content directory, etc?

  36. Thank you for the tutorial. Very helpful.

    I was following the example but was confused about one thing. In step 2 you state

    “Once you install WordPress then you’ll have to go to your Admin area in the back admin and change the General Settings so that the “WordPress Address (URL) points to http://tentblogger.com/icecream and have the “Blog Address” point to http://tentblogger.com (in this example).”

    I’m confused as WordPress has not been installed or activated but according to your instructions I have to login to the admin area.

    I might be missing taking a step or something. Please let me know what I’m doing wrong.

    • For the benefit of others – I have tried the steps and the work.

      As far as changing the URL’s is concerned you can change them after the installation. In short just run through the installation and once the installation is done log-in to the back-end and use the General Settings options to change the URL’s.

  37. I have a fairly new blog, less than a month, and so wish I had used WordPress. I did buy my domain. For a noncomputer geek, I think all this may be way too complicated for me but I did enjoy your article. I even got to the part where I did download wordpress but my confidence in following the other steps waned and I turned back

  38. Help! I am very new to this and am trying to be meticulous about following instructions here… I went through my webhost (Site5) and downloaded word press putting it in an “icecream” subfolder. But I can’t seem to figure out how to get to the next step. Could it be because I downloaded wordpress through the webhost instead of uploading it from my computer?

  39. If I use bluehost and dont want to and dont need to download wordpress, what do I need to know about security? It makes a MySQL for you, etc. Do I need to download onto my computer and use a FTP tool to be fully secure? Isn’t the point of Bluehost supposed to minimize all this? I am knew to this, so just send me to a link if its explained already.

  40. Hi, tried the steps three times and it seemed I finally got it right but…

    Whenever I want to visit the site the main, sample and a post page I created all display “futuro home of something quite cool”. When I add www. to my domain I get a 404 error.

    I ended up putting the installation in a sub-subfolder. mysite/icecream/icecream 2

    Could that be the problem?
    I did that because I saw in the image in this post that the installation was in tentblogger.com/httpsdocs/icecream

    then I moved the index and htaccess files to mysite/icecream wich I guess is a subfolder on the root and not the root itself.

    Any idea of what I should do?
    Start allover and use just one subfolder?

    Thanks

    • And the fourth time it worked, What I did was install wordpress in a subdirectory and not one level deeper as I did before. Now, I can see my site at example.com but not when I go to http://www.example.com. I’ll try to figure that out, maybe it’s something obvious but if anyone’s got a fast answer? Thanks again

      • Oh, I think it was the CNMA record www; my domaing was previously directed to a google sites page. I just changed it to @. Now, let’s wait a while and see

  41. Thank you for the detailed instructions.

    I wanted to know whether the steps recommended in the blog post at http://tentblogger.com/more-wordpress-security/ can be followed even if the installation has been done as per the process outlined in this post?

    Thanks in advance.

Leave a Reply