Install and configure WordPress

Overview

Duration: 1:00

WordPress is the most popular open source blogging system and CMS on the Web. It is based on PHP and MySQL. Its features can be extended with thousands of free plugins and themes.

In this tutorial we will install WordPress on Apache2 server and create our first post.

What you’ll learn

  • How to set up WordPress
  • How to configure WordPress
  • How to create first post

What you’ll need

  • A computer running Ubuntu Server 16.04 LTS
  • Running Apache2 server
  • You don’t need to know how to configure database.

Originally authored by Marcin Mikołajczak

Install WordPress

Duration: 1:00

To install WordPress, use following command:

sudo apt update
sudo apt install wordpress php libapache2-mod-php mysql-server php-mysql

If you haven’t installed MySQL before, you will be asked for password for “root” MySQL user. You can leave this field empty.

Configure Apache for WordPress

Duration: 2:00

Create Apache site for WordPress. Create /etc/apache2/sites-available/wordpress.conf with following lines:

Alias /blog /usr/share/wordpress
<Directory /usr/share/wordpress>
    Options FollowSymLinks
    AllowOverride Limit Options FileInfo
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>
<Directory /usr/share/wordpress/wp-content>
    Options FollowSymLinks
    Order allow,deny
    Allow from all
</Directory>

Then, enable this site with sudo a2ensite wordpress, enable URL rewriting with sudo a2enmod rewrite and reload apache2 with sudo service apache2 reload.

Configure database

Duration: 4:00

To configure WordPress, we need to create MySQL database. Let’s do it!

$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0,00 sec)

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost
    -> IDENTIFIED BY '<your-password>';
Query OK, 1 row affected (0,00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 1 row affected (0,00 sec)

mysql> quit
Bye

Now, let’s configure WordPress to use this database. Open /etc/wordpress/config-localhost.php and write:

<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', '<your-password>');
define('DB_HOST', 'localhost');
define('DB_COLLATE', 'utf8_general_ci');
define('WP_CONTENT_DIR', '/usr/share/wordpress/wp-content');
?>

Enable MySQL with sudo service mysql start.

Configure WordPress

Duration: 2:00

Open localhost/blog in your browser. You will be asked for title of your new site, username, password and address e-mail. You can choose if you want to make your site indexed by search engines.

You can now login under localhost/blog/wp-login.php. In Dashboard, you will see bunch of icons and options. Don’t worry, it’s easy!

Write your first post

Duration: 3:00

You have probably noticed that “Hello world!” post. We will delete it and write something more interesting…

All Posts

From Dashboard (localhost/blog/wp-admin/), select “Posts” icon and click on “All Posts”. Mouse over the “Hello world!” post title and select Trash.

To create new post, click on the “Add New” button. You should notice a fancy WYSIWYG editor with simple (but powerful) text formatting options. You may want to switch to Text mode, if you prefer pure HTML.

Let’s write something! It’s as easy, as using text processors that you know from office suites.

Now, click the Publish button. You can now view your brand new post!

That’s all!

Duration: 1:00

Of course, this tutorial has only described basics of WordPress usage, you can do much more with this blogging platform/CMS. You can install one of thousands of available (free and commercial) plugins and themes. You can even configure it as forum (with bbPress plugin), microblogging platform (BuddyPress), eCommerce platform (WooCommerce) or extend existing WordPress features with plugins like JetPack or TinyMCE Advanced.

WordPress manual and documentation is available in the WordPress Codex.You can read it to learn more about WordPress usage, and even something about themes/plugins development.

If you need more guidance on using WordPress, help is always at hand:

Further reading:

1 Like

Dears,
While doing sudo a2ensite wordpress it would be good idea to add
sudo a2enmod rewrite.
Thank you.

1 Like

I would also add changing to collation, if needed when entering the DB_USER and others MySql settings.

define( ‘DB_COLLATE’, ‘utf8_general_ci’ );

1 Like

Yes, makes sense on both accounts, updated. Thanks!

2 Likes

Happy to help:)

Is it possible to use this method for sites without alias (/blog)?

Yaakov

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
    -> ON wordpress.*
    -> TO wordpress@localhost
    -> IDENTIFIED BY '<your-password>';

Doesn’t work anymoore
Use maybe this Instead:

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '<your-password>';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' WITH GRANT OPTION;
4 Likes

Due to the new version there have to be an other adjustment:
CREATE USER ‘wordpress’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘’;

1 Like

This leaves you with an installation of wordpress that is not able to install plugins. I did some research to see what is required, and apparently doing things this way it is not possible to install plugins without opening yourself up to a world of security vulnerabilities. So no plugins. What means I just wasted all this time for nothing. A warning that this does not install a full, usable version of wordpress would have been nice.

1 Like

