Pothibo

Clean Slate: Install wordpress on nginx. Arch linux style

You decided to start a blog and want to host wordpress on your dedicated server. You might have had a look at Wordpress Install page but you are missing some informations? By definition, Arch doesn’t have a lot installed so you are missing some packages and it can be confusing as what you need to install, what needs to be installed and so on.

I’ll cover my installation process using Arch Linux 2013.05.01. I assume you have a fresh install and you have root access to your machine. Also, I have the assumption that you can edit a file in command line. Let’s get started:

Packages

Worpdress needs a few packages.

  • Mysql (Arch uses mariaDB which is the same as Mysql, if you want to know more, you can read about it on wikipedia;
  • Php & friends;
  • Nginx (Apache is an equally good choice);
  • Unzip (Wordpress comes zipped!).
# pacman -S php php-fpm mariadb nginx unzip

Remember the password you used with mariadb. We will need it to log into the database later.

Installing Wordpress

In some distribution, /var/www is used as the document root for their web server. Arch uses a better different path: /srv/http. Let’s install wordpress in that folder.

# cd /srv/http
# wget http://wordpress.org/latest.zip && unzip latest.zip && rm latest.zip

Small but important change is needed: We have downloaded the file under root privileges. We need to change the user owner as well as the group.

# chown -R http wordpress/
# chgrp -R http wordpress/

Configuring Nginx

Nginx has server rules which are very similar to virtual hosts in Apache. Before setting wordpress’ server up, I like the way ubuntu/debian handles their configuration. In /etc/nginx folder, there is 2 folders. One name “sites-available” and the other, “sites-enabled”. This let you have many configuration files in sites-available and you symlink the configuration you want live in sites-enabled. This is was we are going to do.

# cd /etc/nginx && mkdir sites-enabled && mkdir sites-available

Now this is the single place where you are left a bit by yourself. You will have to edit nginx.conf to include 2 different rules in the http { } directive, just before the close bracket ( } )

http {
 // many directives
 upstream php {
	    server unix:/var/run/php-fpm/php-fpm.sock;
    }
  include sites-enabled/*;
}

Now you want to create a new file /etc/nginx/sites-available called “wordpress.conf”

server {
  server_name yourdomain.com; # Change yourdomain.com for whatever your domain is!
  root /srv/http/wordpress;

  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
  }

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  location ~ \.php$ {
	try_files $uri =404;

	fastcgi_split_path_info ^(.+\.php)(/.+)$;

	include fastcgi_params;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  	fastcgi_pass php;
  }
}

We want this configuration file to be launch with nginx so let’s symlink it

# cd /etc/nginx/sites-enabled/

# ln -s ../sites-available/wordpress.conf wordress.conf

Launching services with systemd

Time to launch nginx and friends. Arch Linux uses systemd as its service manager. This is one of the reason I enjoy working with Arch. Most of the things working with systemd works as “services”. First step is to enable the services we need (nginx, php-fpm and mariadb) and then start them.

# systemctl enable nginx php-fpm mysqld

# systemctl start nginx php-fpm mysqld

A note here that even though mariadb is installed on the system, the service is name mysqld since mariadb is a drop-in replacement for mysql.

Configuring mariaDB and wordpress config.

The last piece of the puzzle is mariadb. We haven’t talked about it until now but it’s not because it’s trivial. If you know some of the tools/commands, they are the same. So for our installation to work, we need to create a database and a user for wordpress.

# mysql -u root -p yourpassword

You should be in mariaDB Command line tool. When creating our new user, we want to make sure that this user only has privileges to its wordpress database.

$> CREATE DATABASE wordpress;
$> CREATE USER 'wp_admin'@'localhost' IDENTIFIED BY 'yourpassword';
$> GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_admin'@'localhost';
$> FLUSH PRIVILEGES;

It’s now time to configure wordpress’ with the credentials we just created.

# cd /srv/http/wordpress/
# cp wp-config-sample.php wp-config.php

Open up wp-config.php and replace those lines with the credentials from mariadb.

/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wp_admin');

/** MySQL database password */
define('DB_PASSWORD', "yourpasswordforuserwp_admin");

Fire up your browser and points it to yourdomain.com. You should be welcomed by Wordpress first time configuration panel! Drop a line below if you need help.

If you liked this tutorial, you should follow @pothibo.

Get more ideas like this to your inbox

You will never receive spam, ever.