Install WordPress in Ubuntu 12.04 LTS Localhost LAMPP server

Install WordPress in Ubuntu 12.04 LTS Localhost LAMPP server

This is a very useful tutorial for WordPress and Ubuntu beginners that are planning to install WordPress in a local host LAMPP (Linux/Apache/MySQL/PHP) server.

This is not using XAMPP or WAMP solution that is common to developers using Windows operating system. This tutorial will illustrate the standard approach of building a LAMPP server in Ubuntu and running WordPress on it. The steps in this tutorial might also work in other similar Linux distribution such as Mint.

Developing a WordPress website in a Linux environment is beneficial since majority of deployed servers for WordPress will also be running in Linux. This will have some benefits in terms of operating system compatibility.

Start Installing the LAMPP server


Before proceeding to the proper installation steps. This tutorial is written using the following:

a.) Ubuntu 12.04 LTS – updated with the latest packages. This is also the latest version as of July 2012.

b.) WordPress 3.4.1– this is the latest version of WordPress as of July 2012 first week.

If you are planning to install Ubuntu or WordPress software in your computer, it is highly recommended to use the latest version for stability and security. It is recommended to upgrade your Ubuntu to use the latest version to ensure that this tutorial will be compatible with your results.

Step 1

Login as root, type this command in the terminal and enter your Ubuntu password. You can launch the terminal command line by pressing Control- ALT- T:

sudo -s -H

Step 2

The first thing to install is the MySQL server. Enter this command:

apt-get install mysql-server mysql-client

It will start downloading packages, so you have to wait. Then you will be required to enter your MySQL root password. Make sure you will remember this as you will be using this during WordPress installation. The username will default to “root”.

Step 3

The next thing to install will be Apache. This is your web server. Type the command below:

apt-get install apache2

Step 4

You will then need to install PHP. This is the server scripting language used by WordPress. Enter this command:

apt-get install php5 libapache2-mod-php5

Step 5

After installing PHP, you need to restart the Apache server by entering this command:

/etc/init.d/apache2 restart

Step 6

It is highly recommended to use your Ubuntu home directory (.e.g /home/codex-m/www) as your document root so that you can easily read and write files.

Document root is where you will be placing the WordPress files for installation, editing and management. This will make your WordPress development work easy as you will have full permission to edit those files without requiring root access.

So in the command prompt, navigate to your Ubuntu home directory by entering the command:

cd /home/your_Ubuntu_username

Replace “your_Ubuntu_username” with your correct username. To make sure you are now in your Ubuntu home directory, type this command:

pwd

It should return:

/home/your_Ubuntu_username

Step 7

Create a www folder in your home directory by entering this command:

mkdir www

Step 8

It is time to assign proper file permissions to document root folder that will be used by Apache and WordPress. First, change the CHMOD of your www folder to 755:

chmod -R 755 www

This will make the www folder readable/writable by Apache which is important. The additional parameter -R means that all files/folders inside the folder (e.g. your WordPress files) will get that permission as well.

Step 9

Next, you need to ensure that Apache has permissions to read and write your home directory. Enter this command:

chmod 755 /home/your_Ubuntu_username

After that, also enter this command:

chmod 755 /home/

The main purpose of doing this is to prevent 403 forbidden errors in Apache when accessing your WordPress website or any HTML/PHP files after changing your document root in Step10.

Step 10

Confirm that you have correctly set permissions by running the following set of commands:

a.) Check if your www directory is now using 755 as the permission:

stat -c '%a' /home/your_Ubuntu_username/www

You should see 755 as the return value.

b.) Check if your home directory is using 755:

stat -c '%a' /home/your_Ubuntu_username/

And also this command:

stat -c '%a' /home/

Step 11

By default (after Apache installation in Step3); the document root of Apache accessible by the web browser is found in this path:

/var/www

In the previous steps, you have changed it to use your Ubuntu home directory such that the new path will be:

/home/your_Ubuntu_username/www

This new path is now configured with proper file permissions that Apache can access. Finally, you need to configure your Apache configuration to use this new path. Follow the steps below carefully and make sure you are still logged-in as root:

a.) Open the enabled sites configuration in Apache using the terminal:

pico /etc/apache2/sites-enabled/000-default

The text editor should look like this:

b.) Change the two instances of /var/www to use your new document root path found in your Ubuntu home directory. For example this is the edited version:

You need to be careful not to change any of the existing lines or code. To save the changes; press Control – O then press enter. To exit the editor, press Control – X.

Step 12

Restart Apache:

/etc/init.d/apache2 restart

Step 13

WordPress will be using a lot of PHP modules for proper operation. You should also install these modules. Copy and paste the command below to the terminal:

apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

Step 14

Restart Apache again:

/etc/init.d/apache2 restart

Step 15

