Wordpress local installation on Arch Linux

Matthew CharlesMattMullenweg (born January 11, 1984 in Houston, Texas) is an American online social mediaentrepreneur, web developer and musician living in San Francisco, California. He is best known for developing the free and open source web software WordPress, now managed by The WordPress Foundation.

I thank you and all those great souls who contribute to this wonderful system!

A Content Management System (CMS) is very necessary for anyone serious about knowledge and its management.There are many such systems available:

Choices are many and all have pros and cons. I stumbled upon WordPress and have been mesmerised by the power and beauty of the system. I have not tried the other systems due to the limited time available to me but WordPress seems to be the easiest CMS system. The epiphany that WordPress can be used locally for managing all my knowledge was just unbelievable. I created an intranet WordPress blogging system at my workplace and that blew everyone’s mind. Even mine! That was on a Windows machine. WAMP package is available for Windows which makes installing the complete WAMP Stack (Windows, Apache, MySQL, PHP) a breeze. I use Manjaro Linux as my primary OS at home. In Linux world we have the LAMP Stack (Linux, Apache, MySQL, PHP) but no single package equivalent to the WAMP.

Why exactly do we need a WordPress blog on local system?

  • The full power of WordPress in offline mode
  • Can be used as a diary, notebook, journal, knowledge repository etc. and is strictly personal
  • One can easily create a blog at WordPress.com and share with the world. For data not intended for sharing a local WordPress is great
  • Database driven and also maintains history – This is one of the most important features for students and researchers
  • Unlike Word documents or PDFs, links can be used to avoid a static linear mode of learning (which is boring)

It is certainly a big task, at least for someone who has no experience with the LAMP stack. **Read the manual. **There is no way around the Arch documentation. It is one of the best and needs to be respected. Reading the doc will save a lot of trouble. Let me jot down what I did to get the system up and running. This is just a summary. This worked for me and should for most of the people reading, but remember that there are too many variables and the great Arch documentation is the only place to get the complete information:

WordPress installation is pretty straightforward and takes only 5 minutes or so. It is the pre-requisites that will make buttocks sore.

The task can be broken down into the following smaller tasks:

  1. Install Apache server
  2. Install MySQL (On Arch and Arch based systems MariaDB has replaced MySQL. Why? Well, read this Wikipedia article.)
  3. Install PHP
  4. Install phpMyAdmin
  5. Install WordPress
  6. Configure Apache
  7. Configure MariaDB using the phpMyAdmin front-end (GUI)

Install pre-requisites

Install Apache

sudo pacman -S apache

Install MariaDB

sudo pacman -S mariadb

Install PHP

PHP: Hypertext Preprocessor or PHP can be installed using the following command:

sudo pacman -S php php-apache

Install phpMyAdmin

phpMyAdmin is a web-based tool to help manage MariaDB/MySQL databases using an Apache/PHP front-end. Commandline can be used for managing but it does not hurt to have a GUI.

sudo pacman -S phpmyadmin

Done installing all the pre-requisites. The LAMP stack is ready to rumble.

Configure pre-requisites

Configuring Apache

Once installed, Apache is ready to serve. The installation creates a User ID http and a Group ID **http. **These defaults should be good enough. Now use **systemd and start the httpd **service

sudo systemctl start httpd

This should start the Apache server. To test visit http://localhost/

The port option in the /etc/httpd/conf/httpd.conf needs some attention. The current setup is for a local WordPress with no internet access intended at all. That means, the server should listen to the local machine ONLY and serve no other request from any other machine.

So, change

Listen 80

to

Listen 127.0.0.1:80

The home directory permissions need to be properly set so that Apache can access the extracted WordPress directory. The following should do the trick:

chmod o+x ~

Configuring MariaDB

Start the MariaDB service

<code style="display:inline-block;padding:.1em .3em;">sudo systemctl start mysqld.service

There is a setup script which, when run, will configure MariaDB. Just type the following on the CLI

mysql_secure_installation

This setup script will ask a few questions. Answer them honestly:) At the end, MariaDB will be ready with a proper root user and password.

Configuring PHP

Apache needs to be configured to run PHP.

Enable PHP by adding the following lines to the /etc/httpd/conf/httpd.conf

  • Add the following in the LoadModule list anywhere after LoadModule dir_module modules/mod_dir.so:

LoadModule php5_module modules/libphp5.so

  • Add the following at the end of the Include list

Include conf/extra/php5_module.conf

Restart the httpd service

sudo systemctl restart httpd

Create a file called test.php in Apache DocumentRoot (in my case /srv/http) ``directory

