How to Set Up a WordPress Local Web Development Testing Environment in Ubuntu Gutsy

Full disclosure: I’m not a Linux expert but I am somewhat competent. I followed directions on sites linked throughout this article and then used a little common sense. On a scale of 1-10 (with 1 being the difficulty level of changing your desktop background) I rate this exercise a 6. It’s a little lengthy only because I tried to spell out exactly what I was doing each step of the way.

This tutorial covers how to install WordPress on Ubuntu Linux in a local hosting environment. Though as you’ll see you can install any other CMS with this same method.

After a comment from Stuart on a previous post I decided to try to create a local web development testing environment in Ubuntu using the tools already available in the repositories. Turned out to be a little harder than using XAMPP but (and this is a big butt) doing it this way will yield more control on your part and your installation will benefit from general Ubuntu updates.

Step 1: Install Apache2, MySQL & PHP5

These instructions are taken verbatim from this helpful article. Why retype the wheel? Open up a terminal and execute this command:

sudo apt-get install apache2

Then, install PHP5:

sudo apt-get install PHP5

Then install MySQL with PHP5:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

At some point in the above installation of MySQL you will be asked to assign a password for the root user. Keep it simple, this isn’t going to be a public server. OK, so now at this point you should be able to access http://localhost. I mean, when you go to that address you shouldn’t be looking at an error page.

Install phpmyadmin

Now, this step isn’t documented anywhere I could find, and maybe it’s not even necessary. I wanted to install phpmyadmin because frankly, I’m used to it. Just open your Synaptic Package Manager and search for “phpmyadmin” and install it.

Now you should be able to create a database for your WordPress installation by going to http://localhost/phpmyadmin. All you need to do is create a database because your user “root” and your password (assigned above) are already in place. I called my database “wordpress”.

Create a “sites” directory

Create a directory within your home directory. Call it whatever you want, I’m calling it “sites”. This will hold all my development sites.

By default, Apache doesn’t know that you’re going to be using the “sites” directory for your localhost development files. You have to tell it this. Thanks to Vinno and the help he gave me on the Ubuntu Forums thread I started I found this to be fairly easy to do.

Open up a Terminal and edit your default file:

sudo gedit /etc/apache2/sites-enabled/default

That should work for you. For me, however, it did not work because the default file did not exist. For some reason it was called 000-default so I had to edit it like this:

sudo gedit /etc/apache2/sites-enabled/000-default

Odd, I know. At the top of the file you should see this:

NameVirtualHost *
<VirtualHost *>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>

We’re going to point the DocumentRoot to our /sites directory; eg. DocumentRoot /home/YOUR USERNAME/sites/. Then restart Apache:

sudo /etc/init.d/apache2 restart

There should be no errors.

Install WordPress

You’ve created the /sites directory and told Apache that this is where you’ll be keeping your localhost files. This is where we’ll now put all our WordPress files.

NOTE: If you only wanted one WordPress installation then you’d just dump all the WordPress files into this /sites directory which could then be accessed at http://localhost.

However, I want to keep all my WordPress sites separate (and I also want to install Texptattern later) so I keep them in their own directories. The naming convention I use was taken from the book Textpattern Solutions. I name the directory the same name as the site I’m working on but call it “.dev” instead of “.com”. So here’s what my local file structure looks like:

/home
  |_ /ben
      |_ /sites
         |_ /wordpress.dev
            |_ /wp-admin
            |_ /wp-content
            |_ /wp-includes
            |_ index.php
            |_ wp-app.php
            |_ wp-atom.php
            |_ wp-blog-header.php
            |_ wp-comments-post.php
            |_ wp-commentsrss2.php
            |_ wp-config.php
            |_ wp-cron.php
            |_ wp-feed.php
            |_ wp-links-opml.php
            |_ wp-login.php
            |_ wp-mail.php
            |_ wp-pass.php
            |_ wp-rdf.php
            |_ wp-register.php
            |_ wp-rss.php
            |_ wp-rss2.php
            |_ wp-settings.php
            |_ wp-trackback.php
            |_ xmlrpc.php

