<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Sam's Ramblings</title>
    <description>Part-time tinkering with electronics, programming, photography and other obsessions
</description>
    <link>https://samwedge.uk/</link>
    <atom:link href="https://samwedge.uk/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 13 Jul 2021 07:15:04 +0000</pubDate>
    <lastBuildDate>Tue, 13 Jul 2021 07:15:04 +0000</lastBuildDate>
    <generator>Jekyll v3.9.0</generator>
    
      <item>
        <title>Migrating a wordpress site to a new server</title>
        <description>&lt;p&gt;I wanted to move some wordpress sites from an old server to a new one and wanted it to be as seamless as possible.
I really didn’t want to use an automated plugin - I’ve tried them in the past and they either don’t work (either badly coded or some missing PHP library)
or they require a paid subscription for some ongoing backup service that I don’t want.&lt;/p&gt;

&lt;p&gt;I decided to do it the old fashioned way, by logging on to the servers via ssh. Incidentally, the steps below can also be used
to provide a backup and restore process.&lt;/p&gt;

&lt;p&gt;The following assumes that you are connected via ssh as the root user. If not, you may need to amend some of the commands. It also assumes you’ve configured your webserver and MySQL.&lt;/p&gt;

&lt;p&gt;Note that any changes to the Wordpress site in between taking the backup and switching to the new server will be lost - obviously, as they aren’t backed up.&lt;/p&gt;

&lt;h3 id=&quot;backup-the-old-files&quot;&gt;Backup the old files&lt;/h3&gt;
&lt;p&gt;Create a location for the backup&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; ~/mysite_backup&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Take a dump of the mysql database to the backup folder, replacing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hostname&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;username&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;database_name&lt;/code&gt; with the relevant information and entering the password when prompted&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;mysqldump &lt;span class=&quot;nt&quot;&gt;-h&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;hostname&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; username &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; database_name &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; ~/mysite_backup/db.sql&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Copy in the wordpress files, printing out progress as it goes via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;verbose&lt;/code&gt; flag&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; path/to/wordpress/folder ~/mysite_backup/&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then we’ll create a gzipped archive. The options here are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;z - use gzip compression&lt;/li&gt;
  &lt;li&gt;c - creates an archive&lt;/li&gt;
  &lt;li&gt;v - verbose, tells us what’s going on while the archive is being generated&lt;/li&gt;
  &lt;li&gt;p - preserve permissions&lt;/li&gt;
  &lt;li&gt;f - lets us specify a filename to write the archive to&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-zcvpf&lt;/span&gt; backup.tar.gz ~/mysite_backup&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;copying-the-backup-file-to-the-new-server&quot;&gt;Copying the backup file to the new server&lt;/h3&gt;
&lt;p&gt;You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scp&lt;/code&gt; to securely copy the backup file to the new server. This may take a while if your Wordpress installation is particularly large.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;scp &lt;span class=&quot;nt&quot;&gt;-v&lt;/span&gt; ~/mysite_backup/backup.tar.gz root@new.server.ip.address:/path/to/copy/file/on/new/server&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then delete the backup files from the old server.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rf&lt;/span&gt; ~/mysite_backup&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;restoring-the-backup-in-the-new-location&quot;&gt;Restoring the backup in the new location&lt;/h3&gt;
&lt;p&gt;Unpack the backup file. The options here are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;x - extracts an archive&lt;/li&gt;
  &lt;li&gt;v - verbose, tells us what’s going on while the archive is being generated&lt;/li&gt;
  &lt;li&gt;z - use gzip compression&lt;/li&gt;
  &lt;li&gt;f - lets us specify a filename to read the archive from&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /path/to/backup/file/on/new/server
&lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-xvzf&lt;/span&gt; backup.tar.gz&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Put the Wordpress files wherever they need to go (determined by your webserver config).&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;r - recursive&lt;/li&gt;
  &lt;li&gt;p - preserve permissions&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rp&lt;/span&gt; backup/mysite_backup/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; /path/to/wordpress/installation/&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Create the database from the backup sql file, replacing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hostname&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;username&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;database_name&lt;/code&gt; with the correct info, and entering the password when prompted&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;mysql &lt;span class=&quot;nt&quot;&gt;-h&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;hostname&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; username &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; database_name &amp;lt; backup.sql&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then clear away the backup files&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rf&lt;/span&gt; backup/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then set the owner &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chown&lt;/code&gt;, group &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chgrp&lt;/code&gt; and permissions &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chmod&lt;/code&gt; in accordance with your setup. The following is an example, and not a recommendation. You need to choose something based on your installation.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;chown&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; root path/to/wordpress/installation
&lt;span class=&quot;nb&quot;&gt;chgrp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; www-data path/to/wordpress/installation
&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; 644 path/to/wordpress/installation&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Make sure you restart your webserver. In the case of Apache:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;service apache2 restart&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h3 id=&quot;testing-things-out&quot;&gt;Testing things out&lt;/h3&gt;
&lt;p&gt;If you’re feeling cavalier and you’ve already configured your webserver to point to your new files, go ahead and change the DNS settings now.
But if you’re a little more cautious, you can use a spare domain or your server’s ip address and configure your webserver to direct traffic to the new Wordpress site.
One problem with this is that Wordpress redirects traffic to its own domain, so you need to fool it into thinking the ip address or spare domain is its correct address.
This is an option normally changed via the admin panel, but due to the redirect, attempting to change this value via the admin panel will update the old Wordpress installation
even if you type in the address of the new installation. To get around this, you can temporarily hard-code the value. Find the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wp-admin/wp-config.php&lt;/code&gt; file and add he following lines near the beginning:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;nb&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'WP_HOME'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'http://your_test_url'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'WP_SITEURL'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'http://your_test_url'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Test away. If all is good, remove the two lines from your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wp-config.php&lt;/code&gt; file and update your DNS records.&lt;/p&gt;
</description>
        <pubDate>Sat, 11 May 2019 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/migrating-a-wordpress-site-to-a-new-server/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/migrating-a-wordpress-site-to-a-new-server/</guid>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>Living off the fat of the land</title>
        <description>&lt;p&gt;I was talking to someone recently who told me that if we divided up the land between each living human, we would get a surprisingly small area each - of the order of two football fields. I was stunned. But not wanting to take someone’s word for it, I decided to check it out for myself.&lt;/p&gt;

