{"id":1894,"date":"2015-08-21T11:18:12","date_gmt":"2015-08-21T10:18:12","guid":{"rendered":"http:\/\/denbeke.be\/blog\/?p=1894"},"modified":"2016-02-02T18:48:00","modified_gmt":"2016-02-02T17:48:00","slug":"caddy-server-and-wordpress-php-fpm","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/","title":{"rendered":"Caddy Server and WordPress (PHP-FPM)"},"content":{"rendered":"<p><a href=\"http:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/attachment\/caddy-logo\/\" rel=\"attachment wp-att-1903\"><img loading=\"lazy\" class=\"alignright size-full wp-image-1903\" src=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/08\/Caddy-Logo.png\" alt=\"Caddy Logo\" width=\"95\" height=\"85\" \/><\/a><\/p>\n<p><em><span style=\"text-decoration: underline;\">Update:<\/span>\u00a0I added rewrite rules for WordPress permalinks to the Caddyfile. I also removed all unnecessary bits which are not needed anymore since Caddy now has built-in HTTPS support with\u00a0<a href=\"https:\/\/letsencrypt.org\" target=\"_blank\">Let&#8217;s Encrypt<\/a>.<\/em><\/p>\n<p>Recently I discovered an amazing open source project: <a href=\"https:\/\/caddyserver.com\" target=\"_blank\">Caddy<\/a>, a fully functional HTTP\/2 webserver, written in Go.<\/p>\n<blockquote><p><em>Caddy is a lightweight, general-purpose web server for Windows, Mac, Linux, BSD, and\u00a0<a href=\"https:\/\/github.com\/mholt\/caddy\/wiki\/Running-Caddy-on-Android\" target=\"_blank\">Android<\/a>. It is a capable alternative to other popular and easy to use web servers.<\/em><\/p>\n<p><em>The most notable features are HTTP\/2, Virtual Hosts, TLS + SNI, and easy configuration with a\u00a0<a href=\"https:\/\/caddyserver.com\/docs\/caddyfile\" target=\"_blank\">Caddyfile<\/a>. Usually, you have one Caddyfile per site. Most directives for the Caddyfile invoke a layer of middleware which can be\u00a0<a href=\"https:\/\/github.com\/mholt\/caddy\/wiki\/Using-Caddy-Middleware-in-Your-Own-Programs\" target=\"_blank\">used in your own Go programs<\/a>.<\/em><\/p><\/blockquote>\n<p>In this tutorial I will explain how to run\u00a0<a href=\"https:\/\/wordpress.org\" target=\"_blank\">WordPress<\/a> with Caddy server (on Ubuntu), using Caddy&#8217;s FastCGI support and <a href=\"http:\/\/php-fpm.org\" target=\"_blank\">PHP-FPM<\/a> (i.e. PHP FastCGI Process Manager). Of course you also need MySQL\/MariaDB to run WordPress.<\/p>\n<h3>MySQL<\/h3>\n<p>I assume that you have a MySQL server up and running\u00a0(or that you have the knowledge to do so) .<\/p>\n<h3>PHP<\/h3>\n<p>Install PHP-FPM:<\/p>\n<pre><code>$ sudo apt-get install php5-fpm<\/code><\/pre>\n<p>PHP-FPM listens to FastCGI requests on a unix socket by default (on Ubuntu and Arch Linux):\u00a0<code>unix:\/var\/run\/php5-fpm.sock<\/code> (or <code>unix:\/var\/run\/php\/php7.0-fpm.sock<\/code> for PHP 7). So we&#8217;ll\u00a0have to tell the webserver to pass the PHP requests to it.<\/p>\n<p>You could also use a regular UDP socket if you want: change <code>listen<\/code> in\u00a0<code>\/etc\/php5\/fpm\/pool.d\/www.conf<\/code> to <code>127.0.0.1:9000<\/code>. On some operating systems (e.g. FreeBSD), PHP-FPM listens on this UDP socket by default.<\/p>\n<h3>Caddyfile<\/h3>\n<p>Now we need to configure Caddy so it will use PHP-FPM.\u00a0We also need to specify virtual hosts for the domain(s) we will be using.<\/p>\n<p>The following Caddyfile contains everything you need to run WordPress with PHP-FPM on HTTP\/2.<\/p>\n<pre><code class=\"nohighlight\">www.my-wordpress-blog.com {\r\n    redir https:\/\/my-wordpress-blog.com{uri}\r\n}\r\n\r\nmy-wordpress-blog.com {\r\n    root wordpress\r\n    log access.log\r\n    errors error.log\r\n    \r\n    # PHP-FPM with Unix socket\r\n    fastcgi \/ \/var\/run\/php5-fpm.sock php\r\n    \r\n    # PHP-FPM with regular udp socket\r\n    # fastcgi \/ 127.0.0.1:9000 php\r\n\r\n    # Routing for WordPress\r\n    rewrite \/{\r\n        to {path} {path}\/ \/index.php?{query}\r\n    }\r\n}<\/code><\/pre>\n<p>Caddy will use the <code>wordpress<\/code> folder as document root, and will pass all PHP requests to a FastCGI process (which is the PHP-FPM process). It will also automatically install SSL certificates (from Let&#8217;s Encrypt) and serve the website over HTTPS. HTTP requests will be redirected to the HTTPS domain.<\/p>\n<p>The <a href=\"http:\/\/caddyserver.com\/docs\" target=\"_blank\">Caddy documentation<\/a> contains more detailed information on the available directives. Checkout my other blogposts if you need help\u00a0<a href=\"http:\/\/denbeke.be\/blog\/servers\/running-caddy-server-as-a-service\/\" target=\"_blank\">Running Caddy Server as a service<\/a>\u00a0or\u00a0<a href=\"http:\/\/denbeke.be\/blog\/servers\/creating-a-self-signed-ssl-certificate-on-linux\/\" target=\"_blank\">Creating a self-signed certificate<\/a>.<\/p>\n<h3>WordPress<\/h3>\n<p>Now it&#8217;s time to install WordPress. Simple download WordPress and copy the files to\u00a0the <code>wordpress<\/code> folder. To install WordPress you can just follow the steps on the screen like any other easy WordPress configuration.<\/p>\n<p>If you want to use HTTP\/2, you should configure WordPress with HTTPS enabled. You can do this in <em>Settings<\/em>, <em>General<\/em>: change <code>http<\/code> in the urls to <code>https<\/code>.<br \/>\nMost browsers only speak HTTP\/2 when using TLS. Although TLS only is not marked as mandatory in the <a href=\"https:\/\/tools.ietf.org\/html\/rfc7540\" target=\"_blank\">RFC 7540<\/a>,\u00a0Firefox and Chrome development teams have no actual\u00a0intents to implement HTTP\/2 without\u00a0TLS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update:\u00a0I added rewrite rules for WordPress permalinks to the Caddyfile. I also removed all unnecessary bits which are not needed anymore since Caddy now has built-in HTTPS support with\u00a0Let&#8217;s Encrypt. Recently I discovered an amazing open source project: Caddy, a fully functional HTTP\/2 webserver, written in Go. Caddy is a lightweight, general-purpose web server for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[227],"tags":[260,231,232,207,151,215,186,212],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Caddy Server and Wordpress (PHP-FPM) &ndash; DenBeke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Caddy Server and Wordpress (PHP-FPM) &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"Update:\u00a0I added rewrite rules for WordPress permalinks to the Caddyfile. I also removed all unnecessary bits which are not needed anymore since Caddy now has built-in HTTPS support with\u00a0Let&#8217;s Encrypt. Recently I discovered an amazing open source project: Caddy, a fully functional HTTP\/2 webserver, written in Go. Caddy is a lightweight, general-purpose web server for [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2015-08-21T10:18:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-02-02T17:48:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/08\/Caddy-Logo.png\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:creator\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:site\" content=\"@MthsBk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\">\n\t<meta name=\"twitter:data1\" content=\"3 minutes\">\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/denbeke.be\/blog\/#website\",\"url\":\"https:\/\/denbeke.be\/blog\/\",\"name\":\"DenBeke\",\"description\":\"Mathias Beke\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/denbeke.be\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/denbeke.be\/blog\/wp-content\/uploads\/2015\/08\/Caddy-Logo.png\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/\",\"name\":\"Caddy Server and Wordpress (PHP-FPM) &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/#primaryimage\"},\"datePublished\":\"2015-08-21T10:18:12+00:00\",\"dateModified\":\"2016-02-02T17:48:00+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/servers\/caddy-server-and-wordpress-php-fpm\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\",\"name\":\"Mathias Beke\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/denbeke.be\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/015ba35e6ce4f5859e3888ca99807575?s=96&d=mm&r=g\",\"caption\":\"Mathias Beke\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1894"}],"collection":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/comments?post=1894"}],"version-history":[{"count":20,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1894\/revisions"}],"predecessor-version":[{"id":2040,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/1894\/revisions\/2040"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=1894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=1894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=1894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}