OK, now go about the normal process of installing WordPress. Visit the location of your WordPress installation. In this case it would be http://localhost/wordpress.dev. It’ll tell you that you have to install WordPress. Do so with the normal installation method and remember that your username is “root”, your password is whatever you choose when you installed MySQL above, your database name is whatever you created in phpmyadmin (in my case “wordpress”) and you’re at “localhost”.

So now, I could access my WordPress Dashboard at http://localhost/wordpress.dev/wp-admin. Simple, right? Of course it is.

NOTE: If you have any questions I may or may not be able to help you. The forum thread I opened is located here and those folks are much more knowledgable than me. If you find errors in this tutorial please let me know by leaving a comment or contacting me so I can remedy the mistake.

Pagan Christianity

14 Comments

  1. Caleb
    - January 18, 2008

    Thank you for this!

  2. Juampa
    - February 17, 2008

    Nice post!. By the way, you just forgot to say that, in addition, one has to change the line to (in case you want DocumentRoot to point to just that folder).

  3. - February 27, 2008

    Hey Ben,
    I encountered few problems

    1. when I try \”sudo apt-get install PHP5\”
    I get an error: E: Couldn\’t find package PHP5

    2. when I go to http://localhost I don\’t get an error, but I do get one when I go to http://localhost/phpmyadmin
    even tho I installed phpmyadmin as you wrote.

    Any tips for a Ubuntu newbie?

    (running Ubuntu 7.10 Gutsy, with E17 as Window Manager)

  4. - February 27, 2008

    [...] openswitch subv3rsive living Skip to content « FP’s, DE’s and Linux How to set up a WordPress local web development testing environment in Ubuntu Gutsy » [...]

  5. - February 27, 2008

    @Sunlust: My first piece of advice would be to ask these questions on the ubuntu forums. But other than that make sure you have all your repositories enabled to install PHP5 (though I\’m not even sure that\’s necessary). As for the phpmyadmin thing, that\’s just odd. I think your best bet would be to ask these questions in the forums. Oh, and when you do please let us know where the thread is located so we can all learn from it. :)

  6. duckgoesoink
    - February 28, 2008

    Hi Ben,

    How do you go about using phpmyadmin once the DocumentRoot has been changed?

    Cheers

    P.S. In Feisty you can use Tasksel to install the default LAMP stack - is that not possible with Gutsy? (I run Feisty and found Taskel made a LAMP installation very easy.)

  7. - February 28, 2008

    I\’ve used XAMPP but never heard of Taskel. They fundamentally accomplish the same thing.

    I didn\’t notice any change to the way I used phpmyadmin when I changed the DocumetRoot.

  8. duckgoesoink
    - February 28, 2008

    I semi-followed your instructions (I like the idea of finding the separate sites at http://localhost) but lost my link to phpmyadmin until I copied the folder to my sites folder - don\’t know why I didn\’t think of that a few hours ago.

    RE: Taskel - the difference between XAMPP and Taskel is that Taskel is included in the Ubuntu base system. I\’m not entirely sure, but I think it would benefit from general Ubuntu updates. I discovered it here - https://help.ubuntu.com/community/ApacheMySQLPHP

    P.S. Thanks for the helpful article!

  9. duckgoesoink
    - February 28, 2008

    Whoops, sorry typo - I mean Tasksel.

  10. - February 28, 2008

    Re: Tasksel - that\’s really interesting. I had never heard of it.

  11. - February 28, 2008

    Hi Ben,

    I followed this on my ubuntu box and it worked out quite well.

    What are your thoughts on a similar approach to local development on OS X? Do you use your iMac for development or just for play?

    Thx

  12. - February 28, 2008

    No, my iMac is my primary development computer. I use MAMP for my localhosting environment on my iMac.

  13. - February 29, 2008

    sweet! downloading now. This looks promising, thanks a bunch!

  14. - February 29, 2008

    Yeah, and it\’s even got a dashboard widget.

Post a Comment

Your email is never published nor shared.

Archives

2008: 01  02  03  04  05  06  07  08  09
2007: 01  02  03  04  05  06  07  08  09  10  11  12
2006: 01  02  03  04  05  06  07  08  09  10  11  12
2005: 11  12