{"id":2074,"date":"2016-03-16T14:14:59","date_gmt":"2016-03-16T13:14:59","guid":{"rendered":"https:\/\/denbeke.be\/blog\/?p=2074"},"modified":"2016-11-25T16:28:44","modified_gmt":"2016-11-25T15:28:44","slug":"serving-owncloud-with-caddy","status":"publish","type":"post","link":"https:\/\/denbeke.be\/blog\/webdevelopment\/serving-owncloud-with-caddy\/","title":{"rendered":"Serving ownCloud with Caddy"},"content":{"rendered":"<p>In this post, I&#8217;ll walk you through how to set up ownCloud with Caddy for a secure, personal cloud service. I wrote this guide while configuring on Ubuntu 14.<\/p>\n<h2 id=\"owncloud\">ownCloud<\/h2>\n<p>A quick introduction to <a href=\"https:\/\/owncloud.org\">ownCloud<\/a> for those who never heard about it (as found on Wikipedia):<\/p>\n<blockquote><p>OwnCloud (stylized ownCloud) is a suite of client-server software for creating file hosting services and using them. OwnCloud is functionally very similar to the widely used Dropbox, with the primary functional difference being that OwnCloud is free and open-source, and thereby allowing anyone to install and operate it without charge on a private server, with no limits on storage space (except for disk capacity or account quota) or the number of connected clients.<\/p><\/blockquote>\n<h2 id=\"installing-mariadb\">Installing MariaDB<\/h2>\n<p>ownCloud requires a database server, so we&#8217;ll start by installing MariaDB.<br \/>\nThe following command will install MariaDB server and client:<\/p>\n<pre><code>$ sudo apt-get install mariadb-server<\/code><\/pre>\n<p>Once you have MariaDB installed you need to secure your installation. This will guide you through some steps.<\/p>\n<pre><code>$ sudo \/usr\/bin\/mysql_secure_installation<\/code><\/pre>\n<h2 id=\"creating-the-owncloud-user-and-database\">Creating the ownCloud user and database<\/h2>\n<p>Now you need to login to the MySQL command line with the root credentials.<br \/>\nUse the following command, and type your root password.<\/p>\n<pre><code>$ mysql -u root -p<\/code><\/pre>\n<p>Once logged in we create a new database for ownCloud:<\/p>\n<pre><code>MariaDB [(none)]&gt; create database owncloud;<\/code><\/pre>\n<p>and a new user:<\/p>\n<pre><code>MariaDB [(none)]&gt; grant usage on *.* to owncloud@localhost identified by 'somepassword';<\/code><\/pre>\n<p>and give that user access to the newly created database:<\/p>\n<pre><code>MariaDB [(none)]&gt; grant all privileges on owncloud.* to owncloud@localhost;<\/code><\/pre>\n<p>Now you have a user <code>owncloud<\/code> with password <code>somepassword<\/code> which has access to the database called <code>owncloud<\/code>.<\/p>\n<h2 id=\"installing-php-fpm\">Installing PHP-FPM<\/h2>\n<p>Since PHP 7 was released a couple of months ago, there is no reason not to install this newer version.<\/p>\n<p>First we need to add the repository which contains PHP 7:<\/p>\n<pre><code>$ sudo add-apt-repository ppa:ondrej\/php\r\n$ sudo apt-get update<\/code><\/pre>\n<p>Now we can install PHP:<\/p>\n<pre><code>$ sudo apt-get install php7.0-fpm<\/code><\/pre>\n<p>Simply installing PHP isn&#8217;t enough, in order to have ownCloud working properly, you also need some extra PHP extensions. A list of all ownCloud requirements can be found <a href=\"https:\/\/doc.owncloud.org\/server\/7.0\/admin_manual\/installation\/source_installation.html\">here<\/a>. The extensions below are recommended for ownCloud and not included in the default PHP installation:<\/p>\n<ul>\n<li>PHP mysql driver<\/li>\n<li>PHP gd<\/li>\n<li>PHP curl<\/li>\n<li>PHP intl<\/li>\n<li>PHP mcrypt<\/li>\n<li>PHP imagick<\/li>\n<\/ul>\n<p>You can install them all at once:<\/p>\n<pre><code>$ sudo apt-get install php7.0-mysql php7.0-gd php7.0-curl php7.0-intl php7.0-mcrypt <\/code><\/pre>\n<p>If you need previews for videos and documents you also need to install the following (non-PHP) packages:<\/p>\n<ul>\n<li>ffmpeg or avconv<\/li>\n<li>LibreOffice<\/li>\n<\/ul>\n<p>For optimal integration with Caddy, accepting PHP-FPM request on a TCP socket instead of a Unix socket is better:<br \/>\nReplace <code>listen = \/run\/php\/php7.0-fpm.soc<\/code> to <code>listen = 127.0.0.1:9000<\/code> in <code>\/etc\/php\/7.0\/fpm\/pool.d\/www.conf<\/code>.<\/p>\n<p><em>Don&#8217;t forget to restart PHP-FPM: <code>sudo service php7.0-fpm restart<\/code> after installing all extensions.<\/em><\/p>\n<h2 id=\"caddyfile\">Caddyfile<\/h2>\n<p>I made the following Caddyfile together with <em>mholt<\/em> and <em>dprandzioch<\/em>. The config contains everything you need for hosting ownCloud server and also supports the desktop and mobile clients.<\/p>\n<pre><code>my-owncloud-site.com {\r\n\r\n    root owncloud\r\n    log owncloud\/access.log\r\n    errors owncloud\/access.log\r\n\r\n    fastcgi \/ 127.0.0.1:9000 php {\r\n            env PATH \/bin\r\n    }\r\n\r\n    rewrite {\r\n        r ^\/index.php\/.*$\r\n        to \/index.php?{query}\r\n    }\r\n\r\n    # client support (e.g. os x calendar \/ contacts)\r\n    redir \/.well-known\/carddav \/remote.php\/carddav 301\r\n    redir \/.well-known\/caldav \/remote.php\/caldav 301\r\n\r\n    # remove trailing \/ as it causes errors with php-fpm\r\n    rewrite {\r\n        r ^\/remote.php\/(webdav|caldav|carddav)(\\\/?)$\r\n        to \/remote.php\/{1}\r\n    }\r\n\r\n    rewrite {\r\n        r ^\/remote.php\/(webdav|caldav|carddav)\/(.+)(\\\/?)$\r\n        to \/remote.php\/{1}\/{2}\r\n    }\r\n\r\n    status 403 \/forbidden\r\n\r\n    # .htacces \/ data \/ config \/ ... shouldn't be accessible from outside\r\n    rewrite {\r\n        r ^\/(?:\\.htaccess|data|config|db_structure\\.xml|README)\r\n        to \/forbidden\r\n    }\r\n    \r\n    header \/ Strict-Transport-Security \"15768000\"\r\n    \r\n}<\/code><\/pre>\n<p>Thanks to Caddy&#8217;s <a href=\"https:\/\/letsencrypt.org\">Let&#8217;s Encrypt<\/a> integration, our ownCloud installation is automatically secured and served over HTTPS. Access and error logs are written to the ownCloud folder, and the data folder (together with other special files) is protected against requests from the outside.<\/p>\n<p>If you want to test your Caddyfile \/ PHP installation, you can create a <code>phpinfo.php<\/code> file in the <code>owncloud<\/code> directory, and put the following line into it:<\/p>\n<pre><code>&lt;?php phpinfo(); ?&gt;<\/code><\/pre>\n<p>Then navigate to <code>https:\/\/my-owncloud-site.com\/phpinfo.php<\/code> with your browser and check if the default PHP info page is displayed. (of course after Caddy is running with your Caddyfile)<br \/>\n<em>Don&#8217;t forget to delete this file after everything is working! Other people don&#8217;t need to know your exact PHP installation with limits and extensions.<\/em><\/p>\n<h2 id=\"installing-configuring-owncloud\">Installing &amp; Configuring ownCloud<\/h2>\n<p>Now it&#8217;s finally time to install ownCloud.<\/p>\n<p>Download the latest ownCloud version (at the time of writing <code>9.0.0<\/code> was the latest version, check this for yourself):<\/p>\n<pre><code>$ wget https:\/\/download.owncloud.org\/community\/owncloud-9.0.0.zip<\/code><\/pre>\n<p>Unzip the files into the <code>owncloud<\/code> directory:<\/p>\n<pre><code>$ unzip owncloud-9.0.0.zip<\/code><\/pre>\n<p>Go to <code>https:\/\/my-owncloud-site.com<\/code> with your web browser. If everything works fine, you will see the ownCloud configuration screen.<\/p>\n<p>However, you need to create a <code>data<\/code> folder for ownCloud and give ownCloud (i.e. <code>www-data<\/code> user) write\/read access to it.<\/p>\n<pre><code>$ mkdir owncloud\/data\r\n$ sudo chown -R www-data owncloud<\/code><\/pre>\n<h2 id=\"concluding\">Concluding<\/h2>\n<p>Caddy&#8217;s rapid development makes it a choice candidate for serving your OwnCloud installation securely and easily.<\/p>\n<p>This blogpost was originally written for the official\u00a0Caddy blog:\u00a0<a href=\"https:\/\/caddyserver.com\/blog\/caddy_and_owncloud\" target=\"_blank\">Running ownCloud with Caddy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I&#8217;ll walk you through how to set up ownCloud with Caddy for a secure, personal cloud service. I wrote this guide while configuring on Ubuntu 14. ownCloud A quick introduction to ownCloud for those who never heard about it (as found on Wikipedia): OwnCloud (stylized ownCloud) is a suite of client-server software [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[227,112],"tags":[260,249,240,151,208,215,186],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v15.6.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Serving ownCloud with Caddy &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\/webdevelopment\/serving-owncloud-with-caddy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Serving ownCloud with Caddy &ndash; DenBeke\" \/>\n<meta property=\"og:description\" content=\"In this post, I&#8217;ll walk you through how to set up ownCloud with Caddy for a secure, personal cloud service. I wrote this guide while configuring on Ubuntu 14. ownCloud A quick introduction to ownCloud for those who never heard about it (as found on Wikipedia): OwnCloud (stylized ownCloud) is a suite of client-server software [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/denbeke.be\/blog\/webdevelopment\/serving-owncloud-with-caddy\/\" \/>\n<meta property=\"og:site_name\" content=\"DenBeke\" \/>\n<meta property=\"article:published_time\" content=\"2016-03-16T13:14:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-11-25T15:28:44+00:00\" \/>\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=\"4 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\":\"WebPage\",\"@id\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/serving-owncloud-with-caddy\/#webpage\",\"url\":\"https:\/\/denbeke.be\/blog\/webdevelopment\/serving-owncloud-with-caddy\/\",\"name\":\"Serving ownCloud with Caddy &ndash; DenBeke\",\"isPartOf\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#website\"},\"datePublished\":\"2016-03-16T13:14:59+00:00\",\"dateModified\":\"2016-11-25T15:28:44+00:00\",\"author\":{\"@id\":\"https:\/\/denbeke.be\/blog\/#\/schema\/person\/386878f712fe3fe22227216f087772dc\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/denbeke.be\/blog\/webdevelopment\/serving-owncloud-with-caddy\/\"]}]},{\"@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\/2074"}],"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=2074"}],"version-history":[{"count":5,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions"}],"predecessor-version":[{"id":2213,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/posts\/2074\/revisions\/2213"}],"wp:attachment":[{"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/media?parent=2074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/categories?post=2074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/denbeke.be\/blog\/wp-json\/wp\/v2\/tags?post=2074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}