Installing WordPress
This chapter explains how to download, unpack, install and configure WordPress 5.4.2 in miscellaneous hosting environments.
Table of contents
- Introduction
- Set up a database for WordPress
- Install WordPress
- Fix file permissions
- Start again
- Codebase layout
- Install CLI program
- Troubleshooting
- Final word
Introduction
[TBA]
Prerequisites
WordPress can run on a number of platforms, but this chapter will focus on installing WordPress in an environment consisting of the Gnu/Linux operating system, the Apache web server, the MySQL (or MariaDB) database server and the PHP scripting language. These four components known as “LAMP” from their initials. LAMP comes pre-installed on some shared web-hosting services, on others you need to install it yourself before you can install WordPress.
In
addition to shared hosting, there are a number of other hosting options
including a virtual private server, cloud instance, and
dedicated hosting. If you need to decide on a host for your
website, you can learn more about hosting options in
this chapter.
In this ebook, I am going to assume that you are using a web host where the LAMP stack is already set up and ready to use.
To work well with WordPress, you need to have access to the command line interface (CLI) of the web server.
The final prerequisite is that you have access to sudo. If you're not sure whether you have this, try to print today's date by means of sudo. If the dialogue goes like this, you have access to sudo (replace “username” with your own login username).
$ sudo date [sudo] password for username: Mon Sep 12 07:47:37 CEST 2016
If the dialogue do not produce the date, and instead goes like this, you don't:
$ sudo date [sudo] password for username: username is not in the sudoers file. This incident will be reported.
It is possible to build and maintain a WordPress site without having access to sudo, but I do not recommend it. To follow the instructions in this chapter, you need access to sudo.
Set up a database for WordPress
With some hosting options, a single database is included in the hosting plan. If this is case, the database is already set up for you, and you only need to know its credentials before proceeding to install.
But usually, you need to create the database yourself. The recommended method for setting up a database for WordPress on a production site is to create a WordPress database and a specific WordPress database user manually. Provided you have root access to a MySQL or MariaDB database, this is done with the sequence of commands below:
$ mysql -u root -p Password: mysql> CREATE DATABASE wordpress; mysql> GRANT USAGE ON *.* TO wordpress@localhost IDENTIFIED BY 'password'; mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, -> LOCK TABLES, CREATE TEMPORARY TABLES ON WordPress.* TO wordpress@localhost -> IDENTIFIED BY 'password'; mysql> quit Bye $
This sequence of commands creates a database named “wordpress”, and a database user named “wordpress”, with password set to “password”, (You should of course pick a more obscure password than “password” when you do this.)
There is a script named mysql_createdb.sh
that does
this.
Install WordPress
Before you can start using WordPress, you will of course need to install it and set it up to be ready for use. To do so, you need to complete the following ten steps:
- Decide on a host.
- Make sure the LAMP-stack on the host is set up and operational.
- If a vhost, set up Apache configuration.
- Download the tarball of the latest version of WordPress from the WordPress download repository.
- Position it in where you want your WordPress root directory (e.g.
/var/www
). - Unpack the tarball. Rename to directory
wordpress
tohtml
(provided that is what is set as the webroot by Apache). - If you don't already have a database set up, create an SQL database and a database user for WordPress. Use the same script used to create a DB for Drupal.
You've now set up to install WordPress. Make sure that the WordPress root directory (e.g. /var/www/html
) is writeable by the web server.
You also need have the following information available:
- Database name
- Database username
- Database password
- Database host
- Table prefix
The “Table prefix” cannot be empty, but you may change it from the
default “wpi_
” if you want to run more than one WordPress
in a single database.
To allow WordPress to automatically copy and
create wp-config.php
, the
directory wp-content
and everyting below it must be
writable by the web server. Make sure it is before proceeding:
$ sudo chgrp -R www-data wp-content . $ sudo chmod -R g+w wp-content .
You need to keep this writable by the web server to enable automatic updates, without having to provide FTP credentials. Not the best practise, securiy-wise, but that is WordPress.
After completing the installationj, add the following constant
in wp-config.php
to enable updates from the admin
GUI:
define('FS_METHOD', 'direct');
Source: StackOverflow.
If you're setting up a site for Norwegian or Danish, you will
probably also want to change DB_COLLATE
:
/** The Database Collate type. Don't change this if in doubt. */ //define( 'DB_COLLATE', '' ); define('DB_COLLATE', 'utf8mb4_danish_ci');
Set authentication unique keys and salts to different unique phrases. These will normally be generate automatically as part of the install, but you can generate these using the WordPress.org secret-key service.
When you point your browser to the base URL of your website-to-be, you should see a screen that looks like the screen dump below. This is the start of a wizard that will guide you through the steps required to connect the site to its database, create tables, add the first user account (the administrator) and prompt you do some basic website settings.

Fill in the form, and the site is up. The username you pick becomes the site admin.
The login screen is at the following path: /wp-login.php
.
Fix file permissions
In order to be able to update from the CLI and from the GUI, set permissions by navigating to the siteroot, recursively assign all files below the wer server group and make all files writable by the web server. Example:
$ cd /var/www/example.com $ sudo -R chgrp www-data . $ sudo -R chmod g+w .
This is not as secure as I prefer, but this is the WordPress way.
Start again
[TBA]
Codebase layout
Three directories:
wp-admin
wp-content
wp-includes
PHP-files in the root:
index.php
wp-activate.php
wp-blog-header.php
wp-comments-post.php
wp-config-sample.php
wp-config.php
wp-cron.php
wp-links-opml.php
wp-load.php
wp-login.php
wp-mail.php
wp-settings.php
wp-signup.php
wp-trackback.php
xmlrpc.php
Auxillary files:
license.txt
readme.html
Install CLI program
WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is WP-CLI.org.
the following sequence of command will download the program, make
it executable, install it under the name wp in a directory
that is in $PATH
and test it.
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar $ chmod +x wp-cli.phar $ sudo mv wp-cli.phar /usr/local/bin/wp $ wp --info OS: Linux 5.4.0-37-generic #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020 x86_64 Shell: /bin/bash PHP binary: /usr/bin/php7.4 PHP version: 7.4.3 php.ini used: /etc/php/7.4/cli/php.ini WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli WP-CLI vendor dir: phar://wp-cli.phar/vendor WP_CLI phar path: /home/gisle WP-CLI packages dir: WP-CLI global config: WP-CLI project config: WP-CLI version: 2.4.0
To check version and update:
$ wp --version WP-CLI 2.4.0 $ sudo wp cli update Success: WP-CLI is at the latest version. gisle@karde:~$
Source: Kista.com: WP-CLI v2.
Troubleshooting
Below is a collection of the problems I've encountered when configuring WordPress, and how I resolved them.
[Currently: none.]
Final word
Installation is only a job well begun. The task of running a production WordPress site entails keeping the configuration up to date. Many of the updates to the WordPress core and contributed modules that appear over time are security updates. Failing to install them in a timely manner when they become available constitutes a security risk.
Last update: 2020-10-26 [gh].