How To Install WordPress Locally On Ubuntu 8.04 Hardy Heron
It is in fact possible to install a fully functional version of WordPress on a desktop PC running Ubuntu Linux 8.04 Hardy Heron. Obviously, this makes a superb environment for testing and experimentation; you can tweak with WordPress to your heart’s content and not worry about rendering your main blog inoperable. If you need to run an internal corporate blog of some kind, hosting WordPress on an Ubuntu box or virtual machine is a cheaper solution than more expensive blogging or collaboration software. Or, if you’re really ambitious (and you can afford the bandwidth), you can host an Internet-accessible WordPress blog out of your apartment.
(If you’re using Ubuntu 7.10 Feisty Fawn, see my guide for installing WordPress on 7.10 here.)
Let’s begin!
First, install Ubuntu into your machine of choice. I used a VMWare virtual machine for this test, running in VMWare Player, set to use 512 MB of RAM and one processor core. Be sure to fully update Ubuntu before installing (go to the System menu, then to Administration, and select Update Manager). Once Ubuntu is fully updated, you will need to install five pieces of software: the Apache web server, the MySQL database server, PHP version 5, the MySQL module for PHP, and finally the WordPress software itself.
First, open up a Terminal window (Applications, Accessories, Terminal), and type the following command (note that all Terminal commands are shown here in bold, and that all Terminal commands are case-sensitive):
sudo apt-get install apache2
Follow the prompts to install Apache. Once the installation is finished, you can test that Apache is working by opening up Firefox and navigating to http://127.0.0.1. If it works, you should see something like this:
Next, you’ll need to install MySQL. Return to the Terminal and type this command:
sudo apt-get install mysql-server-5.0
During the installation you be will asked to provide a root password for MySQL. Be sure to pick a strong password (a combination of lowercase, punctuation, and uppercase letters), since the root user has full access to all tables on all databases. For obvious reasons, you’ll want to remember this password, not least because we need it again in the following steps.
Next, install PHP version 5:
sudo apt-get install php5
Install the MySQL module for PHP:
sudo apt-get install php5-mysql
Finally, download the WordPress software to your Desktop. You can obtain it from this address:
http://wordpress.org/latest.tar.gz
Now that we’ve got our software installed and downloaded, we’ll need to configure it.
First, you’ll probably need to add a line to your /etc/apache2/apache2.conf file. I have read differing things about this; some people claim it isn’t necessary. I have found in my own testing that WordPress would not function properly without it, since Apache did not properly interpret the PHP pages otherwise. To edit apache2.conf, use the following command:
sudo gedit /etc/apache2/apache2.conf
(Note that it’s a good idea to back up any system configuration file before editing it. You can do so quickly by using sudo cp /etc/apache2/apache2.conf ~/Desktop to save a copy to your Desktop. You can of course use vi or emacs or the editor of your choice, but most new users seem to prefer gedit’s GUI.)
Once you are in gedit, add the following line to the end of the file:
AddType application/x-httpd-php .html
Save the file and exit gedit.
Now we’ll need to prepare MySQL for use with WordPress. First, you’ll need to execute a command to initialize MySQL:
sudo mysql_install_db
Once this is completed, log into the MySQL command-line client:
mysql -u root –p
Enter your MySQL root user password from above, and you’ll find yourself at the MySQL> local client prompt. First, create a database for WordPress to use:
CREATE DATABASE wordpress;
(Note that all commands entered in the MySQL local client must end with a semicolon to denote the end of the statement.)
Once the database is created, you’ll need to create a database user for WordPress to use. While still in the MySQL command line client, type this:
CREATE USER wordpressuser;
Then create a password for your new user (note that your password will actually go within the quotation marks, and is case-sensitive):
SET PASSWORD FOR wordpressuser = PASSWORD(“password”);
Now that you’ve got your WordPress database and your WordPress database user, you’ll need to grant the user all permissions on the database (again, the password goes within the quotation marks, and is case sensitive):
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY ‘password’;
(Note that this is different from the Ubuntu 7.10 setup; Ubuntu 8.04 requires the ‘@localhost’ be appended after the username.)
Then type exit to quit the MySQL local command-line client.Now that we have MySQL prepared, we can now actually install WordPress. From a Terminal window, proceed to your downloaded WordPress archive (probably on the Desktop) and use this command:
sudo tar –zxvf wordpress-2.5.1.tar.gz /var/www
(Note that the file name will probably change as WordPress is upgraded with different version numbers.)
This will unpack the WordPress files into a directory called wordpress within Apache’s www directory. (Obviously, depending upon how you need to configure Apache, you can put the WordPress files in a different location.) Now that the files are unpacked, you’ll need to configure WordPress to talk to the MySQL database. To do so, you must create a wp-config.php file in the WordPress directory. Fortunately, WordPress includes a handy wp-config-sample.php you can use as a template.
Type this command (assuming you installed WordPress in the www/wordpress directory):
sudo gedit /var/www/wordpress/wp-config-sample.php
Once there, change the following values (This assumes you used the default database names and passwords listed above):
Change putyourdbnamehere to wordpress.
Change usernamehere to wordpressuser.
Change yourpassword here to the password you selected in the GRANT ALL ON wordpress.* TO wordpressuser IDENTIFIED BY ‘password’; command.
Once you have your changes made (after double-checking the spelling, of course), save your changed file to /var/www/wordpress as wp-config.php.
Everything should now be ready. Open up a web browser, and navigate to http://127.0.0.1/wordpress. If you configured everything correctly, you should then be greeted by the WordPress configuration page. Follow the prompts, and you will have a functional WordPress blog installed on a Ubuntu Desktop machine. Congratulations!
One final note: if you configure your blog from a local browser, it will probably set your blog’s address as http://127.0.0.1/wordpress. This is fine if you only want to view it from the host machine, but if you want to view it over the network, you’ll need to change it. Fortunately, you can do so quickly by going Options in the WordPress admin interface, and then to General, and changing the blog’s URL.
-JM
Sources:
Ubuntu Unleashed, by Andrew & Paul Hudson
WordPress documentation at http://codex.wordpress.org/Main_Page
The Ubuntu Server documentation at http://doc.ubuntu.com/ubuntu/serverguide/C/
Individual testing and experimentation
26 Responses to “How To Install WordPress Locally On Ubuntu 8.04 Hardy Heron”
Comment from Skora
Time August 29, 2008 at 12:48 pm
I got up to this line ” mysql -u root –p”, when I ran into trouble. I received this error- “ERROR 1049 (42000): Unknown database ‘–p’ ”
Any ideas?
Comment from Jonathan Moeller
Time August 29, 2008 at 12:52 pm
Skora:
I’d suggest uninstalling MySQL and reinstalling it from scratch, if possible.
Comment from BC
Time August 30, 2008 at 11:37 am
Jonathan thanks for the instructions. Running into problems after following your instructions.
I am ok getting to http://xxx.xxx.xxx.xxx but when I try http://xxx.xxx.xxx.xxx/wordpress I get the following message:
You have chosen to open
which is a: application/x-httpd-php
from: http://xxx.xxx.xxx.xxx
Comment from BC
Time August 30, 2008 at 12:06 pm
I figured it out….
Hard to clear the Firefox cache. But ran into other problems.
I figured it out with this url
http://mysecondbrain.wordpress.com/2008/05/25/setting-up-wordpresss-on-a-fresh-ubuntu-804-install/
Thanks in advance
Comment from Halibutt
Time September 4, 2008 at 6:14 pm
Sadly, I ran into problems immediately after installing Apache2. sudo apt-get install apache2 works just fine, but the test fails, as firefox tries to download the .phtml file instead of opening it. I wonder what’s wrong, as no solution seems to work for me (yeah, I tried clearing the cache).
Cheers
Comment from Halibutt
Time September 4, 2008 at 7:48 pm
Thanks a lot. Works like a charm in Opera, though Firefox seems to have a problem with downloading files. BTW, the proper synthax for setting a db password is mysql> SET PASSWORD FOR 'wordpressuser' = PASSWORD('beta2beta2'); (single quotes instead of double ones)
Cheers
Comment from Halibutt
Time September 4, 2008 at 7:54 pm
Oh, and another update: in 8.04 indeed the ‘@localhost’ needs to be added. However, then the entire wordpressuser@localhost’ name is too long, one needs to make it shorter than 16 digits. Just a note for all those who wanted to follow the instructions too closely
Comment from #€|!0$
Time November 13, 2008 at 11:43 am
Thanks for the post… It really helped me out…
Btw in ubuntu u need to grand full access permission to the wp-content folder so that wordpress can easily update it… In terminal go in the directory of the wordpress in /var/www/ then
sudo chmod -R 777 wp-content
Comment from pete
Time February 17, 2009 at 11:32 am
I’d like to try this for testing the WordPress forum (*), rather than their blog. Presumably the procedure is just the same?
(*http://bbpress.org/)
Comment from ivanky
Time February 18, 2009 at 10:09 pm
Thanks for the post, i was now in the step where I need to create my wordpressuser, however I have already had a username.
I typed:
mysql -u root –p
CREATE DATABASE wordpress;
CREATE USER wordpressuser; (I have already had a username, can I skip this step then?)
Comment from morchoe
Time May 17, 2009 at 5:40 pm
I am having a problem unTaring wordpress. have you any ideas what I am doing wrong. Thanks for your time.
*******@*********:~/desktop$ sudo tar xzvf wordpress-2.7.1.tar.gz /var/www
[sudo] password for *******:
tar: /var/www: Not found in archive
tar: Error exit delayed from previous errors
Comment from romonoeroetoko
Time July 8, 2009 at 10:16 am
Hm that sounds good but I would like to know more details.
Comment from Richard
Time September 17, 2009 at 7:51 am
Thanks for the help. I’ve been stumbling with setting up a local host on Ubuntu for a while, and this post really helped.
Here’s a tip that might help other folks: when copying the commands, remember that sometimes the quotes don’t copy and paste correctly. You sometimes get the ”curly quotes” when you want the “straight quotes”.
Pingback from Wordpress on Ubuntu « TeamJuchems
Time September 17, 2009 at 8:41 pm
[...] http://www.jonathanmoeller.com/screed/?p=235 [...]
Comment from Seth
Time September 20, 2009 at 8:41 pm
You should have the command
sudo /usr/bin/mysql_secure_installation
instead of sudo mysql_install_db
I’m a beginner, but I just ran your command and noticed in the comments that MySql recommended running the other command in production environment, so that the anonymous user and the test database, that anybody that can have access to, isn’t created. Might as well have every one get in the habit of doing that, even if it is firewalled in a private environment.
Comment from George
Time October 28, 2009 at 10:25 pm
Hi,
I had to use single quote for specifying password.
Also, while trying to untar wordpress directly to /var/www, it gave this error.
tar: /var/www: Not found in archive
tar: Error exit delayed from previous errors
I untared it at desktop itself and sudo moved it to /var/www.
Other than these two things, everything worked, and I have my blog up on my PC. Thanks a ton Jonathan!
Comment from Jvalro
Time November 7, 2009 at 8:28 pm
hey guys when I try to unzip the wordpress file I got this:
laptop:~$ sudo tar -zxvf wordpress-2.8.5.tar.gz/var/www
tar: wordpress-2.8.5.tar.gz/var/www: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Exiting with failure status due to previous errors
Please help thanks guys!!!
Comment from ckoch
Time November 20, 2009 at 5:08 pm
Jvalro,
I had the same problem so what I did was extract the wordpress tar file on my desktop. Then I used
sudo mv wordpress-2.5.1. /var/www to move the extrated file, if this does not work try sudo mv wordpress /var/www.
Comment from ckoch
Time November 20, 2009 at 5:10 pm
hi
I am having a problem with getting wordpress to install… I can get to the /index of wordpress but then I cannot do anything and I cannot open the wp-admin/install.php to open in my browser.
Thankyou for any help
Comment from ckoch
Time November 20, 2009 at 5:12 pm
I forgot to post this in my last post but when I restart apache I get this message at the end
* Restarting web server apache2 Syntax error on line 299 of /etc/apache2/apache2.conf:
AddType requires at least two arguments, a mime type followed by one or more file extensions
Comment from kay man
Time December 15, 2009 at 3:46 pm
hey man… thanks for the great post… worked perfectly… I’ve never used MySQL b4 either… lol
Comment from Aswin
Time January 5, 2010 at 9:20 am
Thanks a lot. I have been trying to do this for a long time.
Pingback from Coming home – the ideal blogging solution
Time July 30, 2008 at 8:10 am
[...] by: http://www.jonathanmoeller.com/screed/?p=235 Also check here: [...]