Furthermore, this installs Wordpress so that it appears to users to be located in a subdirectory called “blog/” which does not actually exist. Although you can change the settings so the user-facing site no longer appears to be in this nonexistent subdirectory, there is no way to move /wp-admin out of “[sitedomain]/blog/wp-admin”

You really should make it clear at the BEGINNING that these instructions are for a single, extremely specific and nonstandard install of wordpress. Now I have to start all over again from scratch.

2 Likes

Holy bullshit. The installation removed my mariaDB.
What can I do?

You need to do some more research. Blog is an alias, not a directory. This is an example of virtual hosts installation. You could use this installation to run more than one WordPress site by creating other virtualhosts. Create the relevant files with the correct naming convention and you would/could have say localhost/music.

Create /etc/apache2/sites-available/mysite.conf and set an alias to /music with the appropriate virtualhost block along with a /config-mysite.php and enabling mysite as a site and soon you should be on your way to opening http://mysite.

I’m just trying to follow this guide. then all of a sudden I’m expected to know what to do.
How do I create a file?

I don’t use linux / unix everyday and I’ve never used Wordpress.

“Create Apache site for WordPress. Create /etc/apache2/sites-available/wordpress.conf with following lines:”

1 Like

Ignore the above post about having a Wordpress Site that is unable to use plugins. Admitted, this tutorial does assume a lot (if you know nothing about Ubuntu). Fortunately, I know everything about Ubuntu and if you did follow this tutorial and WERE able to install Ubuntu, everything will work. The author of the post didn’t know enough about Ubuntu, got frustrated, and made his post hoping to either denigrate the author, the tutorial, or both. If he would had read the tutorial a couple more times he might have figured out it was a simple path or permission issue. Those who knew Ubuntu immediately noticed this issue and fixed it on the fly, as it was knowledge he/she had taken for granted through their years of use with Ubuntu.

Plugins work just fine. Make sure you do the ‘chown -R www-data:www-data /usr/share/wordpress’. Yes that line is different than what’s in the tutorial. It is simply a more complete way to set permissions. Chances are that setting the user ownership will be enough, however, in some instances you MAY need the group ownership to be properly set. If not, then you might complain plugins don’t work.

The other possible issue you might have while using this tutorial (with some admitted assumptions) is the issue of pointing the wordpress symlink at /var/www as opposed to pointing at /var/www/html. This unfortunately is another one of those possible assumpition things.

Finally, there was some droning on about /blog not being a directory in the Unix file system. That is correct, if you followed through the tutorial you will know at no time is the a creation of some directory name ‘blog’. This is a symbolic name that is used in the configuration file. It may or MAY NOT actually exist as a directory in your file system.

It’s just a matter of how much you know or don’t know. But just because something doesn’t work because you thought you followed instructions to the ‘t’ probably has more to do with your lack of knowledge of the overall subject.

This guide was not called a comprehensive guide. But I can guarantee you anyone who has used/administered a Ubuntu box for at least a year will have easily set their WordPress site up with the aid of these instructions supplemented by their knowledge of their own system.

I do help with this stuff, but unfortunately for most, I do it professionally on a pay basis, have Ubuntu servers up on the internet now you can peruse (i have a publicly available ubuntu shell server for responsible people) and look at active production servers and how they are configured. Contact me personally if you would like to know more.

The guy who wrote the tutorial needs to be thanked for all the time and effort he put into it. It has helped thousands of people get working sites. Just because 1 guy couldnt figure out how to do something has more to do with that one guy than it does this tutorial.

I’m such a softee. I just can’t help sticking up for people.

Ron

1 Like

Hey guys,

Can you help a gal out?

What should we be using for the following?

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost
-> IDENTIFIED BY ‘’;

Am I supposed to create a password?
The initial instructions said I would not need to create a mysql password.

Also - dumb question - if I am to create a password, do I include the ’ before and after password?
for example ‘abcdef12345’.

How do I check the syntax in mysql? I keep getting errors about my syntax but no clue how to view the syntax and look for errors?

If I show tables, it says my tables are empty :frowning:

mysql> SHOW TABLES;

Empty set (0.00 sec)

1 Like

Can you help a gal out?
What should we be using for the following?
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost
-> IDENTIFIED BY ‘’;

That is incomplete, and will throw a MySQL error.

You actually should not use that, as it will not work on all version of mysql. It is actually specific to the latest and greatest. Do it the old way, like so:

create database wordpress;
create user ‘wordpress’@‘localhost’ identified by ‘password’;
use wordpress;
grant all privileges on wordpress.* to ‘wordpress’@‘localhost’;
flush privileges;
quit;

I am fairly certain that set of commands will work on all versions of MySQL. Setting specific privileges is surely a more secure way of granting database privileges, however, it can be problematic. It might not be portable across all version of MySQL. You might leave out a certain privilege and then this makes for a nightmare troubleshoot. Plus other reasons that are not coming to me atm.

