Are you new to WordPress? Are you a WordPress theme or plugin developer? Do you need to test things out without having it go live and without having to go through FTP?
WordPress requires a web server with MySQL support, which most bloggers and developers probably don’t have on their own computer. However, WordPress can easily be installed on your own system for private usage and testing.
Why Install Locally Instead of Live to Sandbox?
- It’s the real deal. Themes. Plugins. Everything.
- No internet connection required.
- No FTP needed. Everything is stored on your own hard drive.
- No need to worry about accidentally sending a ping to online services like Technorati.
The Canonical Team provides many flavors of Ubuntu, such as the Desktop edition and the Server edition. Regular users would probably be running the Desktop edition. How would you go about enabling the Apache HTTP Server, PHP, and MySQL? No, you do not need to fully convert to Ubuntu Server.
Time Required: ~30 minutes
Requirements: Basic knowledge of Ubuntu and the Terminal
Apache is the world’s most popular HTTP Web Server and is recommended for use with WordPress. To install Apache, simply run the following command in the Terminal.
sudo apt-get install apache2
Test the installation by browsing to http://localhost in your favorite web browser. You should see a page that says ‘It works!’
MySQL is the database system that is used by WordPress to store all the posts, settings, users, etc…
To install the MySQL server, run the following command.
sudo apt-get install mysql-server-5.1
You will be asked for a password during installation. Make this secure as the root user is able to access all databases and tables.
PHP is a server side scripting language that WordPress is coded in. Simply run the following commands to install the latest stable ersion, PHP5.
sudo apt-get install php5 libapache2-mod-php5
After installation, you should restart Apache using the following command.
sudo /etc/init.d/apache2 restart
Test the installation by running the following. This will create a file named phpinfo.php and open it in gedit.
sudo gedit /var/www/phpinfo.php
Insert the following line into phpinfo.php. Save the file then close gedit.
<?php phpinfo(); ?>
In your favorite web browser, browse to http://localhost/phpinfo.php or http://127.0.0.1/phpinfo.php. If everything worked properly, you should see a PHP Info listing similar to the following.
Install the MySQL Module for PHP
Run this command.
sudo apt-get install php5-mysql
Congratulations! You have successfully installed the web server software! Now it’s time to start installing WordPress.
Create a WordPress Database
Login to MySQL using the following command. Use the password you created earlier when asked.
mysql -u root –p
You should now find yourself in the mysql> client.
Your names can be anything you like. For the purpose of this tutorial, the database name of ‘wordpress’, the user of ‘wordpress_user’, and a password of ‘blogairlines12345′ is used. Do not use this as your password as it is very unsecure.
Let’s start by creating a new database. Please remember that all commands must end in a semicolon or it won’t work.
CREATE DATABASE wordpress;
Now create a database user.
CREATE USER wordpress_user;
Now let’s set a password to the database user.
SET PASSWORD FOR wordpress_user = PASSWORD(“blogairlines12345”);
Replace blogairlines12345 with your desired password. Be sure not to remove the quotations. Password is case sensitive.
Now we must grant the database user all privileges to access the database. Again, replace blogairlines12345 with the password you just created.
GRANT ALL PRIVILEGES ON wordpress.* TO wordpress_user@localhost IDENTIFIED BY ‘password’;
Congratulations! You have successfully created a database!
You may wish to install phpMyAdmin, something most web hosts offer, for easier database management, however this step is completely optional. Follow instructions on the Ubuntu Documentation.
Now to actually install WordPress.
Download the latest version of WordPress (or a development build if you choose) from the official website.
Create a new directory at /var/www/wordpress. You can change the name ‘wordpress’ to whatever you like but for the purpose of this tutorial, ‘wordpress’ is used. You can use the following command to do this. If you plan on using a command to extract the WordPress files straight from the archive, this step can be skipped as the archive contains the wordpress folder inside.
Change the permission of that folder to 777 so WordPress can read and write to it. Otherwise, you will be asked for an FTP password inside WordPress and we aren’t setting up FTP servers here.
chmod -c 777 -R /var/www/wordpress/
Extract all the WordPress files into this directory. You can use this command. Change the file directories to match where your downloaded archive is.
sudo tar xzvf '/home/brian/Downloads/wordpress-3.0.tar.gz' -C /var/www/
Use the command ‘exit’ to quit the MySQL Client or start a new terminal process. Use the following command to open the wp-config-sample.php file. Edit this like you would for a regular WordPress installation on a web server.
sudo gedit /var/www/wordpress/wp-config-sample.php
Edit the sections about MySQL database settings. If you followed all the names in this tutorial, it would look something like the following. The only modifications you need to make are in the lines highlighted.
<?php // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpress_user'); /** MySQL database password */ define('DB_PASSWORD', 'blogairlines12345'); /** MySQL hostname */ define('DB_HOST', 'localhost'); ?>
Save the file under the name wp-config.php. Close gedit.
Using your favorite web browser, browse to http://127.0.0.1/wordpress and follow the instructions provided. You can also use localhost instead of 127.0.0.1. If you get a message reading Error Establishing a Database Connection, it means you have done something wrong.
After the quick installation, you are all done. You can find your new installation at http://127.0.0.1/wordpress.
Congratulations! A WordPress installation has been successfully completed at 127.0.0.1 (localhost).