&lt;p&gt;The Earth is an oblate spheroid, which means it is a slightly squished ball. It is slightly fatter at its equator (6,378 km) than at its poles (6,357 km) due to its rotation. But, taking its mean radius of 6,371 km and assuming it is spherical, we get a surface area of 5.1 x 10&lt;sup&gt;8&lt;/sup&gt; km&lt;sup&gt;2&lt;/sup&gt; using A=4πr&lt;sup&gt;2&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;So it seems that the Earth is a big place. But remember that 71% of the Earth’s surface is water. So only 29% is land. So there is 1.479 x 10&lt;sup&gt;8&lt;/sup&gt; km&lt;sup&gt;2&lt;/sup&gt; of land.&lt;/p&gt;

&lt;p&gt;Some of this land is barren. Approximately 1/3rd of land is desert. This includes sandy deserts such as the Sahara, Gobi and Atacama as well as icy deserts such as Antarctica. So now we are down to 4.93 x 10 &lt;sup&gt;7&lt;/sup&gt; km&lt;sup&gt;2&lt;/sup&gt;.&lt;/p&gt;

&lt;p&gt;How many people are there on Earth? At the time of writing, the world population is estimated to be 7.6 billion and rising fast. It took humans over 200,000 years to hit 1 billion people and only another 200 years to hit 7 billion.&lt;/p&gt;

&lt;p&gt;If we were to divide the useable land into plots of equal size and give a slice to each person, we would each get just under 6.5 km&lt;sup&gt;2&lt;/sup&gt;. That about 2.5 x 2.5 km (about 1.5 x 1.5 miles).&lt;/p&gt;

&lt;p&gt;To turn that into football pitches (assuming Association rules), that’s about 650 pitches give or take (turns out Association rules allow a range of pitch sizes).&lt;/p&gt;

&lt;p&gt;So each person has a bit more that just two football fields. But still, this is a remarkably small area that has to sustain all life (plants and animals) that goes to feeding you. But it is not just yours alone. You will have to share it with one or two other apex predators - maybe a bear, lion, a wolf and an eagle. There will be several prey animals - a small herd of gazelle, a couple of buffalo and a smattering of rodents. There will be insects and other invertebrates.&lt;/p&gt;

&lt;p&gt;Some of the land will be forest, some will be bog, some open plains. Not all will be suitable for all animals, resulting in each animal taking a small area based on its niche capabilities. You will have to fit in around this.&lt;/p&gt;

&lt;p&gt;Everything you do must take into account the other animals living in the same 2.5 x 2.5 km square. If we were this aware about nature and the influence that our technology and population has on it, then we would take better care. We would be sensitive to the pesticides, emissions, human waste, energy consumption, deforestation and every other influence that our lives have on the plants and animals sharing the tiny plot of land with us.&lt;/p&gt;

&lt;p&gt;So whatever you do in life, think about your small plot of land and the life you share it with.&lt;/p&gt;

</description>
        <pubDate>Fri, 19 Apr 2019 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/living-off-the-fat-of-the-land/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/living-off-the-fat-of-the-land/</guid>
        
        
        <category>Nature</category>
        
      </item>
    
      <item>
        <title>Auto-Enabling NumLock on the Linux Mint Login Screen</title>
        <description>&lt;p&gt;I use the number keys a lot. Not the line of numbers at the top of the keyboard, but the grid of numbers to the right. In order to use these numbers, you need to have NumLock set to on. This is just a simple keyboard press to activate it. However, if ever it is not already activated and I press the numbers, then the numbers act like arrow keys. It has always baffled me why these keys double as arrows, as there are arrow keys right next to them! But that’s another complaint for another day. I like NumLock turned on and I make mistakes when it is off. So I would like it turned on by default.&lt;/p&gt;

&lt;p&gt;Unfortunately, NumLock is off by default on Linux Mint. The is a menu option to turn it on, but as can be seen here, the menu option is deactivated by default.&lt;/p&gt;

&lt;p&gt;System Settings -&amp;gt; Login indow -&amp;gt; Settings -&amp;gt; Activate Numlock&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/numlock2.png&quot; data-lightbox=&quot;numlock&quot; data-title=&quot;The numlock option is deactivated&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/numlock2.png&quot; title=&quot;The numlock option is deactivated&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To enable the menu option, we need to install &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;numlockx&lt;/code&gt; first. Why there would be a menu option that uses a feature not installed by default is my second complaint, which again, I will leave for another day :)&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;numlockx&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then you should see that the menu item is enabled, so activate NumLock on startup.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/numlock3.png&quot; data-lightbox=&quot;numlock&quot; data-title=&quot;The numlock option is enabled after installing numlockx&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/numlock3.png&quot; title=&quot;The numlock option is enabled after installing numlockx&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/numlock4.png&quot; data-lightbox=&quot;numlock&quot; data-title=&quot;The numlock option is now enabled by default&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/numlock4.png&quot; title=&quot;The numlock option is now enabled by default&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then sit back and relax as you can confidently type numbers without the fear that you will accidentally move the cursor by mistake…&lt;/p&gt;
</description>
        <pubDate>Tue, 09 Oct 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/enable-numlock-linux-mint-login/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/enable-numlock-linux-mint-login/</guid>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>Darlington Pair Transistors Wedding Gift</title>
        <description>&lt;p&gt;I am terrible with presents. Every now and again I have an idea of what to get somebody for Christmas or for their birthday and inevitably I forget before the event. But when it came to the wedding of one of my friends, I had an very definite idea of what to make that would not leave my mind. His surname is Darlington. I reasoned that once he was married, he would form a Darlington Pair. In electronics, a &lt;a href=&quot;https://en.wikipedia.org/wiki/Darlington_pair&quot; target=&quot;_blank&quot;&gt;Darlington Pair&lt;/a&gt; is made when one transistor feeds into another, creating a super sensitive switch that can be activated by touch. My wedding present would be a device which, when touched by two people, and those two people touch each other, an LED lights up. Of course I had to package it as a wedding gift. I couldn’t just present them with a hastily soldered circuit board. But this is where my 3D printer comes in handy :)&lt;/p&gt;