Am I supposed to create a password?
The initial instructions said I would not need to create a mysql password.

They are talking about the mysql-server password here. You may or may not need to. However, do yourself a favor and just prior to creating the wordpress database, run this command:

mysql_secure_installation

Running that will not make anything harder, and the 3 or 4 questions it asks are easy to understand, but replying ‘Yes’ to all questions will not break anything. During this process, it will ask you to set the mysql-server password. However, again, depending on the version this may or not be needed. Current combinations of Ubuntu/mysql-server will not need a root password for mysql-server if you are logged in as the root Ubuntu user. Modern version connect through a socket (don’t worry, you don’t need to know the details of this) and will automagically log you in as the mysql-server root user if you are logged in as an Ubuntu user with root privileges.

Also - dumb question - if I am to create a password, do I include the ’ before and after password?
for example ‘abcdef12345’.

No. This in fact would be a security hole. You NEVER have to know or even include an old password when updating the password.

If I show tables, it says my tables are empty :frowning:
mysql> SHOW TABLES;

That’s correct. The WordPress tables are created during the actual WordPress installation (the part where you complete the WordPress setup in your browser).

Ron

PS. Almost ALL versions of of WordPress tutorials for Ubuntu 20.04 leave you with a broken installation, if followed to the letter. They assume much. One of things NEVER pointed out in the installation guides are that changing the ownership of the php sub-system and the javascript sub-system to (chown -R www-data:www-data ) might be required to get things working. Additionally, most newer WordPress installation guides combined with Ubuntu 20.04 also tend to forget little things, like php-intl, php-xml, php-bcmath and a shit ton of other files required to make things work. You’ll know if this is the issue if your WordPress installation is missing the images, all the fonts are wonky, etc etc. This is specifically due to symbolic links hardcoded in WordPress installations which end up pointing style sheets and other critical javascript and php which are not in the places where they should be. The solution to this is DON’T use the latest and greatest. If you are relatively weak in your Ubuntu skills, you’ll have a much better time (ie, successful) if you build your WordPress installation on Ubuntu 18.04, and using the version of WordPress provided in the repository (ie, apt get wordpress).

2 Likes

I agree with ronaldljohnson above about:

Can you help a gal out?
What should we be using for the following?
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost
-> IDENTIFIED BY ‘’;

That is incomplete, and will throw a MySQL error.

You actually should not use that, as it will not work on all version of mysql. It is actually specific to the latest and greatest. Do it the old way, like so:

create database wordpress;
create user ‘wordpress’@‘localhost’ identified by ‘password’;
use wordpress;
grant all privileges on wordpress.* to ‘wordpress’@‘localhost’;
flush privileges;
quit;

The above commands do not work. I followed the tutorial exactly and that doesn’t work but his solution does.

2 Likes

Thank you for taking the time to clarify these questions.
It would be nice if your clarifications are included in the tutorial.
I was stuck on the plugin-less installation as well, because I just followed the steps in the tutorial.
You might be underestimating how often people just copy code sections without reading the insides.

Yeah a lot of people DO just follow the tutorial which is ok if you know Ubuntu well enough to get yourself out of trouble. If not, chances are you’ll get so lost during troubleshooting and trying fix things you end up just reloading the OS from scratch and starting over. Which is ok because repetition does make for getting things right and learning, but when all you want to do is get some subsystem working it can make for a frustrating time.

Which is the primary reason I take time to write comments, respond if I’ve gotten something wrong, and most of all just to make corrections for the next guy. This is a relatively well written tutorial which is one reason I come back to it occasionally. I sometimes use it as a template if I need to install multiple machines.

Anyways, I run a small hosting business so have dealt with many WordPress issues. Most of my clients have the whole OS to contend with as well on top of WordPress. I do offer free and introductory accounts. If you need some help or have any interest you can send a mail to support@fbr1.us or support@zettabytes.org. Mention this thread and the message will get filtered to me.

Ron

Hey guys,

thank you for the guide, all worked well until I got this problem:
“You won’t be able to install new themes from here yet since your install requires SFTP credentials. For now, please add themes in the admin.”

After a few hours - yes really :hot_face: I found a solution on another forum, I thought I’d share it here

Open wp-config.php with your text editor of choice and add the following line to the end of the file:

define(‘FS_METHOD’,‘direct’);
?>
Save and reload apache

Now, I can install themes etc without being asked to put an FTP account info for AWS EC2

Cheers

Emanuel

Seems like the following mysql command is not correct:

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
-> ON wordpress.*
-> TO wordpress@localhost
-> IDENTIFIED BY ‘’;

It produces ERROR 1064 (42000)

According to this post:
You don’t use IDENTIFIED BY in GRANT queries, it’s used in CREATE USER.

CREATE USER 'root'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

https://stackoverflow.com/questions/52372165/mysql-error-1064-42000-you-have-an-error-in-your-sql-syntax

1 Like