- Last updated on: December 3, 2018
The WPlift Guide: How to Install WordPress in Ubuntu Linux
Howdy open source enthusiasts! Did you know that there is an OS out there, as beautiful, robust and secure as Apple’s Mac OSX and yet completely free? Of course you did – its Linux! That’d be a generic term, but we’re talking about Ubuntu – the world’s most popular free OS!
Today we’re going to learn how to install WordPress locally in Ubuntu. With a bit more effort, you’ll be able to host your very own web server at home accessible across the Internet. (Server geeks, you know what I’m talking about). So let’s get to it folks!
Prerequisites
- Ubuntu 12.04 LTS or higher: Pre 12.04 versions of Ubuntu are outdated – and could contain various security vulnerabilities. So, if you’re still using one of them, please upgrade at the earliest!
- Active Internet connection: We would need it to install the necessary applications.
- Root privileges: Usually all Ubuntu installations require you to enter a root access password during installation. However, if you’re using a non-administrative account, you would need an account with administrative privileges or the root password. Either one would work.
Preparing your System
First thing’s first. It’s always a good practice to update the software sources to the latest version, before installing any new software. To do this, fire up Terminal and issue the following command:
sudo apt-get update
During the installation we would need to edit various files. It’s better to use the command line interface – since people reading this tutorial might be looking to install Ubuntu in their server or home PC. We will be using nano – an open source CLI editor. You can install nano by:
sudo apt-get install nano
We would need to unzip the wordpress.zip file. To install the unzip program, use the following command:
sudo apt-get install unzip
Once done, we’re going to install the list of software required to run a web server. It’s the equivalent of installing WAMP or XAMPP in Windows. In Ubuntu, it’s called the LAMP stack – an acronym for:
- Linux – The operating system
- Apache – The webserver
- MySQL – The database software
- PHP – The dynamic scripting language that WordPress uses in unison with MySQL
The Copy-paste dilemma
If you’re an absolute beginner, here are two tips that could come in handy:
- If you’re connecting to a remote server, you’re probably using an SSH client called Putty. In order to paste text in Putty, you need to right-click on the interface. Ctrl+V does not work.
- If you’re using Terminal in Ubuntu’s dektop version, the combination Ctrl+Shift+V works for pasting data. Alternatively you can right-click and select the Paste option.
- In order to copy text in Putty or Terminal – select the text and press Ctrl+Shift+C
How to Install LAMP in Ubuntu
Thanks to Ubuntu, installing the LAMP stack has never been easier. Here’s what you got to do:
Step 1 – Install Apache Web Server 2.0 in Ubuntu
Apache is one of the oldest web server software in the world, powering over 50% of the Internet’s web pages. Other popular webservers include Microsoft IIS, NGINX (pronounced Engine X) and Lighttpd. NGINX is a robust webserver used in high performance sites – it uses half the resources required by Apache while performing faster. However, configuring NGINX properly can be quite complicated – which is why we do not recommend it for a beginner.
To install Apache, issue the following command:
sudo apt-get install apache2
If any question is asked during the installation process, keep pressing the Enter key (also called the Return key) so that the default values will get entered.
Once done, you’ll have the webserver running. The base directory is:
/var/www/
All the files inside this directory will be visible in your webserver. To access the web server, simply enter your server’s IP or domain (in configured). If you’re using your own laptop/desktop, the IP would be:
https://localhost
If you’re using a server, simply replace ‘localhost’ with your server’s IP address.
At this stage, you’ll see a message like this:
If you don’t know your server’s IP address, you can find it by issuing this command:
ifconfig eth0 | grep inet | awk '{ print $2 }'
Here’s a sample output:
[email protected]:~# ifconfig eth0 | grep inet | awk '{ print $2 }' addr:178.245.226.477
Step 2 – Install MySQL Database in Ubuntu
MySQL is an open source database software (technically called an RDBMS – relational database management system). Other notable database software include Oracle, Microsoft SQL Server and IBM DB2. 99.9% percent of the websites and hosting companies use MySQL as their primary database server. To install MySQL, issue the following command:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
This command installs 2 additional programs to install make MySQL compatible with Apache and PHP. During the installation, you’ll be asked to set the root password. Let’s choose ‘calendar’ as the root password for our tutorial – you’re free to choose anything you like! If you press Enter without entering a password, that’s not an issue, you can use no root password or you can set a new root password in the following steps.
Once the installation completes, we need to activate/start the MySQL database:
sudo mysql_install_db
Next, we’ll start the MySQL configuration script:
sudo /usr/bin/mysql_secure_installation
- The prompt will ask you for your current root password. In our tutorial, we’ll type ‘calendar’ and press Enter. If you haven’t chosen any, simply press Enter to proceed to the next step.
- This step asks you if you want to change your root password. If yes, press Y, else press N to proceed to the next step.
- In all the following steps, keep on pressing Enter to submit the default values until the setup completes.
Here’s a quick look at the messages displayed while executing the configuration script.
[email protected]:/var/www# sudo /usr/bin/mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... Thanks for using MySQL!
All done! If you’ve completed all of the above steps, your MySQL installation should now be secure.
Step 3 – Install PHP 5 in Ubuntu
PHP is a free and open source server-side scripting language used for web-development and also as a general purpose programming language. In other words, it’s used to generate HTML pages dynamically. WordPress and almost all modern CMS use PHP. To install PHP, issue the following command:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
If prompted, press Enter. Next, we will need to modify Apache’s configuration file for it to serve relevant PHP files. First we open the configuration file we need to edit:
sudo nano /etc/apache2/mods-enabled/dir.conf
Remember when we installed nano in the beginning of this tutorial? We’ll we’re using it now. Once the file opens, copy and paste the following:
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
Press Ctrl+O to save the file. It’ll ask you if you want to save – type Y and press Enter. In order for the changes to take effect, we’ll be restarting the webserver:
sudo service apache2 restart
Next, we check if the Apache is working in sync with PHP. Issue the following commands in order:
cd /var/www/ sudo nano info.php
This opens the text editor. Copy-paste the following data:
<?php echo '<h1 style="text-align: center;">Mmm.. Soup</h1>'; phpinfo(); ?>
Press Ctrl+O to save, followed by Y and Enter to confirm the save. The moment of truth is upon us. Open the following link in your web browser:
https://localhost/info.php
You should see the following webpage:
Congratulations, you now have installed LAMP in your Ubuntu machine.
Installing WordPress in Ubuntu
If you’ve reached till here without any difficulty, pat yourself in the back! You’re almost done. It’s time to download WordPress.
Head over to the directory /var/www and create a new folder with a name of your choice. Let us pick WP1 signifying our first installation of WordPress.
mkdir /var/www/WP1
Extract the content of the wordpress.zip file inside WP1. If you’re using a GUI based version of Ubuntu, then you could use Ubuntu’s File Manager and extract the zip archive. You can also do this by entering the following commands from the Terminal:
cd /var/www/WP1/ sudo wget https://wordpress.org/latest.zip sudo unzip latest.zip
Once the extraction is completed, a new folder called “wordpress” will be created, containing all the files. You have two choices:
- Move (and not copy) all files present inside the wordpress folder to the WP1 folder OR
- Let the directories be as is, i.e., do nothing
Based on your choice, one of the following is your WordPress installation URL:
- If you’ve picked the first option then your WordPress installation would be accessible from https://localhost/WP1/
- If you’ve gone with choice 2, your WordPress installation would be accessible from https://localhost/WP1/wordpress/
Setting the Correct Folder Permissions for WordPress
You might install themes and plugins in your local WordPress installation. For this purpose, you need to set the correct permissions in the wp-content folder. To do this, simply open Terminal and issue the following command:
sudo chmod -R 777 /var/www/WP1/wp-content/
Or if you’ve chosen choice 2 earlier, issue this command instead:
sudo chmod -R 777 /var/www/WP1/wordpress/wp-content/
This command allows modification, creation and deletion of files and folders present inside the wp-content folder. If you recall, all your themes, plugins and uploaded media (other than the posts/pages) reside inside the wp-content folder.
Create a database in MySQL for WordPress
WordPress needs to store its data – posts, pages, configuration etc in a database file. In order to create a new database in MySQL for WordPress, follow these steps:
Enter the MySQL console using the command
mysql -u root -p
When asked for the password, enter ‘calendar’. If you’ve chosen a different password, use that instead of calendar. If you haven’t chosen any password, simply press Enter.
Now we’re inside the MySQL console. Let’s pick a database name – say ‘wp1db’. You can choose anything you like but it has to be alphanumeric and cannot exceed 7 characters. Issue the following commands carefully (don’t miss a semicolon) followed by pressing the Enter key after each command:
CREATE DATABASE wp1db; FLUSH PRIVILEGES; exit
Here’s a screenshot of the above process:
The Final Steps
All is set. Now it’s time to embark the final stage of our WordPress installation:
Open your browser and navigate to your WordPress installation URL as mentioned under Installing WordPress in Ubuntu. Assuming we’ve picked the second choice, our URL would be:
https://localhost/WP1/wordpress/
You should see the following page:
Click on “Create a Configuration File” to proceed to the next step.
Once you press “Let’s Go” you’ll enter the actual WP installation – which is the crucial part. Enter the following data carefully:
- Database Name: wp1db (or the one you’ve chosen)
- User Name: root
- Password: calendar (or the password that you’ve set during the MySQL installation)
- Database Host: localhost
- Table Prefix: wp1_
Once set, press the ‘Submit’ button. If you get the following message, don’t worry. This means that Apache does not have permission to write/modify the wp-config.php file. Let’s fix that.
Copy the selected text and paste it the wp-config.php – overwriting all its previous content. The following commands help you do that from the CLI:
cd /var/www/WP1/wordpress/ #moving to the WordPress installation directory sudo nano wp-config.php
Now paste the content, and save. You should set the proper permission to the config.php file –
sudo chmod 775 wp-config.php
Return to your browser and press the “Run the Install” button. You should see this page:
Enter your site’s details and press “Install WordPress”. If all goes well, you should get:
Now we login to our freshly created WordPress installation:
To find the WordPress dashboard:
And the WordPress site:
Congratulations, you’ve installed WordPress in your Ubuntu machine!
Conclusion:
This tutorial has been a part of the Install WordPress series – tutorials for installing WordPress in the three most popular Operating Systems in the world – Windows, Mac and Linux.
What we’ve learnt today is valid for all the various spin-offs of Ubuntu like Lubuntu, Kubuntu, Edubuntu, etc. They’re all derivatives of Ubuntu, which itself is a derivative of Debian – a more powerful, advanced and versatile derivative of Linux.
If you’re using Fedora or Arch Linux or other derivatives of Linux, then the process would be a bit different. Once you’ve installed the LAMP stack, then rest of the procedure is the same. This tutorial is also applicable for installing WordPress in GUI-less environments – where everything is based on a CLI. This makes is perfectly suitable for installing WordPress in a VPS or dedicated server. All you have to do is replace the term ‘localhost’ with you server’s IP address. Pretty neat, huh?
Happy trails, open source guy!
2 thoughts on “The WPlift Guide: How to Install WordPress in Ubuntu Linux”
Why do all browser screen shots appear to be from Windows, when this post is about installing WordPress on Ubuntu?
I would say that the server is Ubuntu, but is being connected to remotely via clients (PuTTY, web browsers, etc) on a Windows machine.
Comments are closed.