&lt;p&gt;I used FreeCAD to design the enclosure.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/darlington_pair1.png&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;FreeCAD&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair1.png&quot; title=&quot;FreeCAD&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And Fritzing to design the circuit layout prior to soldering. Even on a small circuit such as this one, I like to play around with the layout in Fritzing to make sure that I get the components in the right place and cut the tracks correctly.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/darlington_pair2.png&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;Schematic&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair2.png&quot; title=&quot;Schematic&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/darlington_pair3.png&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;Stripboard Layout&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair3.png&quot; title=&quot;Stripboard Layout&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then printed the enclosure using my 3D printer. This took a couple of attempts and test prints to get right. I needed to test out how much tolerance to add in to the lip so that the lid could fit snugly onto the base. I also needed to test how large the diameter should be for the bolt hole so that the bolt can grip on without cracking the plastic. I did these test prints on small sections of the enclosure, rather than printing the whole thing and wasting time, plastic and money. To test the bolt hole diameter, I printed a set of cylinders mounted to a small base each with a slightly different tolerance (2.9 mm, 3.0 mm and 3.1 mm) to fit a 3 mm bolt. It turns out the 3.0 mm hole was perfect when printed with my Ultimaker. I did a similar small-scale test to ensure the lid lip was correct.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/darlington_pair4.jpg&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;3D printing the enclosure&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair4.jpg&quot; title=&quot;3D printing the enclosure&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/darlington_pair5.jpg&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;3D printing the enclosure&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair5.jpg&quot; title=&quot;3D printing the enclosure&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then assembled all of the components together&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/darlington_pair6.jpg&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;Inserting the electronics&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair6.jpg&quot; title=&quot;Inserting the electronics&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/darlington_pair7.jpg&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;Adding the battery&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair7.jpg&quot; title=&quot;Adding the battery&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The completed device was inscribed with a message to the happy couple. I decided to have the transistors poking through the top of the enclosure to symbolise their union (the two transistors working together). The two screws exposed on the surface, when touched together, will cause the LED to light up. If one person touches the left screw, and another touches the right screw, then the LED will only light up when the two people touch each other.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/darlington_pair8.jpg&quot; data-lightbox=&quot;darlington_pair&quot; data-title=&quot;Testing the finished product&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/darlington_pair8.jpg&quot; title=&quot;Testing the finished product&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

</description>
        <pubDate>Tue, 02 Oct 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/darlington-pair-transistors-wedding-gift/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/darlington-pair-transistors-wedding-gift/</guid>
        
        
        <category>Electronics</category>
        
      </item>
    
      <item>
        <title>Mounting Linux Mint Home Directory on Different Drive</title>
        <description>&lt;p&gt;I recently mounted my Linux Mint home directory on a different internal hard drive to the operating system. Why did I do this? I wanted the operating system to run on a solid state drive to allow my computer to boot and run as quickly as possible, without limiting the amount of space I have to store files (as SSDs are expensive and typically measured in GB not TB).&lt;/p&gt;

&lt;p&gt;I didn’t want to have to go to a special &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt&lt;/code&gt; or other directory to access my files – I wanted it to be as seamless as possible. So moving everything under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home&lt;/code&gt; to a separate drive was desirable.&lt;/p&gt;

&lt;p&gt;The end result is that I have a 240GB Kingston HyperX Solid State Drive running Linux Mint 18.3 ‘Sylvia’ Cinnamon. All of my personal files (Desktop, Documents, Photos, Music etc.) reside on a 2TB Seagate Firecuda Hybrid Drive. (I chose a Hybrid as it’s faster than a HDD but cheaper, higher capacity and more reliable than a SSD).&lt;/p&gt;

&lt;p&gt;This gives me the following benefits:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Best compromise between enough storage space and fast responsive operating system&lt;/li&gt;
  &lt;li&gt;If I need to upgrade the operating system, I don’t need to worry about my personal files being wiped&lt;/li&gt;
  &lt;li&gt;I can easily upgrade the size of my personal storage space without touching the operating system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I performed this on Linux Mint, although this should be equally valid for Ubuntu without modification. If using another Linux distro, then you may need to tweak some of the steps.&lt;/p&gt;

&lt;p&gt;The steps below should be fairly failsafe. We are not deleting or wiping anything – merely copying and relocating. However, it is possible to mess up the mounting so that you can’t log in. I have included some steps to take should anything go wrong.&lt;/p&gt;

&lt;h3 id=&quot;step-1&quot;&gt;Step 1&lt;/h3&gt;
&lt;p&gt;Back everything up. Just in case. If you have just performed a fresh installation, then you obviously don’t need to worry about this.&lt;/p&gt;

&lt;h3 id=&quot;step-2&quot;&gt;Step 2&lt;/h3&gt;
&lt;p&gt;If it isn’t already connected, physically install your second hard drive.&lt;/p&gt;

&lt;h3 id=&quot;step-3&quot;&gt;Step 3&lt;/h3&gt;
&lt;p&gt;Format your new drive. I used the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gparted&lt;/code&gt; program to create a ‘gpt’ partition table (Select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Device&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Create Partition Table&lt;/code&gt;) and format it for an ‘ext4’ filesystem (select &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Partition&lt;/code&gt; -&amp;gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;New&lt;/code&gt;). Just make sure that you select the correct drive in the top-right of the screen (you can use the volume size as a guide).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;: If you select the wrong drive then you’ll end up wiping your data and operating system (but you did take a backup, right?)&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/home_partition1.png&quot; data-lightbox=&quot;home_partition&quot; data-title=&quot;gparted&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/home_partition1.png&quot; title=&quot;gparted&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;step-4&quot;&gt;Step 4&lt;/h3&gt;
&lt;p&gt;Create a temporary directory for your new home drive:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo mkdir&lt;/span&gt; /mnt/new_home&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then mount your drive. You can do this as a one-off via a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo mount&lt;/code&gt;… command, or edit the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/fstab&lt;/code&gt; file. I prefer the latter, albeit via the gnome-disk-utility program (aka ‘Disks’ in Linux Mint). Open Disks, select your new drive and click the settings (cogs) icon:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/home_partition2.png&quot; data-lightbox=&quot;home_partition&quot; data-title=&quot;gparted&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/home_partition2.png&quot; title=&quot;gparted&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then select Edit Mount Options. Set the options as below:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/home_partition3.png&quot; data-lightbox=&quot;home_partition&quot; data-title=&quot;gparted&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/home_partition3.png&quot; title=&quot;gparted&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select OK then hit the Play button to mount the drive&lt;/p&gt;