Using your favorite code editor (gedit will do), create a PHP file called as info.php containing the following code to test your Apache and MySQL installation:

<?php
phpinfo();
?>

Save info.php to your document root folder path:

/home/your_Ubuntu_username/www

Step 16

Now access info.php in the web browser by typing this in the address bar:

http://localhost/info.php

You should be able to see the details of your PHP configuration settings without any errors.

 

Install WordPress in Ubuntu LAMPP server


With your server running, you can now install WordPress:

Step 1

Launch the terminal then go to your new document root path:

cd /home/your_Ubuntu_username/www

Step 2

Download the latest WordPress version (be patient it can take some time to download depending on the speed of your Internet connection):

wget http://wordpress.org/latest.zip

Step 3

Unzip WordPress:

unzip latest.zip

After unzipping, you should be able to see the WordPress folder in your document root.

Step 4

Connect to MySQL to create the WordPress database. Issue this command in the terminal, replace PASSWORD with your own MySQL root password as configured in the Step2 of the LAMP installation.

mysql -uroot -pPASSWORD -hlocalhost

For example, if your password is MrSmiley then the command to type will be:

mysql -uroot -pMrSmiley -hlocalhost

The username is automatically set to root and the hostname will be localhost. You will be able to see th MySQL prompt after successul login:

mysql>

Step 5

In the MySQL prompt, create the WordPress database by entering this command:

create database wordpress;

The database name will be “wordpress”. You can assign any database name that you like. For example, if you want the database name to be MyWordpressDatabase then enter it as:

create database MyWordpressDatabase;

Step 6

Exit MySQL database:

exit;

Step 7

Go inside your WordPress directory in document root, find the file: wp-config-sample.php. Open it with a text editor and define your MySQL connection parameters. Replace:

define('DB_NAME', 'database_name_here');

