Step 1: Installing LAMP
First of all you need to set up LAMP on your Ubuntu machine. If you have not installed LAMP please install it. Read my blog Installing LAMP Stack on Ubuntu and Debian in Just 3 Steps to install LAMP and proceed with the further steps.
Step 2: Downloading WordPress
There are two methods to download WordPress:
- Via Downloading tar file (recommended)
- Prompt to your home by running command 1
- Run the command 2 in your terminal to download the tar file in your home directory.
- Run the command 3 to extract the wordpress directory in your home directory.
1. cd ~/ 2. wget http://wordpress.org/latest.tar.gz 3. tar xzvf latest.tar.gz
- Via downloading zip file from wodpress.org
- Download the zip file
- Extract the downloaded zip file to your home directory
You should have a wordpress named directory in your home directory (or where you prompted when downloading the zip file and extracted it.)
Step 3: Install php5-gd and libssh2-php
PHP has the capability to extend the language by installing different extension modules according to your needs and requirements. In this step we’ll install two PHP extension modules name gd and libssh2-php.
sudo apt-get update sudo apt-get install php5-gd libssh2-php
If you further want to learn about installing and learning about some PHP Extension Modules then read my blog Understanding Root Directory, Testing PHP Engine and Installing PHP Extensions on Ubuntu
Step 4: Creating Database
Open your terminal and run the following commands one by one:
1. mysql -u root -p 2. CREATE DATABASE wordpress; 3. quit
- Enters into MySQL CLI and your prompt will look like this: mysql>
- Create a new database named wordpress
- Exits from the MySQL CLI
Step 5: Configuring WordPress
Note: for this section I suppose your wordpress directory is in your home directory.
Our wordpress directory contains a file named wp-config-sample.php. Save it as wp-config.php and open it in gedit. Run the following command to do so.
1. cp wordpress/wp-config-sample.php wordpress/wp-config.php 2. gedit wordpress/wp-config.php
- saves wp-config-sample.php as wp-config.php
- Opens wp-config.php in gedit like shown below
1. define('DB_NAME', 'wordpress'); 2. define('DB_PASSWORD', 'yourpassword');
On your localhost you would not like to be asked for the FTP Server related information when installing themes and plug-ins. To avoid this and directly download the plug-ins and themes include the following snippet of code in the ‘wp-config.php’ as shown underlined in the picture below:
Step 6: Copying ‘wordpress’ to Root Directory
Our database and configuration file is ready, now it’s time to copy our wordpress directory to the our root directory to browse the wordpress site on our localhost. Run the following command to copy wordpress directory to the root directory:
sudo rsync -avP wordpress/ /var/www/html/wordpress/
Now, we need to change the permission of the ‘wordpress‘ directory. Prompt to the wordpress directory in the root directory we just copied and run the following command:
sudo chown -R username:www-data *
This command will assign the control of our wordpress directory to www-data user. This is a user web servers used to access the files. In this way the server would be able to write directly to our wordpress directory.
Step 7: Creating ‘Uploads’ Directory
We need to create a directory named uploads inside wp-content directory to hold our uploaded files such as images, videos and etc. Run the following command to do so:
sudo mkdir wp-content/uploads
Our uploads directory needs to change the permission so that the web server itself could write to this directory:
sudo chown-R :www-data wp-content/uploads
Now our web server would be able to write in this directory.
Step 8: Configuring by Web GUI of WordPress
Now we ready to browse our wordpress’ web interface to do a bit more configuration and log into it. Type http://localhost/wordpress and you’ll see the following page:
Fill the required information in the form as shown above and click Install WordPress button. You’ll be asked to log in with a Success Message as show below:
You’ve successfully installed WordPress on your Ubuntu machine. You can start your work immediately but if you are not happy with the default WordPress URL style and want to change then you need to do a bit more configuration. To learn about it read my blog Configuring the Permalinks in WordPress on Ubuntu.