&lt;h3 id=&quot;step-5&quot;&gt;Step 5&lt;/h3&gt;
&lt;p&gt;Copy all of your files to the new drive. If successful, then your /mnt/new_home directory will look identical to your /home directory. I moved each user individually, so that I could check everything was progressing ok without waiting until the end of the copy (which can take a long time if you have a lot of files).&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-axv&lt;/span&gt; /home/user_name /mnt/new_home &lt;span class=&quot;c&quot;&gt;#replacing user_name with the name of the user you want to copy.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You could also move all users in one go via:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cp&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-axv&lt;/span&gt; /home/&lt;span class=&quot;k&quot;&gt;*&lt;/span&gt; /mnt/new_home&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The flags used here are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;-a&lt;/strong&gt;: Archive mode, recursively copies, preserving permissions etc. Without this, your copied files will all belong to the root user.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;-x&lt;/strong&gt;: Ensures that the copy does not follow symbolic links to others hard drives. May not be needed in your case, but not a bad shout to include it anyway&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;-v&lt;/strong&gt;: Verbose, displaying what is being copied. I like to see progress so that I know the copy is still working&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the user permissions will be applied at the end of the copy, so don’t worry if you see all of your files initially belonging to root.&lt;/p&gt;

&lt;h3 id=&quot;step-6&quot;&gt;Step 6&lt;/h3&gt;
&lt;p&gt;Once you are happy that everything has copied successfully, we will swap out the home directory with the new one.
First we’ll rename the home directory:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo mv&lt;/span&gt; /home /home_old&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Then we will create a folder for the new drive to mount to:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo mkdir&lt;/span&gt; /home&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And finally mount the drive. Go back to the Disks program and change the mount point from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/mnt/new_home&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home&lt;/code&gt;. Then mount it (hit the play button). If happy that all looks ok, restart the computer and hopefully everything just works!&lt;/p&gt;

