{"id":1791,"date":"2013-12-24T17:26:23","date_gmt":"2013-12-25T01:26:23","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=1791"},"modified":"2014-01-15T11:50:27","modified_gmt":"2014-01-15T19:50:27","slug":"notes-on-setting-up-a-server","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=1791","title":{"rendered":"Notes on setting up a server."},"content":{"rendered":"<p>I\u2019m setting up a new Ubuntu server and while most of the defaults are fine, there are some things that I need to adjust. I have a very shallow understanding of this stuff, so there could be better and more secure ways to do this, but this works for me.<\/p>\n<h3>Disallow access to PHP include files<\/h3>\n<p>There isn\u2019t any reason that people need to see the include files that I use in my websites. You could name them .inc.php so that the raw code isn\u2019t available, but that\u2019s not very elegant, and outsiders can still access the file. There isn\u2019t anything particularly sensitive in them, but by themselves, they don\u2019t display correctly. So I added a few lines to my \/etc\/apache2\/apache2.conf file. Just below the section that disallows viewing .htacess files.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#\n# The following lines prevent .htaccess and .htpasswd files from being \n# viewed by Web clients. \n#\n&lt;Files ~ &quot;^\\.ht&quot;&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;Order allow,deny\n&nbsp;&nbsp;&nbsp;&nbsp;Deny from all\n&nbsp;&nbsp;&nbsp;&nbsp;Satisfy all\n&lt;\/Files&gt;\n\n# The following lines prevent .inc files from being\n# viewed by Web clients.\n#\n&lt;Files ~ &quot;\\.inc$&quot;&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;Order allow,deny\n&nbsp;&nbsp;&nbsp;&nbsp;Deny from all\n&lt;\/Files&gt;\n#\n<\/code><\/pre><\/p>\n<h3>Prevent directory browsing<\/h3>\n<p>If you have a bunch of images in a directory, then anyone who wants can view all of them just by looking at the web page source and putting the directory name after your URL. I\u2019d rather they not do that, so I restrict listing of the files by adding this line to my \/etc\/apache2\/httpd.conf file. On my default Ubuntu install this file is empty.<br \/>\n<pre><code class=\"preserve-code-formatting\">\nOptions Includes FollowSymLinks MultiViews\n<\/code><\/pre><\/p>\n<p>Restart Apache for the changes to take effect.<\/p>\n<h3>Alternate method to prevent directory browsing<\/h3>\n<p>If you want to prevent directory browsing in just one directory and either don\u2019t want to change the whole site or don\u2019t have access to the files named above, add this line to your .htaccess file.<br \/>\n<pre><code class=\"preserve-code-formatting\">\nOptions -Indexes\n<\/code><\/pre><\/p>\n<p>Probably don\u2019t have to restart Apache for changes to take effect.<\/p>\n<h3>Prevent Directory Browsing on a Per Site Basis<\/h3>\n<p>Changing the httpd.conf file will change the behavior of all sites on your server. If you want to change the behavior of just one site, edit its file in \/etc\/apache2\/sites-avalilable. Find the line that has Options FollowSymLinks in it and if it has Indexes in it, delete it. This is what the default Ubuntu install has.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&lt;Directory \/var\/www\/&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;Options Indexes FollowSymLinks MultiViews\n&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride None\n&nbsp;&nbsp;&nbsp;&nbsp;Order allow,deny\n&nbsp;&nbsp;&nbsp;&nbsp;allow from all\n&nbsp;&nbsp;&lt;\/Directory&gt;\n<\/code><\/pre><br \/>\nProbably do have to restart Apache for changes to take effect.<\/p>\n<h3>Prevent access to your include directory<\/h3>\n<p>Add this to your site\u2019s file in \/etc\/apache2\/sites-avalilable.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n#&lt;Directory \/www\/MySite\/include.php&gt;\n#&nbsp;&nbsp;&nbsp;&nbsp;Deny from all\n#&lt;\/Directory&gt;\n<\/code><\/pre><\/p>\n<h3>Show an error document instead of the default 404 error<\/h3>\n<p>Create a normal php document with your sites navigation and a message that says the file can\u2019t be found and maybe you can find it with the nav menus. Add this to your site\u2019s file in \/etc\/apache2\/sites-avalilable. And while you are at it, there is no reason you need to tell anyone that they don\u2019t have permission to see a particular file, just tell them it\u2019s not found, so add the same line for a 403 error. I take them back to the main page and display the missing file in the main page.<br \/>\n<pre><code class=\"preserve-code-formatting\">\nErrorDocument 404 \/index.php?p=missing\nErrorDocument 403 \/index.php?p=missing\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019m setting up a new Ubuntu server and while most of the defaults are fine, there are some things that I need to adjust. I have a very shallow understanding of this stuff, so there could be better and more secure ways to do this, but this works for me. Disallow access to PHP include &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=1791\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Notes on setting up a server.<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-1791","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1791"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/1791\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}