/** MySQL database username */
define(‘DB_USER’, ‘username_here’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘password_here’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

With your database connection parameters (replace “Your MYSQL password” with your correct password):

define('DB_NAME', 'wordpress');

/** MySQL database username */
define(‘DB_USER’, ‘root’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘YOUR MYSQL PASSWORD’);

/** MySQL hostname */
define(‘DB_HOST’, ‘localhost’);

Step 8

Replace:

define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');

With the output provided in this URL (enter this in the browser):

https://api.wordpress.org/secret-key/1.1/salt/

Step 9

In your text editor, go to File – Save As. Save it as:

wp-config.php

Make sure wp-config.php is found inside your WordPress directory along with index.php.

Step 10

Finally launch the WordPress installation in the web browser by typing this URL:

http://localhost/wordpress/wp-admin/install.php

Follow the rest of the instructions by providing your username, password, email, etc. Then after installation you can login to the WordPress admin panel in this URL:

http://localhost/wordpress/admin

Or view your newly installed WordPress website in this URL:

http://localhost/wordpress/

You have just installed WordPress in Ubuntu using LAMPP localhost server.

 

About the Author

31 thoughts on “Install WordPress in Ubuntu 12.04 LTS Localhost LAMPP server

  1. suedyHeterene - August 18, 2012 at 12:18 pm

    Hey, I am new here. I am sorry if this Isn`t the best place for this post but I was hoping some one here on http://www.wpwebhost.com would be able to show me where I can watch the movie The Dark Knight Rises On the internet for free. Thanks

  2. Wayferer - September 1, 2012 at 12:51 pm

    Thank you. This was very helpful!

  3. venkat - October 10, 2012 at 2:06 pm

    hi i am getting

    Not Found

    The requested URL / was not found on this server.
    Apache/2.2.22 (Ubuntu) Server at localhost Port 80

    this error … please help me out…

  4. Alan Ferguson - October 14, 2012 at 11:39 am

    Thank you for this tutorial. I have spent all week (evenings) trying to get this to work. It took me countless hours to get LAMP itself working, and I though that I was home free. I figured that WordPress would be easy to install. However, I deviated from the default values by two things – I did not use the home page for my documents with the same name as all the examples. I thought that I had changed everything that was needed, but maybe not. I also installed WordPress in /usr/share/wordpress, and hoped that links to it from /var/www/wordpress would work OK.

    So, I removed WordPress from Ubuntu 12.04 and re-installed it where you recommended, and then it all just worked. I spent lots of time following other tutorials, but they did not work.

    Again, thanks for your straightforward tutorual!

    Al Ferguson

  5. Kartar - November 17, 2012 at 3:22 am

    stem 16 in apache2 and step 9 in word press is not working… plz help me out

  6. Michael - January 6, 2013 at 3:02 am

    Very good tutorial, especially if you don’t have much experience with WP / Ubuntu ::: I consider myself an “experienced” WP dev. and even I enjoyed working through this … THX

  7. ahmed - January 19, 2013 at 7:53 pm

    when i do this
    Finally launch the WordPress installation in the web browser by typing this URL:

    http://localhost/wordpress/wp-admin/install.php

    i see this message

    We were able to connect to the database server (which means your username and password is okay) but not able to select the wordpress database.

    Are you sure it exists?
    Does the user root have permission to use the wordpress database?
    On some systems the name of your database is prefixed with your username, so it would be like username_wordpress. Could that be the problem?

    If you don’t know how to set up a database you should contact your host. If all else fails you may find help at the WordPress Support Forums.

  8. Dennis - January 28, 2013 at 10:00 pm

    Hey,

    everything worked fine or maybe not. I installed wordpress but then i got some problems. I tried to install plugins or upload some pictures but wordpress cannot create folder or move pictures to the uploads for example. this happends everytime. It has not the rights to do this.

    So I installed it again. I set the rights like you said “chmod -R 755 www” but only for root are the files read and writeable.

    I am sorry but can you tell me what i made wrong? Or what i make wrong by using wordpress?

    Thanks a lot!

  9. Stephen LIu - February 4, 2013 at 10:57 pm

    Hi,

    Thanks for your tutorial.

    It works for me with WP dashboard started after login. But I encountered problem on search theme;
    warning:
    An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.

    Try again

    Advice would be appreciated. TIA

    Regards
    SL

  10. Andrew B - February 20, 2013 at 1:28 am

    Thanks a lot, Codex Meridian! I do appreciate and keep it up!

  11. Axel Larator - February 21, 2013 at 5:01 am

    Hi and THX!!!

    I am using antiX and kept the stuff in /var/www. But it works like a charm.

    Cheers
    Axel

  12. Alvaro - February 21, 2013 at 6:34 pm

    thumbs up bro! 20 minutes and I got my own local WP, thanks heaps.

  13. Jochen - February 23, 2013 at 10:38 pm

    , thanks for your straightforward tutorual!

    THX

    • Jochen - February 23, 2013 at 10:48 pm

      missing code in wp-config.php

      putenv(‘TMPDIR=’. $_SERVER[‘DOCUMENT_ROOT’] .’/wp-content/tmp’); define(‘WP_TEMP_DIR’, ABSPATH . ‘wp-content/tmp’);

    • Jochen - February 24, 2013 at 12:01 am

      this helped:

      sudo ls -al /home/….my_username…/www/ /var/home…my_username…./wordpress/

      sudo chown www-data:www-data -R /home/…my_username…/www

      checked with:

      sudo ps aux|grep apache

  14. Suraj Banakar - March 8, 2013 at 4:42 pm

    You just finalised my decision of using Ubuntu as my main operating system!
    I don’t know how to thank you, for this!
    You have just made my life a whole lot easier!
    Earlier I had to switch to xp to develop using wordpress on local server, but thanks to your tutorial, I can run wordpress locally on Ubuntu!
    Thanks a ton to you!

  15. Joe - March 23, 2013 at 7:22 am

    Thank you so much! Went through some other instructions on another site and it would not start. These directions were great and everything now works fine.

  16. Claudia - March 23, 2013 at 10:18 am

    Currently it sounds like WordPress is the preferred blogging
    platform available right now. (from what I’ve read) Is that what you are using on your blog?

  17. Page - March 31, 2013 at 11:53 am

    My installation works fine up until the 10th step. Any suggestions?

  18. mattyy - April 5, 2013 at 7:21 am

    i followed all of the instructions for installing the server on the OS when it come to the part of adding the info.php file to the www file it would not let me do so, it said i did not have the correct permissions.

    i have checked the file permissions and it is saying that the file is chmod 755, i have tried to add a plain text file to the folder to no avail

    There is only one account on my machine and that is the main account anyone know how to solve this??

  19. Mihai - April 15, 2013 at 1:24 am

    Thanks a lot for this tutorial. Worked just great for me! I will gladly recommend your site! Thanks again!

  20. DaMaD - May 11, 2013 at 11:29 pm

    Read and Execute right for everyone on home directory? Hopefully you have nothing to hide.

  21. stephen - June 18, 2013 at 1:29 pm

    After loading my laptop with Ubuntu 12.04.he is not allowing me to log in instead giving me ubuntu 12.04 LTS localhost tty1 and local login: What can I do pls?

  22. Brian J - July 10, 2013 at 8:13 am

    When I get to ‘create database wordpress;’ command it spits back
    ‘ERROR 1007 (HY000): Can’t create database ‘wordpress’; database exists’
    Any idea what caused this, will it cause problems and how to fix/work around it?
    Thanks

  23. John D - July 23, 2013 at 5:09 am

    Excellent! Great walkthrough from start to finish on a LAMP/Wordpress install.

Share your thoughts with the community