This is my little how-to on installing and configuring Wordpress on Arch Linux with nginx+php-fpm. It is by no means the best way to do it or even complete, but it helped me get my blog out in minutes.

Assuming your already installed MySQL(or MariaDB), nginx via pacman and php-fpm from the AUR.

First configure php-fpm.

[www]
# The user nginx and php-fpm does run under.
user = nginx
group = nginx

# listen on a sock-file instead of a port.
listen = /var/run/php5-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Then edit the php.ini to enable the MySQL-plugins:

extension=mysqli.so
extension=mysql.so

Now the important part, the nginx-configuration.

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;

events {
worker_connections 1024;
}

proxy_buffers 16 16k;
proxy_buffer_size 32k;

Next on is the custom Wordpress-configuration:

server {
    listen          80;
    root            /var/www/html/blog;
    server_name     zufallsheld.de;
    index           index.php;

    # Use gzip compression
    # gzip_static on; # Uncomment if you compiled Nginx using --with-http_gzip_static_module
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 5;
    gzip_buffers 16 8k;
    gzip_http_version 1.0;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;

     # Cache static files for as long as possible
    location ~* \.(xml|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
    try_files $uri =404;
    expires max;
    access_log off;
    }

     # Don't cache uris containing the following segments
    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
    set $cache_uri "no cache";
    }

    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp\-postpass|wordpress_logged_in") {
    set $cache_uri 'no cache';
    }

    # Use cached or actual file if they exists, otherwise pass request to WordPress
    location / {
    try_files /wp-content/w3tc/pgcache/$cache_uri/_index.html $uri $uri/ /index.php?q=$uri&$args;
    }

    # Rewrite minified CSS and JS files
            location ~* \.(css|js) {
            if (!-f $request_filename) {
            rewrite ^/wp-content/w3tc/min/(.+\.(css|js))$ /wp-content/w3tc/min/index.php?file=$1 last;
            }
    }

    # Add trailing slash to */wp-admin requests.
    rewrite         /wp-admin$ $scheme://$host$uri/ permanent;
     # Don't cache uris containing the following segments
    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
    set $cache_uri "no cache";
    }

    location ~ \..*/.*\.php$ {
            return 404;
    }

    # normal php-configuration
    location ~* ^/(.*\.php)$ {
            #logging
            access_log /var/log/nginx/blog.access.log;
            error_log /var/log/nginx/blog.error.log notice;

            try_files $uri $uri/ index.php;
            include /etc/nginx/fastcgi_params;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            # connect to php-fpm via socket-file
            fastcgi_pass  unix:/var/run/php5-fpm.sock;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\. {
            deny all;
    }

    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
            deny all;
    }

}

And that’s basically it. Now just open the browser and point it to http://yourdomain/wp-admin/install.php and configure Wordpress to connect to your mysql-instance.

Helpful resources:



Related posts: