In the 1st part of this series, we installed all the necessary files and packages. We also created a basic Apache configuration for our blog.
In the 2nd part of this series, we created a dedicated MariaDB database and user for WordPress.
In this post you’re in for some fun. It’s the day to setup WordPress and actually start blogging. Now that we did our homework, we simply need to rely on WordPress famous 5 minutes initialization process.
Finally we’re going to improve the blog’s SEO by looking into permalinks and learn how to tweak the post URLs.
1. WordPress 5min Installation
1.1 Language Setup
If you’ve been following this series, you may recall in the 1st part actually seeing the very first screenshot of WordPress setup:
In case you need it, you can force the redirection to the setup page by adding /wp-admin to the URL after your Raspberry Pi IP address.
Hopefully this 1st screen is self-explanatory, just select the language you would like to use in WordPress’ interface.
The next screens should be as easy as long as you take the time to carefully read the instructions:
1.2 Database Setup
In simple terms, WordPress is about to create a wp-config.php file in its root directory (i.e. /var/www/html/wordpress) with all the required information to access the database.
This is where everything we did in the 2nd post of this series comes into play:
Once more this should be simple enough. Remember, we created a database called wordpress, as well as a user also called wordpress, who could connect to MariaDB, only from localhost and has all the access rights to the wordpress database.
Obviously replace <your database password> with the appropriate value.
One word about the Table Prefix parameter. As the name suggests, it’s a prefix added to all tables created by WordPress. This is very handy if say, you have a limited number of databases. By prefixing the tables used by different software (or even several WordPress installations) you avoid potential data collisions.
It’s important to understand that all the information provided above are saved in clear text in the wp-config.php file! Thus I hope you now see why we created a dedicated user and database, with the proper privileges in the previous post.
Indeed, assuming the worst, would a bad guy succeed in breaching your server and get access to the file system, at least he wouldn’t get MariaDB’s root password, but merely access to WordPress’ database. Any other database would remain safe.
1.3 Blog Setup
Moving on, let’s create a first user and give the blog a title !
As a last step, enter a name for your blog, then add a username and password for your 1st user, who’ll be a WordPress administrator.
And you’re done ! Point your browser to your Raspberry Pi IP address and you’ll see your blog’s home page.
2. Improving SEO
2.1 Pretty URLs
Before calling it a day, there is one more thing we need to take care about. This has to do with WordPress permalinks.
Out of the box WordPress doesn’t enable pretty URLs. Your posts show up with links like: https://your.domain.net/?p=14.
As you may have guessed, p=14 is a post ID in WordPress database. But the link itself doesn’t provide much information regarding what the post is really about.
A much better link should be human readable and could look something like: https://your.domain.net/your_post_title.
There the link has meaning, it gives clues about the post content (provided it has a carefully crafted title). Search engines and Google, in particular, use URLs as one of many signals to rank documents (including your posts). In other words, it helps with SEO (Search Engine Optimization) and you have better chances of appearing among the top search results.
Simply put, changing the URL structure is a must.
Fortunately WordPress allows to do this rather easily. However Apache must be configured first to support the feature and this is what we’re going to do next.
2.2 Apache mod_rewrite
$ cd /etc/apache2/mods-available/
$ ls -l rewrite*
$ cd ../mods-enabled/
$ sudo a2enmod rewrite
Similarly to what we’ve seen with sites, a2enmod creates a link in /etc/apache2/mods-enabled to the rewrite module in the /etc/apache2/mods-available directory. This tells Apache to load the module on startup.
Although you wish you’re done, we must also change Apache’s WordPress site configuration wordpress.conf:
$ cd /etc/apache2/sites-available
$ sudo vi wordpress.conf
After the line:
The AllowOverride directive allows Apache configuration to be overridden (per directory) in a .htaccess file. The FileInfo enables the rewrite module.
Finally, let Apache reload the configuration:
$ sudo systemctl reload apache2
2.3 WordPress Permalinks
The last step consists in enabling the URL structure we’d like to use for our posts in WordPress:
In this example I’ve chosen to use the post name as the main URL for my posts but other options are available.
Remember I mentioned a file called .htaccess? After enabling permalinks WordPress creates such a file in its root directory to configure Apache URL rewriting module as necessary.
$ cd /var/www/html/wordpress/
$ ls -lA $ cat .htaccess
3. Final Words
And voilà, you’re now ready to start blogging like crazy. You’re in control of your own WordPress installation, the rest is up to you and mostly a matter of inspiration.
As usual don’t hesitate to let me know if you’ve found this blog post useful, if you’ve found anything inaccurate or even errors.
Previously in this series:
- WordPress On Raspberry Pi – Part 1 – Preparation: packages and archives installation, initial Apache configuration
- WordPress On Raspberry Pi – Part 2 – Database: MariaDB user and database creation for WordPress
- WordPress On Raspberry Pi – Part 4 – phpMyAdmin Installation