&lt;h3 id=&quot;step-7&quot;&gt;Step 7&lt;/h3&gt;
&lt;p&gt;Check your files all look ok. Do this for each user. If happy, you can remove the old home directory:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-rf&lt;/span&gt; /home_old&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If all fails
If something has gone wrong, then don’t panic. You still have three copies of your data:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Your external backup (you did back everything up, didn’t you?)&lt;/li&gt;
  &lt;li&gt;Your original home direcory (that we renamed to /home_old&lt;/li&gt;
  &lt;li&gt;Your copy of /home that we’re trying to mount.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the worst comes to the worst, then wipe your computer and regenerate your files from your backup. However, it shouldn’t come to that.&lt;/p&gt;

&lt;p&gt;If you can log in, then check that you have set up the mounting correctly. Retrace the steps above to make sure that you haven’t missed anything.&lt;/p&gt;

&lt;p&gt;If you can’t log in, then hold down &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl+Alt+F1&lt;/code&gt; to open a terminal and log in with your username and password. Edit the File System Table file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/fstab&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This file will look something like this:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-apache&quot; data-lang=&quot;apache&quot;&gt;&lt;span class=&quot;c&quot;&gt;# /etc/fstab: static file system information.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Use 'blkid' to print the universally unique identifier for a&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# device; this may be used with UUID= as a more robust way to name devices&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# that works even if disks are added and removed. See fstab(5).&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# &amp;lt;file system&amp;gt; &amp;lt;mount point&amp;gt;   &amp;lt;type&amp;gt;  &amp;lt;options&amp;gt;       &amp;lt;dump&amp;gt;  &amp;lt;pass&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# / was on /dev/sda2 during installation&lt;/span&gt;
UUID=4bcb0546-271c-4366-b294-9aa603dd4b72 /               ext4    errors=remount-ro 0       1
&lt;span class=&quot;c&quot;&gt;# /boot/efi was on /dev/sda1 during installation&lt;/span&gt;
UUID=4947-4AB8  /boot/efi       vfat    umask=0077      0       1
&lt;span class=&quot;c&quot;&gt;# swap was on /dev/sda3 during installation&lt;/span&gt;
UUID=884d6349-f03f-46a4-854e-d5af5d961f2c &lt;span class=&quot;ss&quot;&gt;none&lt;/span&gt;            swap    sw              0       0
UUID=88e85a4f-2421-4399-933b-930ea08c39e3 /home ext4 defaults 0 0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;This shows the hard drives (identified by their UUID) followed by their mount points. Check that they are set correctly. If you see a problem, then edit the file, save and restart. You can restart with sudo reboot.&lt;/p&gt;

&lt;p&gt;If you can’t figure out what has gone wrong, then you can always put your old home directory back where it was. Comment out the line that mounts your new drive by preceding it with a hash &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; and saving (your new drive will be the one mounting to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home&lt;/code&gt;. Then unmount the drive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo umount /home&lt;/code&gt; (or reboot if this doesn’t work, such as if the device is busy). You can then remove the home directory mount folder sudo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rmdir /home&lt;/code&gt; and move your old home directory back to it’s original location &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo mv /home_old /home&lt;/code&gt; then restart.&lt;/p&gt;

&lt;p&gt;Hopefully it won’t come to that and everything will just work, but it’s always good to have a Plan B (and C and D…)&lt;/p&gt;
</description>
        <pubDate>Sat, 05 May 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/mounting-linux-mint-home-directory-on-different-drive/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/mounting-linux-mint-home-directory-on-different-drive/</guid>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>Removing a Soldering Iron Tip Tinner Tin Lid</title>
        <description>&lt;p&gt;This might seem like a silly post, but I managed to do the impossible – removing the lid from a soldering iron tip tinner tin (what a mouthful). This is the first time I have ever bought the stuff, so I never knew how hard it would be to get inside. I’ve opened similar tins before, such as shoe polish, but this little guy is on a whole new plane of difficulty.&lt;/p&gt;

&lt;p&gt;After going at it with everything from fingernails, screwdrivers, pliers, g-clamps, hot water, cold water and rubber gloves and still failing, I took to the internet to see if I was the only one having this difficulty.&lt;/p&gt;

&lt;p&gt;The reviews for this product are full of people pleading for help in opening the tin. It seems some people even resorted to drilling a hole in the lid to equalise the pressure so you’re not working against the atmosphere.&lt;/p&gt;

&lt;p&gt;Some of the reviews contained success stories. “Just remove muscle from the equation. As soon as I stopped forcing it off and tried gently, it came right off” was one response, although the only reason I’m trying so hard is because “gently” was just not good enough!&lt;/p&gt;

&lt;p&gt;Then I noticed a little-used tool in my spudger set. A simple suction cup. Could this allow me to lift the lid without squeezing the sides? I gave it a go. The first couple of times the paper on the lid prevented a good seal, but after a further attempt the lid popped right off!&lt;/p&gt;

&lt;p&gt;Reading the reviews of this product, I think that success will come on a case-by-case basis, with different solutions working for different people and not all solutions working for everyone. So I just wanted to throw another potential solution out there for you to try.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/tiptinner2.jpg&quot; data-lightbox=&quot;tiptinner&quot; data-title=&quot;Trying a spudger - no joy&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/tiptinner2.jpg&quot; title=&quot;Trying a spudger - no joy&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/tiptinner3.jpg&quot; data-lightbox=&quot;tiptinner&quot; data-title=&quot;Looking at the other tools in my spudger set&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/tiptinner3.jpg&quot; title=&quot;Looking at the other tools in my spudger set&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/tiptinner4.jpg&quot; data-lightbox=&quot;tiptinner&quot; data-title=&quot;Trying the suction cup&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/tiptinner4.jpg&quot; title=&quot;Trying the suction cup&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/tiptinner5.jpg&quot; data-lightbox=&quot;tiptinner&quot; data-title=&quot;Success!&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/tiptinner5.jpg&quot; title=&quot;Success!&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 18 Feb 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/removing-a-soldering-iron-tip-tinner-tin-lid/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/removing-a-soldering-iron-tip-tinner-tin-lid/</guid>
        
        
        <category>In the shed</category>
        
      </item>
    
      <item>
        <title>WordPress Permalinks Not Working (404 Not Found)</title>
        <description>&lt;p&gt;I recently migrated this WordPress website between servers. It was fairly straightforward: copy the database, copy the files, transfer the domain etc. However, one (big) issue that I encountered was that with the exception of the homepage and the admin dashboard, every page resulted in a 404 Not Found. I checked my Permalink settings in the dashboard – this was set as it should have been (custom structure set to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;posts/%postname%&lt;/code&gt;). This was indeed the format pages were trying to access, so it should have been fine.&lt;/p&gt;

&lt;p&gt;As a quick test, I turned off my custom permalink and set it to Plain and bing – everything now worked, albeit with a permalink structure that I was not happy with (both because it looked less readable and I didn’t want to break my links – I’ve managed to keep them since I migrated to WordPress from Grav a few years ago). So I set my Custom Structure back on and went hunting for the cause of the issue.&lt;/p&gt;

&lt;p&gt;Changing the permalink structure amends the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.htaccess&lt;/code&gt; file in the root wordpress directory. If the permissions for this file are set incorrectly then WordPress can’t write to it. I checked the permissions and there was no issue. The contents of the file contained the correct Apache Directives set by WordPress.&lt;/p&gt;

&lt;p&gt;It was as if Apache was ignoring my &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.htaccess&lt;/code&gt; file. hmm… let’s have a quick google…&lt;/p&gt;

&lt;p&gt;Seems as though Apache is configured by default to prevent its settings from being overridden by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.htaccess&lt;/code&gt; file. So I went into my site’s configuration file and added:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-apache&quot; data-lang=&quot;apache&quot;&gt;&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Directory&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /var/www/path/to/website/ &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;
&lt;/span&gt;    &lt;span class=&quot;nc&quot;&gt;AllowOverride&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;All&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;Directory&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;I then restarted Apache and checked my website – everything worked 🙂&lt;/p&gt;

</description>
        <pubDate>Fri, 09 Feb 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/wordpress-permalinks-not-working-404-not-found/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/wordpress-permalinks-not-working-404-not-found/</guid>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>How to Straighten a Length of Wire</title>
        <description>&lt;p&gt;I had a need to straighten some pieces of wire that came from a coil. They started out all bent and twisted. Even after some manual manipulation, trying hard to get out every kink using a pair of pliers, it was still wonky – nowhere near straight enough. I then tried putting it in a clamp and pulling, but there was no way I could pull hard enough to straighten it.&lt;/p&gt;

&lt;p&gt;In the end, I managed to straighten this wire using a drill. I fixed one end to a workbench using a clamp (although I also tested holding using a pair of pliers – it worked just as well). The other end I attached to the drill. The smallest bit that fits into my drill is around 2.5 mm, whereas the wire is 0.8 mm. However, I managed to grip the wire into one of the gaps between the three parts of the drill’s end effector. Pulling the wire taught, I then gave the drill around three rotations before carefully releasing. This has the effect of stretching the wire without me having to pull it hard.&lt;/p&gt;

&lt;p&gt;Apart from the ends that were under the clamp and in the drill (which can be cut off), the wire came out lovely and straight. I’ve tried this with both copper and aluminium wire and both worked beautifully.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2018/straight_wire1.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Bent copper wire&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire1.jpg&quot; title=&quot;Bent copper wire&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire2.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Wire after manual straightening (using pliers)&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire2.jpg&quot; title=&quot;Wire after manual straightening (using pliers)&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire3.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Wire held by a clamp&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire3.jpg&quot; title=&quot;Wire held by a clamp&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire4.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Wire held by drill&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire4.jpg&quot; title=&quot;Wire held by drill&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire5.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Straightening wire using a drill&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire5.jpg&quot; title=&quot;Straightening wire using a drill&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire6.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Single straight copper wire&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire6.jpg&quot; title=&quot;Single straight copper wire&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire7.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Straight copper wire&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire7.jpg&quot; title=&quot;Straight copper wire&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire8.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Multiple straight copper wire&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire8.jpg&quot; title=&quot;Multiple straight copper wire&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2018/straight_wire9.jpg&quot; data-lightbox=&quot;straight_wire&quot; data-title=&quot;Straight aluminium wire&quot;&gt;
	&lt;img src=&quot;/assets/posts/2018/straight_wire9.jpg&quot; title=&quot;Straight aluminium wire&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sat, 06 Jan 2018 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/how-to-straighten-a-length-of-wire/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/how-to-straighten-a-length-of-wire/</guid>
        
        
        <category>In the shed</category>
        
      </item>
    
      <item>
        <title>Configuring a Webserver Running Apache and Nginx</title>
        <description>&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;This post serves as a reminder to myself what the basic steps are to configure my webserver. Hopefully it will help others. There are some additional steps I took following those below, such as to configure Python, but that is outside the scope of this post.&lt;/p&gt;

&lt;p&gt;I was prompted to put this together because I wanted to understand how everything bolts together. I was using a server running Plesk which configured everything for me, but whenever I wanted to do anything “not usual” such as configuring Python via WSGI, I found myself editing configuration files that stated something like “this file was auto-generated and will be overwritten”. As such, a lot of configuration was done through mouse-clicks on the Plesk web interface – great for beginners as it masks you from the details. I found myself running a webserver without knowing what was going on in the background. Not so great if things start to go wrong, or if you want to do something that is not available via Plesk. I am also a big believer in “infrastructure as code”. If I can automate processes then I will. Configuration via mouse-clicks is not easy to sustain or transfer to another webserver.&lt;/p&gt;

&lt;p&gt;The steps below are the basic steps required to configure a webserver with multiple virtual hosts, running Nginx to handle requests and serve static content, and Apache to serve dynamic content.&lt;/p&gt;

&lt;h2 id=&quot;assumptions&quot;&gt;Assumptions&lt;/h2&gt;
&lt;p&gt;You have Ubuntu 16.04 installed
You aren’t afraid of the command line, ssh etc…
You have backed everything up – I will not take responsibility for lost files yadda yadda…..
You have full root access to your server
You know your server’s public IP address (denoted in this tutorial by x.x.x.x)&lt;/p&gt;

&lt;h2 id=&quot;general-overview&quot;&gt;General Overview&lt;/h2&gt;
&lt;p&gt;Apache is known to be resource-intensive, but great at generating dynamic files. Nginx is known to be nimble and great for static content, but not great for dynamic content. By combining the two, you can have the best of both worlds.&lt;/p&gt;

&lt;p&gt;I’m oversimplifying, but the general path of a static request will look like this:&lt;/p&gt;

&lt;p&gt;Client requests static page &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo.html&lt;/code&gt; from the server on Port 80
Nginx grabs the file from disk and serves it to the client
For dynamic content, it looks like this:&lt;/p&gt;

&lt;p&gt;Client requests dynamic page &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo.php&lt;/code&gt; from the server on Port 80
Nginx connects to Apache on Port 8079 (for example)
Apache constructs the static content, returns it to Nginx and goes back to sleep
Nginx serves the content back to the client
The benefits are:&lt;/p&gt;

&lt;p&gt;Apache, which is resource hungry, only has to deal with dynamic content
Apache does not have to deal with clients on slow connections and can release resources as soon as it has served the content to Nginx
Nginx deals with client on slow connections, freeing up Apache to deal with the things it is good at
If the webserver is busy and Apache has no free threads to deal with requests, Nginx can still serve a useful response to the client, such as a message to come back later. This is far better than the server simply hanging&lt;/p&gt;

&lt;h2 id=&quot;lets-get-started&quot;&gt;Let’s get started&lt;/h2&gt;
&lt;h4 id=&quot;log-in-as-root-user-through-ssh&quot;&gt;Log in as root user through SSH&lt;/h4&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;ssh root@x.x.x.x&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;create-a-new-non-root-user-with-sudo-priviledges&quot;&gt;Create a new non-root user with sudo priviledges:&lt;/h4&gt;
&lt;p&gt;We don’t want to use the root account if we can help it. Let’s set up a user account with sudo privileges so we can do what we like, but with a degree of safety. Enter the following commands, but change username to the name of the user that you want:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;adduser username
usermod &lt;span class=&quot;nt&quot;&gt;-aG&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;username&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;switch-to-your-newly-created-account-and-test-sudo-works&quot;&gt;Switch to your newly-created account and test sudo works&lt;/h4&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;su username
&lt;span class=&quot;nb&quot;&gt;ls&lt;/span&gt; /root         &lt;span class=&quot;c&quot;&gt;#(should get permission denied error)&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo ls&lt;/span&gt; /root    &lt;span class=&quot;c&quot;&gt;#(should give a list of directories)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;ensure-repositories-and-packages-are-up-to-date&quot;&gt;Ensure repositories and packages are up to date&lt;/h4&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get update
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get upgrade&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;install-some-useful-tools-if-not-already-installed&quot;&gt;Install some useful tools, if not already installed&lt;/h4&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nano&lt;/code&gt; is the text editor we will use. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man-db&lt;/code&gt; allows you to view the manual pages of commands, for example by typing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;man ls&lt;/code&gt;&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;man-db nano&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;install-apache-if-not-already-installed&quot;&gt;Install Apache, if not already installed&lt;/h4&gt;
&lt;p&gt;This was already installed on my webserver, but if not you can install it with:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;apache2&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;bind-apache-to-port-8079-instead-of-default-80&quot;&gt;Bind apache to port 8079 instead of default 80&lt;/h4&gt;
&lt;p&gt;Apache will be running on Port 80 by default. Instead, we want Nginx to be exposed on Port 80. Let’s change Apache to be on Port 8079 by editing one of Apache’s configuration files:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/apache2/ports.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Change the line that says &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Listen 80&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Listen 8079&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we’ll need to change it in the Virtual Host file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/apache2/sites-enabled/000-default.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Change &amp;lt;VirtualHost *: 80&amp;gt; to &amp;lt;VirtualHost *: 8079&amp;gt;&lt;/p&gt;

&lt;p&gt;Tell Apache to reload the config file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If you like, you can temporarily add port 8079 to the firewall whitelist to test this port loads the default Apache page. If all is ok, remove it from firewall as we will only ever talk to Apache internally via Nginx. My webhosting company gives me access to do this from a user-interface. You can then access the page via a specific port by browsing to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x.x.x.x:8079&lt;/code&gt;&lt;/p&gt;

&lt;h4 id=&quot;set-up-nginx&quot;&gt;Set up Nginx&lt;/h4&gt;

&lt;p&gt;Install Nginx:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;nginx&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You can start the server with:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/nginx start&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Check that Nginx is running ok by browsing to your IP address. Since Nginx looks for website files in the same directory as Apache, it may pick up Apache’s index.html and look like Apache is serving webpages, but remember that Apache is running from a different port so this is not the case. If you want to be absolutely sure, you can stop Apache and test that web pages are still being served by typing in:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/apache2 stop&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We are first going to configure Nginx to handle all requests to your server, whether directly to your IP address, or via domain names, in the same manner. We will come back to this later to change its behaviour so that if a user browses to your site via a domain name, we will serve up files specific to that domain. For now though, let’s just get the basics working.&lt;/p&gt;

&lt;p&gt;There are two important directories located in /etc/nginx:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;sites-available&lt;/li&gt;
  &lt;li&gt;sites-enabled&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sites-enabled&lt;/code&gt; contains configurations for each of the websites hosted on your server. But rather than keep the configuration files in directly in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-enabled&lt;/code&gt;, it is good practice to keep them in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-available&lt;/code&gt; and create a symbolic link (shortcut) in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-enabled&lt;/code&gt;. This provides a place to keep a configuration file for each of your sites and allows you to enable/disable each site by create/deleting the symbolic link without touching the original configuration file.&lt;/p&gt;

&lt;p&gt;There is a default configuration file in sites-enabled and sites-available. We will delete these, and create our own:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo rm&lt;/span&gt; /etc/nginx/sites-available/default
&lt;span class=&quot;nb&quot;&gt;sudo rm&lt;/span&gt; /etc/nginx/sites-enabled/default&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We can then create our own file for all requests. I will call this file ip because it will eventually become the config file for all accesses to your server via the IP address (or where the host in the HTTP header can not be resolved). As said above, for now this will handle all requests via all domains that point to your server.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/nginx/sites-available/ip&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And add the content:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-nginx&quot; data-lang=&quot;nginx&quot;&gt;&lt;span class=&quot;k&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;listen&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;default_server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
    &lt;span class=&quot;kn&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;/var/www/html/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;index.php&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;index.html&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;index.htm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
    &lt;span class=&quot;kn&quot;&gt;server_name&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
    &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;try_files&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$uri&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$uri&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;/index.php&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
    &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;\.php$&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;proxy_set_header&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;X-Real-IP&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$remote_addr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;proxy_set_header&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;X-Forwarded-For&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$remote_addr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;proxy_set_header&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;Host&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;proxy_pass&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;http://127.0.0.1:8079&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
    &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;~&lt;/span&gt; &lt;span class=&quot;sr&quot;&gt;/\.ht&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kn&quot;&gt;deny&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The important parts of this configuration file are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;listen 80 default_server;&lt;/code&gt; tells Nginx to listen on Port 80 and use this config file for any hosts that can not otherwise be resolved&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root /var/www/html;&lt;/code&gt; Tells Nginx where to look for files&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;proxy_pass http://127.0.0.1:8079;&lt;/code&gt; Tells Nginx to pass any requests for PHP files (dynamic content) through to Apache on Port 8079&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We now need to create a symbolic link in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-enabled&lt;/code&gt; and reload Nginx to enable the config file to be picked up:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /etc/nginx/sites-available/ip /etc/nginx/sites-enabled/ip
&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/nginx reload&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;lets-re-cap&quot;&gt;Let’s Re-Cap&lt;/h4&gt;
&lt;p&gt;By now, we have performed the following:&lt;/p&gt;

&lt;p&gt;Apache is running on Port 8079.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Nginx is running on Port 80&lt;/li&gt;
  &lt;li&gt;All static content is served by Nginx&lt;/li&gt;
  &lt;li&gt;All dynamic content in PHP files is served by Apache, via Nginx&lt;/li&gt;
  &lt;li&gt;Port 80 should be open and Port 8079 should be closed, forcing all requests through Nginx&lt;/li&gt;
  &lt;li&gt;All incoming traffic to your webserver should be pointed at files located in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/var/www/html/&lt;/code&gt;, whether that traffic is through a domain name or your server’s IP address
We will now look at separating out the traffic from different domain names, allowing you to host several sites on the same server. We will have to perform the following:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
  &lt;li&gt;Create the relevant directories from which content will be served&lt;/li&gt;
  &lt;li&gt;Modify Apache configuration files, so that Apache knows where to go for dynamic content for each domain&lt;/li&gt;
  &lt;li&gt;Modify Nginx configuration files, so that Nginx knows where to go for static content for each domain&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;creating-webspace-directories&quot;&gt;Creating Webspace Directories&lt;/h4&gt;
&lt;p&gt;We will now create three directories, one for traffic directly to the IP and one for each of two example domain names. Each webspace directory will contain a public folder where files that should be served can be stored. This will then give you a place to store other files in the future that you do not want to be served, such as configuration or password files.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /var/www
&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; ip/public
&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; example1.com/public
&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; example2.com/public
&lt;span class=&quot;nb&quot;&gt;sudo chmod&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; 755 /var/www&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Change the permissions of these directories – we don’t want to use sudo every time we edit a file here. The following commands will change the owner to the currently logged in user.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo chown&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt; /var/www/ip
&lt;span class=&quot;nb&quot;&gt;sudo chown&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt; /var/www/example1.com
&lt;span class=&quot;nb&quot;&gt;sudo chown&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-R&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt;:&lt;span class=&quot;nv&quot;&gt;$USER&lt;/span&gt; /var/www/example2.com&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We can now also remove the html directory currently used by Apache/Nginx as we will no longer be needing it:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; /var/www/html&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Let’s tell Nginx that we have moved the default directory:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/nginx/sites-available/ip&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;and change the line root /var/www/html/; to root /var/www/ip/public/;&lt;/p&gt;

&lt;p&gt;Tell Nginx to reload the file:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/nginx reload&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now let’s create an example static html file, and an example dynamic php file. This will allow us to test that each site works with both static and dynamic content:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;ip static&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /var/www/ip/public/static_test.html
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;example1.com static&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /var/www/example1.com/public/static_test.html
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;example2.com static&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; /var/www/example2.com/public/static_test.html
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;?php echo('ip dynamic'); ?&amp;gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;ip/public/dynamic_test.php
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;?php echo('example1.com dynamic'); ?&amp;gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;example1.com/public/dynamic_test.php
&lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;?php echo('example2.com dynamic'); ?&amp;gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;example2.com/public/dynamic_test.php&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h4 id=&quot;setting-up-virtual-hosts-in-apache&quot;&gt;Setting up virtual hosts in Apache&lt;/h4&gt;
&lt;p&gt;Apache has the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-available&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sites-enabled&lt;/code&gt; style of configuration as Nginx. Let’s change directory to the available sites:&lt;/p&gt;

&lt;p&gt;cd /etc/apache2/sites-available/&lt;/p&gt;

&lt;p&gt;If you list the files with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls&lt;/code&gt;, you should see a file called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;000-default.conf&lt;/code&gt;. This is the default config file for all requests to Apache. We need to point this to our newly-created webspace. Edit the file:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo nano 000-default.conf&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and change the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DocumentRoot&lt;/code&gt; to our new location: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DocumentRoot /var/www/ip/public/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We can use this file as the basis for the config for our other domains:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo cp &lt;/span&gt;000-default.conf example1.com.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Edit the file and let’s make some changes:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano example1.com.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;ul&gt;
  &lt;li&gt;Set the ServerAdmin email address to something useful.&lt;/li&gt;
  &lt;li&gt;Set the DocumentRoot to the correct location: DocumentRoot /var/www/example1.com/public/&lt;/li&gt;
  &lt;li&gt;Add the line: ServerName example1.com with your main domain name for this webspace&lt;/li&gt;
  &lt;li&gt;Add the line: ServerAlias www.example1.com with any aliases or subdomains that you want to point at this webserver&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Repeat the above for your other domain names (example2.com in this tutorial).&lt;/p&gt;

&lt;p&gt;Enable the virtual hosts by adding a symbolic link in sites-enabled:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /etc/apache2/sites-available/example1.com.conf /etc/apache2/sites-enabled/example1.com.conf
&lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /etc/apache2/sites-available/example2.com.conf /etc/apache2/sites-enabled/example2.com.conf&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Restart apache and test:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/apache2 reload&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;At this point, the static HTML pages should all still point to /var/www/ip/public/ because Nginx does not yet know about the virtual hosts. All the dynamic PHP pages should point to the correct place, because these requests are being handled by Apache.&lt;/p&gt;

&lt;p&gt;In other words, test by browsing to the following, replacing the examples with your domain names:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;x.x.x.x/static_test.html Should display “ip static”&lt;/li&gt;
  &lt;li&gt;x.x.x.x/dynamic_test.php Should display “ip dynamic”&lt;/li&gt;
  &lt;li&gt;example1.com/static_test.html Should display “ip static”&lt;/li&gt;
  &lt;li&gt;example1.com/dynamic_test.php Should display “example1.com dynamic”&lt;/li&gt;
  &lt;li&gt;example2.com/static_test.html Should display “ip static”&lt;/li&gt;
  &lt;li&gt;example2.com/dynamic_test.php Should display “example2.com dynamic”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we are all ok with Apache and dynamic pages. We just need to fix Nginx and the static pages.&lt;/p&gt;

&lt;h4 id=&quot;setting-up-virtual-hosts-server-blocks-in-nginx&quot;&gt;Setting up virtual hosts (Server Blocks) in Nginx&lt;/h4&gt;
&lt;p&gt;Let’s browse to out Nginx config files for out sites-available:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /etc/nginx/sites-available/&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Remember we had one config file here called ip for all of our requests. We need to create a new one for our two example domains. We’ll do example1.com first:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo cp &lt;/span&gt;ip example1.com
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano example1.com&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You’ll need to change the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Remove default_server from the line listen 80; You can only have one default server config, which is the file ip&lt;/li&gt;
  &lt;li&gt;Update the root path root /var/www/example1.com/public/&lt;/li&gt;
  &lt;li&gt;Add the server name and aliases: server_name example.com www.example.com;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Repeat for example2.com&lt;/p&gt;

&lt;p&gt;Now reload the config files for Nginx:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;sudo&lt;/span&gt; /etc/init.d/nginx reload&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;And check that the following resolve correctly:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;x.x.x.x/static_test.html Should display “ip static”&lt;/li&gt;
  &lt;li&gt;x.x.x.x/dynamic_test.php Should display “ip dynamic”&lt;/li&gt;
  &lt;li&gt;example1.com/static_test.html Should display “example1.com static”&lt;/li&gt;
  &lt;li&gt;example1.com/dynamic_test.php Should display “example1.com dynamic”&lt;/li&gt;
  &lt;li&gt;example2.com/static_test.html Should display “example2.com static”&lt;/li&gt;
  &lt;li&gt;example2.com/dynamic_test.php Should display “example2.com dynamic”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Your webserver should now be configured to serve pages using Nginx, with Apache helping out in the background for any dynamic pages. If you want to add a new domain, you can just create the directory structure, add the configs for Apache and Nginx and reload the servers!&lt;/p&gt;
</description>
        <pubDate>Sun, 23 Jul 2017 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/configuring-a-webserver-running-apache-and-nginx/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/configuring-a-webserver-running-apache-and-nginx/</guid>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>Red Parasite Hitching a Ride on a Spider</title>
        <description>&lt;p&gt;I saw a wolf spider the other day (Pardosa amentata) dashing about with her egg sac beneath her. As it was a warm sunny day, she was particularly fast so I was unable to take a photograph. However, I did notice that she had two bright red lumps on her abdomen. I had never seen this before, and reasoned that it must be some sort of parasite that was living on her or had laid some eggs. There are species of wasp that target spiders, but they tend to subdue the spider before laying eggs to incapacitate it whilst keeping it fresh ready for its young. The spider I saw was certainly not subdued! I could not find anything on the internet about any vibrant red parasite that attacked spiders in the UK. Every google search with any combination of “red”, “spider” and “mite” landed me on an article about the unrelated “red spider mites”!&lt;/p&gt;

&lt;p&gt;By pure coincidence, the very next day, I saw a young garden spider (Araneus diadematus) with the very same red lumps! This spider was very small (~4 mm) so it was hard to see, but I was able to take some photographs:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/posts/2017/spider_parasite1.jpg&quot; data-lightbox=&quot;spider_parasite&quot; data-title=&quot;Garden Spider with parasite&quot;&gt;
	&lt;img src=&quot;/assets/posts/2017/spider_parasite1.jpg&quot; title=&quot;Garden Spider with parasite&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;
&lt;a href=&quot;/assets/posts/2017/spider_parasite2.jpg&quot; data-lightbox=&quot;spider_parasite&quot; data-title=&quot;Close up of parasite on spider&quot;&gt;
	&lt;img src=&quot;/assets/posts/2017/spider_parasite2.jpg&quot; title=&quot;Close up of parasite on spider&quot; style=&quot;display:inline; width:30%&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I posted these images to the &lt;a href=&quot;https://www.facebook.com/groups/BritishSpiderIdentificationGroup/&quot; target=&quot;_blank&quot;&gt;British Spider Identification Facebook Group&lt;/a&gt;, where I quickly got a lead on the parasite: Trombidium sp., most likely Trombidium holosericeum (the Red Velvet Mite). Once I had the genus that the parasite belonged to, I was finally able to discover some useful information on the internet! The UK Safari website says the larvae feed off spiders and insects before dropping off, burrowing underground, moulting and emerging as adults. It also says they do not injure their host.&lt;/p&gt;

</description>
        <pubDate>Tue, 27 Jun 2017 00:00:00 +0000</pubDate>
        <link>https://samwedge.uk/posts/red-parasite-hitching-a-ride-on-a-spider/</link>
        <guid isPermaLink="true">https://samwedge.uk/posts/red-parasite-hitching-a-ride-on-a-spider/</guid>
        
        
        <category>Nature</category>
        
      </item>
    
  </channel>
</rss>
