Install WordPress on Ubuntu or Debian
Installing WordPress quickly and easily
In recent years, WordPress has become the most widely used content management system world-wide. WordPress is used with more than 25% of all websites on the Internet. One reason why WordPress is so successful is because it is simply simple. In terms of infrastructure this means, that a small cloud server with a few resources is sufficient to successfully install and operate WordPress. In addition, WordPress has a very large developer community that provides countless plugins, features, themes, and extensions.
In this article, I will briefly summarize the steps to successfully install and run your WordPress on an Ubuntu 16.04 LTS. The tutorial will also work for Debian 8.
Preparing the installation
Just create a new cloud server with a provider of your choice. With gridscale you can directly select a corresponding operating system (Ubuntu 16.04. LTS or Debian 8) and start within 20 seconds.
Log on to your new cloud server via SSH as root and follow the next steps.
Step 1 – Installing a MySQL server
If you do not have a MySQL server installed on your new cloud server, do it now:
$ apt-get -y install mysql-server
During the installation you will be prompted for a password for the MySQL administrator (root). Please enter a password or leave it blank if you do not want to set a password.
After the installation, MySQL is already ready for use.
Step 2 – Increasing the security of your MySQL server
Under Debian and Ubuntu, the package ‘mysql-server’ provides a small support, which allows you to easily secure the installation of your MySQL server. Do the following:
You are now prompted for your password for the MySQL administrator. Enter the password or leave the field blank if no password is set.
Now you are guided by a few options to make the MySQL server safer. The dialogue should be very similar to the following:
$ 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] y ... 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] y ... 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] y - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - 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] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
Step 3 – Creating a database for WordPress
Now create a new database for WordPress. To do this, log in to your MySQL server using the ‘root’ user.
$ mysql -u root -p
If you have not set a password, leave the parameter ‘-p’. You should then get MySQL directly. Here you can configure MySQL, create new users and databases, and assign rights.
To create a database, apply the following command:
$ create database wordpress;
When you submit a MySQL command, make sure that it ends with ‘;’. Otherwise, MySQL does not recognize that you have sent the command for execution and waits for further input. When you forget the ‘;’ just type it into the new line. MySQL builds the right command from it.
Now you should create your own user for the new database. I usually name the users identical to the database to which the user will have access. You can also create another user name. In the following I will give the user with the password ‘my_password’; preferably you replace this string with a secure password.
$ create user wordpress@localhost identified by 'my_password';
Now you have a user and a database, but no rights have been assigned for the new user to access the new database.
The easiest way is to assign all permissions for the user ‘wordpress’ to the database ‘wordpress’. This can be done with the following command:
$ grant all privileges on wordpress.* to wordpress@localhost;
MySQL cached the access rights, which is why you must instruct MySQL to re-read the tables. Then you leave the MySQL prompt:
$ flush privileges; $ exit;
Continue with the next step.
Step 4 – Downloading and configuring WordPress
You can install WordPress via a package manager (apt-get install wordpress). I prefer to use the latest WordPress version. Since the installation is not very difficult just try it and see if you get along with it.
First, download the latest version of WordPress:
$ mkdir -p /var/www $ cd /var/www $ wget http://wordpress.org/latest.tar.gz -O - | tar xvfz -
You should now find a new directory with the name ‘wordpress’ in the directory / var / www. For WordPress to work, you need a few more packages. Just install them from the Ubuntu or Debian repository.
Just watch out: For Ubuntu, the package libssh2-php does not exist in the standard LTS repositories, hence it is possible that you have to activate the Universe repository in the file /etc/apt/sources.list first.
$ apt-get -y install php5-gd libssh2-php
Now I will show you how to configure WordPress. You will do most of the work on the web installer. There are only a few preparations necessary on the console. Go to the new directory ‘wordpress’
$ cd wordpress
You should be able to find a configuration example in the directory. Just copy this file so that you can make changes in it.
$ cp wp-config-sample.php wp-config.php
Now open the file with a text editor of your choice (nano, pico, vi, emacs etc …)
$ vi wp-config.php
Search in the file for the settings for your database and configure the access data for the new database user.
// ** 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'); /** MySQL database password */ define('DB_PASSWORD', 'mein_passwort');
Then save the file and exit the editor.
Step 5 – Installing a web server
Now you need a web server, which can deliver your new WordPress. A very common web server is, for example, Apache or nginx. In this guide I use the Apache web server. First of all the installation:
$ apt-get -y install libapache2-mod-php5 php5-mysql
You may wonder why I do not install Apache2 directly. Apt-get is a clever package manager and when selecting the mod-php5 for apache2, the package manager will notice that it needs to download and install additional packages so that I can use mod-php5 for Apache.
Now you change a parameter in the default configuration of the installed web server and you are almost done. Go to the Apache2 configuration directory:
$ cd /etc/apache2/sites-enabled
Edit the file ‘000-default.conf’ in there (again with your favorite editor):
$ vi 000-default.conf
Just adjust the path for the DocumentRoot:
And restart the web server
$ /etc/init.d/apache2 restart
Step 6 – Call up the configuration of your WordPress
If everything has worked, you should now be able to reach your new cloud server via a browser and land directly on the configuration page of your new WordPress.
Set a page title, enter a user name and password for the administrator, click Next, and then sign in to WordPress with your new credentials.
To allow WordPress to store and change data on your cloud server, it is necessary to adjust the access rights. The easiest way is to give the web server the permissions to your WordPress directory. This can be done with the following command:
$ chown -R www-data:www-data /var/www/wordpress
That’s it already. Congratulations, your new WordPress blog is installed and you can get started.
Installing WordPress quickly and easily In recent years, WordPress has become the most widely used content management system world-wide. WordPress is used with more than 25% of all websites on the Internet. One reason why WordPress is so successful is because it is simply simple. In terms of infrastructure this means, that a small cloud server […]
Thank you for your feedback!
We will get back to you as soon as the article is finished.