To see if it works go to: http://localhost/test.php

Enable the mysqli and mcrypt extensions in PHP. Uncomment the following lines in /etc/php/php.ini:

extension=mysqli.so extension=mcrypt.so

Note:

There is a possibility that the following error may show up

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. AH00013: Pre-configuration failed httpd.service: control process exited, code=exited status=1

When this happens open /etc/httpd/conf/httpd.conf and replace

LoadModule mpm_event_module modules/mod_mpm_event.so

with

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Configure MariaDB for WordPress using phpMyAdmin

First, configure phpMyAdmin. Create /etc/httpd/conf/extra/httpd-phpmyadmin.conf and add the following content to it

Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin" <Directory "/usr/share/webapps/phpMyAdmin"> DirectoryIndex index.html index.php AllowOverride All Options FollowSymlinks Require all granted

Include it in /etc/httpd/conf/httpd.conf

phpMyAdmin configuration Include conf/extra/httpd-phpmyadmin.conf

Restart the Apache service

sudo systemctl restart httpd

  1. Go to http://localhost/phpmyadmin/
  2. Login as **root **with the password created during the MariaDB setup
  3. Create a user
  4. Create a DB for WordPress

Now that all the pre-requisites are installed and configured, it is time for the WordPress install.

Install WordPress

Do not install from the official Arch repositories. Why? Because,

**Warning: **While it is easier to let pacman manage updating your WordPress install, this is not necessary. WordPress has functionality built-in for managing updates, themes, and plugins. If you decide to install the official community package, you will not be able to install plugins and themes using the WordPress admin panel without a needlessly complex permissions setup, or logging into FTP as root. pacman does not delete the WordPress install directory when uninstalling it from your system regardless of whether or not you have added data to the directory manually or otherwise.

So, just get the zip from the WordPress.org website and unzip it.

Configure WordPress

Create /etc/httpd/conf/extra/httpd-wordpress.conf so that Apache can find WordPress and add the following content:

Alias /wordpress "/usr/share/webapps/wordpress" <Directory "/usr/share/webapps/wordpress"> AllowOverride All Options FollowSymlinks Require all granted php_admin_value open_basedir "/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:$"

The alias /wordpress in the first line can be changed. For example, /myblog would require navigating to http://hostname/myblog to see the local WordPress website.
/usr/share/webapps/wordpress is the install location when WordPress is installed from the official repos. So, change the paths to WordPress install folder. Append the parent directory to the php_admin_value variable without fail:

Alias /myblog "/home/arandomuser/wordpress" <Directory "/home/arandomuser/wordpress"> AllowOverride All Options FollowSymlinks Require all granted php_admin_value open_basedir "/home/arandomuser/:/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:$"

Now, open /etc/httpd/conf/httpd.conf and add the following line:

Include conf/extra/httpd-wordpress.conf

The extracted WordPress directory contains a file wp-config-sample.php which needs to be renamed to wp-config.php and modify the following lines correctly:

// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress / define('DB_NAME', 'wordpressDB'); /* MySQL database username / define('DB_USER', 'arandomuser'); /* MySQL database password / define('DB_PASSWORD', 'thePassword'); /* MySQL hostname */ define('DB_HOST', 'localhost');

Once all this is done, navigate to http://localhost/wordpress

WordPress should be available for personal knowledge management.

WordPress Issues

The default permalinks are not pleasing at all. They need to be changed. For me, a permalink should have the following structure:

http://localhost/wordpress/2014/06/08/sample-post/

So, I went to the Dashboard -> Settings -> Permalinks and looked at the options. The desired option was available. I chose the one I wanted and asked WordPress to save my permalink choice. It refused saying:

If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. Click in the field and press CTRL + a to select all.

It generated a text box that contained the following text which needs to be added to the .htaccess file:

RewriteEngine On RewriteBase /wordpress/ RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /wordpress/index.php [L]

This is where the beauty of .htaccess file became quite apparent. The directory where WordPress was extracted, say, /home/arandomuser/wordpress, should have a .htaccess file with the aforementioned text to make new permalinks work. This is the same directory where the index.php file resides.

I went to the directory and found no .htaccess there. I created one and pasted the required text. I tried using the new permalink to navigate to my posts. No success!

Further research pointed me to the /etc/httpd/conf/httpd.conf file where a module needs to be enabled. So, I uncommented the following line:

LoadModule rewrite_module modules/mod_rewrite.so

Everything works now!

I will soon be installing WordPress at workplace on a dedicated server. It will be a Windows machine. It will surely be simpler than this but I will jot down my experience.

Further research