{"id":2257,"date":"2015-06-25T13:46:26","date_gmt":"2015-06-25T20:46:26","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2257"},"modified":"2018-05-03T06:35:45","modified_gmt":"2018-05-03T13:35:45","slug":"spinning-up-a-new-virtual-machine","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2257","title":{"rendered":"Spinning up a new Virtual Machine"},"content":{"rendered":"<p>Most of my websites are low volume and so I host them on the same VPS at Linode. For a new project, I decided to put the websites on a separate VPS. I spent a day researching the current choices and you probably won\u2019t go wrong with any of them. For me, it came down to either Linode (which I\u2019ve been happy with) or Digital Ocean (which I\u2019ve used for backups and helping my nephew learn programming). Since I don\u2019t need a lot of space right now and I had a referral code, I decided to go with the $5\/mo Digital Ocean plan.<\/p>\n<p>Since I\u2019m familiar with it, I installed Ubuntu 14.04.2 LTS with Apache, MySQL, and PHP. I have some customizations that I made to make it consistent with my current server.<\/p>\n<h3>Users, Permissions, and Groups<\/h3>\n<p>The first thing I did was log in as root and create a new user\u2014me and add myself to the sudoer\u2019s table.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp; adduser myusername\n<\/code><\/pre><\/p>\n<p>There are a couple of ways to do this but for now I just added my user name directly instead of creating a sudoers group like I normally do.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;myusername ALL=(ALL:ALL) ALL\n<\/code><\/pre><\/p>\n<p>Without logging out of the root account, I logged in with my username and edited the \/etc\/ssh\/sshd_config. This was a test to see whether I could log in as myself and that I could edit files owned by root using sudo. I then changed PermitRootLogin  to no<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;# Authentication:\n&nbsp;&nbsp;&nbsp;&nbsp;PermitRootLogin no\n<\/code><\/pre><br \/>\nTo get the changes to take effect, I restarted the SSH daemon with <i>sudo service ssh restart<\/i>.<\/p>\n<p>I like to have a group that is able to edit all of the files in www. I call this different things on different machines, e.g. &#8216;staff&#8217;, &#8216;web-admin&#8217;, &#8216;www&#8217;. On this machine I\u2019m using &#8216;www&#8217;.<\/p>\n<p>If you type the command <i>groups<\/i>, you can see which groups you belong to. To add a new group you can edit the groups file or use these commands to add a group and add a member to a group.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;sudo groupadd www\n&nbsp;&nbsp;&nbsp;&nbsp;sudo usermod -a -G www myusername\n<\/code><\/pre><\/p>\n<h3>Fail2ban<\/h3>\n<p>I don\u2019t know how they find random IP addresses to attach, but 7 minutes after installing Fail2ban it banned the first site. Installation is straightforward. I didn\u2019t make any customizations except to add my IP address and change the email address for notifications.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;sudo apt-get install fail2ban\n&nbsp;&nbsp;&nbsp;&nbsp;sudo cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local\n&nbsp;&nbsp;&nbsp;&nbsp;sudo vi \/etc\/fail2ban\/jail.local\n&nbsp;&nbsp;&nbsp;&nbsp;sudo service fail2ban restart\n&nbsp;&nbsp;&nbsp;&nbsp;sudo iptables -L\n<\/code><\/pre><\/p>\n<h3>Updating Apache<\/h3>\n<p>First, I updated my .profile as I described in an earlier post. Then I changed the default location for my web pages from \/var\/www\/html to \/srv\/www. First I created a www directory in srv. Then made a symlink to it in root. <\/p>\n<p>I want everyone in the web admin group to be able to edit the files so I ran <i>sudo chown myusername:www www<\/i><\/p>\n<p>I edited the \/etc\/apache2\/apache2.conf file to change the default location to \/www and prevent directory listing\u2014I removed <i>Indexes<\/i> from <i>Options<\/i>.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;Directory \/www\/*&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Options FollowSymLinks\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride None\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Require all granted\n&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/Directory&gt;\n<\/code><\/pre><\/p>\n<p>I don\u2019t want people to see the contents of my .inc files. Some people add the suffix .php to them to hide them, but I prefer to make them all invisible to browsers.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n# We don&#039;t want people to see .inc files\n&lt;Files&nbsp;&nbsp;~ &quot;\\.inc$&quot;&gt;\n&nbsp;&nbsp;Order allow,deny\n&nbsp;&nbsp;Deny from all\n&lt;\/Files&gt;\n<\/code><\/pre><\/p>\n<p>I also don\u2019t want people to see the Subversion files from my WordPress installs and backups from old  projects that used Subversion (nowadays I use git).<\/p>\n<p><Directorymatch \"^\/.*\/\\.svn+\/\"><br \/>\n  Order deny,allow<br \/>\n  Deny from all<br \/>\n<\/Directorymatch><\/p>\n<p>And I don\u2019t want anyone to see .git files, although best practice says don\u2019t put them in document root.<\/p>\n<p><Directorymatch \"^\/.*\/\\.git+\/\"><br \/>\n  Order deny,allow<br \/>\n  Deny from all<br \/>\n<\/Directorymatch><\/p>\n<p>Since I don\u2019t have a domain name attached to this IP address, I added these lines to the bottom of the conf file.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;# Suppress the warning message when restarting Apache until we get a FQDN\n&nbsp;&nbsp;&nbsp;&nbsp;ServerName localhost\n<\/code><\/pre><\/p>\n<p>I have a couple of templates for websites so I put one in the www directory for testing. Then I changed the DocumentRoot in 000-default.conf to that directory and restarted Apache. <\/p>\n<h3>Miscellaneous<\/h3>\n<p>I don\u2019t plan to use a database for these websites, but I decided to set up MySQL and PhpMyAdmin. I followed the instructions at <a href='https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-secure-mysql-and-mariadb-databases-in-a-linux-vps'>Digital Ocean<\/a> to change the root password and add myself as a user.<\/p>\n<p>phpMyAdmin install is straightforward, except that you need to add this line:<br \/>\n<pre><code class=\"preserve-code-formatting\">\nInclude \/etc\/phpmyadmin\/apache.conf\n<\/code><\/pre><br \/>\nto the end of your \/etc\/apache2\/apache2.conf and restart Apache\u2014even if you are running the latest version of Ubuntu LTS.<\/p>\n<p>Then I installed git using the command sudo apt-get install git-core.<\/p>\n<p>Finally, I often convert MySQL databases to SQLite databases for use in Apple Apps so I installed SQLite.<br \/>\n<pre><code class=\"preserve-code-formatting\">\n&nbsp;&nbsp;&nbsp;&nbsp;apt-get install php5-sqlite\n&nbsp;&nbsp;&nbsp;&nbsp;sudo apt-get install sqlite3\n<\/code><\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of my websites are low volume and so I host them on the same VPS at Linode. For a new project, I decided to put the websites on a separate VPS. I spent a day researching the current choices and you probably won\u2019t go wrong with any of them. For me, it came down &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2257\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Spinning up a new Virtual Machine<\/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":[4],"tags":[],"class_list":["post-2257","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2257","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=2257"}],"version-history":[{"count":1,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2257\/revisions"}],"predecessor-version":[{"id":3104,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2257\/revisions\/3104"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}