My First Book Mastering Sass is Out Now!

My very first book was published in late August 2016. The book Mastering Sass is published by Packt Publishing and is available in ebook (PDF, Mobi, Kindle) format or print.

It covers advanced Sass, Compass and Susy techniques to create responsive, data-intensive web applications such as e-commerce websites, news websites or anything else.

One of the things you’ll learn from Mastering Sass is how to build a robust, responsive grid system using Susy with only 27 lines of Sass.

You can get you copy now from PacktPub:
Mastering Sass

Creating and Adding SSH Keys from Git to Github

I’ve done the “creating and adding SSH keys from Git to Github” process possibly 5 times now in the past 3 -4 years. Each time I had to just follow along blindly with the Github guide and cross my fingers and pray I got all of the black magic incantations correct and didn’t accidentally unleash the hordes of hell upon the world by my copy/pasting.

So recently I got a new laptop and the day I bought it I remember being happy I had a nice new laptop with a touch screen and Windows 8, which I really like! I’m not an idiot who can’t adjust to a new menu. “Oh Noes! A menu that covers the entire screen instead of just a quarter. How will ever manage??”. Come on people!

Anyways, as I was saying I was happy about my new laptop but there was an underpinning of doom! I know at some point I was going to have to set up all my dev software from servers, to IDEs and of course…SSH access to Github. Dun Dun DUUUUUNNN. So this time I decide enough was enough. The Github guide is enough to get the job done but I want to understand what the heck I’m doing and why. I started into the process but instead of just copying and pasting and finger-crossing I researched each command. I Googled and Bingled and Stackoverflowgled my way to figure out what each part was doing and why. I went from copying and pasting to straight up typing it all out from memory in about an hour. And I fully understood it so I full control. The black magic was in my control now!

So I thought I’d write an in depth tutorial of getting setting up SSH Keys for use with Github so you too can stop dreading the black magic of SSH and take control of its power. Here goes…

Check for pre-existing SSH keys

The first thing you should do if you are on a machine which perhaps already has Git installed or your or other people have used for server-side development is check if you already have an SSH key on your machine. It could be for any reason but you could already have an SSH key. SSH keys are not just for connecting your machine to Github. You also use SSH to connect to Amazon AWS, Microsoft Azure and many other Cloud Based systems.

The SSH key you are about to create would be your personal or “private” SSH key. Any service you wish to SSH into using the private => public key authentication, not just Github would require your private key and public key which is placed on that service (for example Github). The service then compares your private key with it’s key (public key) and together they form your authenticated secure connection with that service. For that reason, you may already have created an SSH key and, if so, you can (and probably should) simply use that key.

To Check for an Existing SSH key

To check for an existing ssh key open Git Bash and run

ls -a ./.ssh

You will either see a list of files one of which should be in the following list:

  • id_rsa.pub
  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub

Otherwise you will see an empty folder or an error:

ls: Cannot access /.ssh: No such file or directory

This means there is no such folder. So no SSH keys have ever been generated.

WINDOWS: If you’re on Windows and using the latest (Jan 2016) Git Bash you might have a false positive because Git actually doesn’t look in the right directory when doing ls -a ./.ssh. You should double check with:

dir C:\User\{your-username-here}\.ssh

When we generate our key it will create this folder and the required file. Most likely id_rsa.pub or id_rsa

Creating a new SSH Key

To generate a new SSH key we use the ssh-keygen unix command. We will be using it with the following flags:

  • -t rsa => This is the type of key we want to generate. You can choose from dsa, ecdsa, ed25519, rsa or rsa1. For Github we will be using rsa.
  • -b 4096 => This is the number of bits (or characters) you want in the key. For RSA keys, the default is 2048 bits. Github requires 4096 bit RSA keys for authentication.
  • -C "[email protected]" => This is a comment or a labal for this RSA key. Github recommends it the email associated with your Github account.

NOTE: The -C flag for comment is uppercase. A lowercase “c” is for something completely different and only works with rsa1.

The above flags are all you require to create a suitable SSH key for use with Github. The full command is:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

What if I already have a key and I want to keep it?

You might already have an SSH key and you don’t want to delete it. Maybe it’s in use on another service. Or perhaps it’s dsa or it’s rsa but doesn’t have a comment or it’s only 2048 bits.

In these cases you will need multiple SSH keys. To this you can add the following flag to the above command:

  • -f output_keyfile => This is the file you want to save your key to. You do not need to specify an extension. Also, by convention you should use all lowercase with underscores, not hypens. Definitely no spaces!

Your code to create a new SSH file would look like:

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/your_file_here

After all of that you should see something like the following:

Your identification has been saved in /c/Users/YourUserName/.ssh/your_file_here.
Your public key has been saved in /c/Users/YourUserName/.ssh/your_file_here.pub.
The key fingerprint is:
SHA256: SoMeRanD0MJuNkAnDCraPHeReThaTIsVeRyLongBla [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|   some random   |
|    symbols      |
|     and junk    |
+----[SHA256]-----+

Or you could just use the normal command with no -f flag and enter another filename…but what’s the fun in that?

Turn on the SSH Agent

Right now all you have done is create the public and private keys. However, just as you would need to add the public key to Github so you know your connecting with Github when you make an SSH connection, you also still need to add the private key to your own SSH Agent so Github can identify you.

To do this you first turn on your SSH Agent with the following command:

eval $(ssh-agent -s)

If that doesn’t work you may need to wrap the $(ssh-agent -s) in double quotes:

eval "$(ssh-agent -s)"

The next step is to add your private key from id_rsa to the SSH Agent using ssh-add:

ssh-add ~/.ssh/id_rsa

Now if you run:

ssh-add -l

you will see the id_rsa key, and possibly others if you have more than one ssh added to the SSH Agent.

Adding your SSH Key to Github

Finally, we’re ready to add the public key to Github so we can connect securely and easily. The reason we do all of this is so we can securely gain access to our repositories every time we want to clone, push, pull or fetch through Git.

First copy the contents of the file in .ssh/id_rsa.pub to your clipboard. You can either open it in a text editor and copy it that way or you can use the command:

clip < ~/.ssh/id_rsa.pub

Then log into you Github Account and:

  1. hover on your profile icon on the top right and go to Settings
  2. On the left Sidebar Menu go to SSH keys
  3. Click the Add SSH key button in the upper right corner of the SSH keys panel
  4. Paste the key into the Key textarea and give it a Title you’ll recognise that you’ll associate with this key. I generally use the Computer name.
  5. Click Add Key to save.

That’s it! You now not only know how to give yourself SSH access to Github but also what is actually going on. This will help you correct mistakes or just play around and get comfortable with doing this. Also, everythin you’ve learned here will help you if you need to add private/public SSH key pairs to other services for anything.

Leave a comment if you have any problems or questions.

WordPress 4.4

A shiny new WordPress to try out! Yay! I’ve switched to the new Twenty Sixteen theme too. On first impressions I’m liking it…however I’ll have to redo all my images. I’d cropped them exactly to work with the Twenty Fifteen theme and now they’re all about 30px – 40px too small. That’s a job for after Christmas though.

Updating all my plugins too and that was definitely faster. About 2 – 3 seconds from clicking update to the plugin being done updating. That’s compared to about 5 – 7 the last few times. Even the download and install of twenty sixteen from through the Dashboard was all considerably faster.

The REST API is here at last they say. So once work eases off a bit I’m eager to play with that. Have some ideas I want to try out too so it’s come at just the right time it seems.

Laravel Installer on Windows: Setting your Environment PATH Variable

Seriously? Can people please stop ignoring the fact that Windows users also use Frameworks and APIs and whatever else’s when you’re writing your documentation!

You wouldn’t build a website that only works on Mac would you?! So stop acting like people don’t use Windows to do their job also!

Anyways, here’s how to install the Laravel installer for Laravel 5…on a Windows (if you’re own a Mac…go read the actual instructions which were made only for you).

NOTE: The following is for Windows 8 but should work on Windows 7 also.

  1. Run composer global require "laravel/installer=~1.1" from the commandline.
  2. Open you Environment Variables…

      Method 1 (easy way)

    1. Search “env”
    2. Go to “Edit environment variables for your system”
    3. Under “System Variables” select to “Path” and click “Edit…”
    4. Add ;C:\Users\YOUR_USERNAME_HERE\AppData\Roaming\Composer\vendor\bin to the end.
      IMPORTANT: There must be a semicolon before it, and no slash or semicolon after it

      Method 2 (The fun way)

    1. Go to Control Panel > System and Security > System > Advanced System Settings
    2. Go to the Advanced tab
    3. Click “Environment Variables…”
    4. Under “System Variables” select to “Path” and click “Edit…”
    5. Add ;C:\Users\YOUR_USERNAME_HERE\AppData\Roaming\Composer\vendor\bin to the end.
      IMPORTANT: There must be a semicolon before it, and no slash or semicolon after it
  3. 2.1
    2.1.1

Don’t forget to run composer self-update and then close the current cmd and start a new one. This is because the current cmd window won’t pick up the changes to the path, so you have to close it and start a new one.

Enjoy!

P.S. In fairness for years Mac users had to put up with the same thing so I know it’s karma, but still…us Windows users have it tough already…we’re using Windows :(

Learning Drupal8: Day 1

I’ve decided to look for something other than WordPress as my CMS of choice. Hearing Drupal8 will be more OOP, and use Twig templates I’m getting on board.

What’s got me excited about Drupal8

I’ve been a WordPress developer for almost all of my time with php. I’ve written a series on how to build a theme, reviewed plugins and tweet regularly about nice new developments like not having to @import css in your child stylesheets anymore. However, I’ve been growing discontent with WordPress lately. I’ve been really getting my OOP on in PHP and started writing my own MVC framework (more to learn and for the fun of it than anything else). As a result, every time I come back to WordPress to write a plugin or tweak something I get a bad taste in my mouth.

I HATE the ‘add_action’ and ‘add_filter’ functions. Why can’t we have an OOP wrapper for those stupid functions?! Or an Observer pattern that just picks up plugins in a nicer way. I hate the ugly “loop” and the clunky menu functions. The awkward mix of procedural and OOP in places makes me cringe. Frankly, while the WordPress admin is nice and simple to use, WordPress is not fun to develop for. At least not once you realise what it’s missing.

Perhaps ‘missing’ is the wrong word. Ignoring might be a better word. WordPress is blatantly ignoring what are becoming the standards in PHP. I know WordPress isn’t a framework but I still think they need to adopt the PSR-2 coding standard. PSR-4…not much point I guess if you’re still clinging onto procedural functions all over the place. Anyways, those things and more got me searching for something else. I’d been hearing about Drupal adopting some Symfony components and Composer. So I watched some videos and read some posts…and I’m excited about Drupal8.

OOP at the core, PSR-4 autoloading, routing and Twig! Possibly the most exciting thing is that we can use clean, simple templating syntax to build themes for Drupal8. While I’ve never built a theme or even a full website with Drupal I WANT to now. So that’s what’s got me excited about Drupal8. The Drupal team have made a brave move and I for one hope other organisations will follow suit…but if they don’t, I hope developers will follow suit and move to the brave new world.

Installing Drupal8

It’s been a few years since I’ve installed Drupal. I can remember it was really awkward. There wasn’t much help in the form of…well, forms. Most things were manually set up in the config files and it was a steep learning curve. Also, it really didn’t use server resources well. While WordPress would install fine on the default php.ini settings Drupal needed alot of time to do what it did.

Part of that is now better. There is an interface which will let you quickly add your DB connection credentials and setup your overall site info but it STILL required me to up my script execution times. Not only that, it let everyrhing go arseways first with no warning. There where two screens before it tried creating all the MANY databases tables. Surely Drupal could do a check and let you know you might want to up your max_execution_time from the defaul 30 seconds to AT LEAST 60. Drupal could even use set_time_limit to extend it a little bit if needed. Instead it crapped out and half installed the database and required me to drop all the tables and delete the settings.php file, up my max_execution_time, reboot my local server and try again. Not a good start.

Admin and Status Settings

The admin is still a bit overwhelming. However, I can remember the same of WordPress and Joomla anytime I’ve tried to get into it (I just can’t…it’s admin is so ugly!). I think the only CMS I instantly liked and understood how to get around was OctoberCMS (I’m just waiting for it too pick up some steam). While the admin is a bit cluttered, I really like the new Quick Edit feature which allows you to edit content from the front end…sort of Concrete5 style. WordPress has been threatening this since before 3.9 but it’s still just a plugin for beta testing. The CKEditor will have too work it’s charm on me still but I like the various levels of HTML editing it allows for. Although some tag buttons like the QuickTags in WordPress would be nice.

Another thing I noticed was an error out of nowhere about “Trusted Host Settings”. I have no idea why this is a thing. I mean really? You’re gonna make me use regular expressions to hold your hand to figure out the server address your on? I can’t get my head around this. I stopped my Drupal journey for day 1 there because I broke the site and frankly I wasn’t in the mood to set it up after the php.ini stuff (which only took a few seconds but still bugged me). I’ll read up on it tomorrow. For now I need to eat and write the IoC for my MVC framework “Thistle”.

Creating a Local CDN for Local Web Development

The What

I start most of my projects on my local XAMPP install. WordPress Plugins, WordPress Themes, Laravel Applications, websites, PHP frameworks or libraries…just about anything. One thing I’ve realised I do alot is download things like Boostrap, Foundation, jQuery, and other libraries I use frequently.

The Why

I realised most of the projects have these various frameworks and libraries in them. So 10 projects in my htdocs folder might each have the entire Bootstrap Framework in it somewhere. That’s both a waste of time and space. Now I could use the various online CDNs to link to the files I want to use, but I’ve realised that doesn’t always work out.

Example:
Recently (just over Christmas), I was on a train to the location I was spending Christmas. I’d started working on a plugin just before I left, with the aim I would work on it with the quiet time I would surely have. On the train up I couldn’t connect to the WiFi. So I opened my IDE, started my server and decided it might be for the best to not have the distrations of the internet. I opened the project in the browser AAANND…everything was broken. I’d used the bootstrap CDN to load everything holding it together. It was a mess.

So after all that I decided there might be a few benefits to creating a local CDN! No more duplicate css and js files, I can still choose from compressed or uncompressed and even older version of things like Bootstrap and jQuery when the project dictates it…like when developing a plugin or extension for a companies website built on Bootstrap 2.3 or jQuery 1.9. It happens, and time and budget constraints are always a factor.

The How

Directory structure

I use XAMPP as my local server. Mainly because it’s available for the main Operating Systems (Windows, Mac, Linux). So if your on MAMP or WAMP you’ll have to adjust accordingly.

In your root web directory (mine is C:/xampp/htdocs ) create a folder called “cdn”. Here we’ll keep all of our frameworks, libraries and even images and any other files you’ll be using frequently across multiple local projects. For this example I’ll be using Bootstrap v3.3.2.

Create a folder called “bootstrap” and within that a folder for the version: “3.3.2”. This will allow you to easily manage and utilize multiple versions across your projects. For example I also have “2.3.2” for any legacy projects.

Within the “3.3.2” folder download and extract the essential boostrap files. You’ll get it here: https://github.com/twbs/bootstrap/releases/download/v3.3.2/bootstrap-3.3.2-dist.zip

You should now have the following folder structure

xampp
  |-- htdocs
        |-- cdn
             |-- bootstrap
                 |-- 3.2.3
                      |-- css
                      |-- fonts
                      |-- js

I also like to have the original .zip files in a folder called “downloads” so if I do need the entire thing quickly for something it’s there.

So I simply created a “downloads” folder in “boostrap” and place all the zip archives in there.

So now all you have to do is link to that one copy of bootstrap from any local project using:

<link href="http://127.0.0.1/cdn/bootstrap/3.2.3/css/bootstrap.min.css" rel="stylesheet" type="text/css" >
and
<script src="http://127.0.0.1/cdn/bootstrap/3.2.3/js/bootstrap.min.js" type="text/javascript"></script>

TIP #1 If you’re worried about performance use http://127.0.0.1 instead of http://localhost in the urls. It’s slightly faster because the DNS doesn’t need to lookup the alias. Same goes for custom Virtual Host aliases.
TIP #2: I’ve actually set mine up so http://cdn.dev/ goes to the cdn folder. You could even create an alias to each framework, such as cdn.boostrap.dev/3.2.3/” links to Bootstraps v3.2.3 directory and so on…but I’ll leave that up to you.

Aliens: Colonial Marines

When I watched this I got angry. The demo looks awesome! That sentry turret bit and the when the power goes out. That all looked straight out of the film. Right “feel” too it.

Ugh! The only thing the same is the sound. The sounds in the game are perfect. The dialogue and voice acting is absolutely terrible but the sound effects and music is all good.

What might have happened…

It’s like they had a huge server crash and lost all the work from 5 years and then spent 1 year making what we ended up getting. The sound effects were straight from the film so that’s only bit that’s the same. They had to rewrite the script so some 12 years old foreign exchange student got that job and all the neighbours did the voice acting. “If you make a fucking sound your brains are what they find in the garbage tomorrow!” What on LV-426 is that supposed to mean?? He’s gonna make him stand over a bin while he shoots him? Or he’s going to scoop up his brains and put them in the bin after?? O.o (at least he’s considerate of the cleaners I guess) Also…who are “they” that are looking in the garbage every morning?

Some other notable quotes

“You gotta run this by me before you talkin’ crazy”

— Winters

“O’Neal if you don’t move your ass everyone on this ship will die! Ignore that that sounded like a question and move your ass marine”

— Cruz

“Raider 6-5 will wait for you, but goddammit don’t make us wait for you!”

— Cruz

Someone read that out loud and nobody noticed anything wrong with that statement…seriously??

The Loader Boss Fight

*** SPOLER WARNING ***
I’ve played some frustrating bossfights. Most of the time it’s just because the first two or three times you react too slow to the bosses killer projectile move or you just didn’t see the bright glowing flashing unmissable item you’re meant to use until you cave and watch the walkthrough on YouTube.

That said, the midway “bossfight” involving the loader and a “not so big or intimidating” boss alien is FUCKING INFURIATING!!!! I play all new games I get on the Hardest difficulty first time around (or second hardest, depending). It’s more fun and you get more achievements that way and you get better at the game faster. That way when you finish the campaign and move online your less likely to be among the worst of the noobs.

However, on Colonial Marines, after trying that boss fight about 6 times I gave ap and dropped it to the easiest setting. It’s a terrible, tedious, buggy, painful mess of a fight and it simply wasn’t worth anymore than six tries.

While in the loader you become far less of a threat to the aliens around you. I could almost see them all saying “Oh good he’s getting into that stupid yellow thing. LET’S GET HIM!!!”.

Basically, the main problem is, if you don’t beat the boss first time, the checkpoint places you about 10 seconds into the fight, so you’re already under attack and not even near the Loader. So you have to climb slowly into the stupid thing while aliens slash away at you taking all your armour and health. Then, if you’re lucky enough to not die before being able to move again the real pain begins…controlling the loader. It randomly spins around so your back is facing all the enemies. You miss way more punches than you land. I think you miss 4 out of five punches at least. And the whole time your “team” are on their lunch break or something for all the help they are. Then when you finally win the fight the finishing move is so ridiculous it looks more like you’ve gently laid the alien on it’s back so you can tickle it’s belly. It’s so unsatisfying. STUPID STUPID STUPID FUCKING GAME!!!

Conclusion

Stay away from it unless you get it for €5 second hand somewhere and you want a laugh at some of the dialogue and you REALLY REALLY like the Aliens universe enough to be very forgiving.

For me…I’m saving for Alien: Isolation. I hear good things.

Apache shut down unexpectedly due to a blocked port – Solution

Problem:

You start Apache ( XAMPP, WAMP, MAMP, AMPPPS or something ) and mysql starts just fine but Apache gives red errors along the lines of:

[Apache]  Status change detected: running
[Apache]  Status change detected: stopped
[Apache]  Error: Apache shutdown unexpectedly.
[Apache]  This may be due to a blocked port, missing dependencies, 
[Apache]  improper privileges, a crash, or a shutdown by another method.
[Apache]  Press the Logs button to view error logs and check
[Apache]  the Windows Event Viewer for more clues
[Apache]  If you need more help, copy and post this
[Apache]  entire log window on the forums

Solution:

If you are using the latest Skype:

  1. Go to Tools > Options > Advanced > Connection
  2. Disable the “Use port 80 and 443 for alternatives for incoming connections” setting
  3. Sign Out and close all Skype windows*
  4. Start Apache and it should work now

* On Windows 8 you will need to open Task Manager and kill the skype.exe process before changes will take effect. Skype never really shuts off completely by just closing the window on Windows 8.

UPDATE (28th September 2015)

Some people have still had issues with port 80 being blocked so I’m going to list some possible causes below. Unfortunately without knowing more about someone’s individual setup and what they have installed it’s impossible for me to know what the problems is.

So, it could be:

  1. Another application (other than Skype is using port 80). Likely candidates are another server such as WAMP, MAMP, AMPPS, or Visual Studio Server (which will have been installed if you installed Visual Studio Express/Pro for Web). Even if you’ve uninstalled them they can still “reserve” the right to port 80. Best set XAMPP to use another port such as 8080, which is a common alternative to port 80.
  2. Firewalls. A firewall is designed to prevent incoming and outgoing connections. Some firewalls block port 80 by default because it’s a common port to get attacked or scanned by malicious A-holes.
  3. Anti-virus software. Again, by default some anti-virus software will block port 80.

Possible solutions:
Open up your task manager and see what applications/processes are running. If any of the above are running, either kill them in the task manager (if possible…many firewalls and anti-viruses won’t allow you to stop them from the task manager) or from the actual application and restart XAMPP (mainly Apache) and try again. Once you’ve found the culprit either change it’s configuration to allow XAMPP to have port 80…or change which port XAMPP by default. Again, 8080 is a common alternative. More on how to do that here: http://stackoverflow.com/questions/11294812/how-to-change-xampp-apache-server-port

That’s all the advice I can offer I’m afraid. Hope it helps!

Turn off Windows 8 UAC ( User Account Control )…COMPLETELY

THE WHY

So I got a new computer for myself for work yesterday. It was certainly time. I tried and tried to get a Windows 7 or figure out a way to fund a Mac of some sort but I needed a computer fast. Lots of clients and contracts and just couldn’t put it off. So I got the best machine I could find on the company budget and made the (reluctant) step to Windows 8. Not even 8.1. Just pain ol’ 8. To be honest I think windows 8 got a bit of a unfair time. Not completely unfair…just slightly.

NOTE: To just get straight to the instructions go right to the end of this article. Also, I’m assuming you’re not an average user and don’t need hand holding or pictures.

To be fair I’m not the average user. I’m probably a Windows power user. Not a superuser but certainly not afraid to get my hands dirty. I keep Task Manager (or Process Explorer usually) on so I can see what processes are running always. If a process appears for no reason I know about it before my Anti-Virus does usually.

I’m a web developer so I spend most of my time jumping between local servers, command prompt, Git, IDEs and FTPs. I spend my days designing user interfaces and figuring out ways to make UI’s intuitive. So I was quickly able to apply all of that knowledge to Windows 8 and within two hours and some head scratching moments I was adjusted. In fact, I like 8. I like the look and it’s not Vista (as in it performs just fine). A few things simply are not intuitive and there were no hints. Especially when using it on a desktop PC with a mouse. Things like grabbing the top of the screen and pulling down to property shut down an app. That was the only thing I actually ended up searching online for an answer yesterday. Everything else, I’m happy to say I found myself.

THE WHEN

However today…I had my first genuine “Fer-Fuk-Sake Windows 8” moment. I like to have a shortcut to both the hosts file and the vhosts-https.conf file in my htdocs directory of XAMPP. Reason being, when I setup a site, or Laravel or WordPress locally I can just pop in and out of these two files real quick in notepad, setup my vhost for the site ( ‘laravel.dev’ or something ) and restart Apache. Takes all of 10 seconds. Not today….

Today, I found out that Microsoft have painted everyone heavily with the “computer dullard brush”. Far more than they did with Vista. We’re all knuckle-dragging morons who might send the world into an apocalyptic dark age if left with ACTUAL administrator access to OUR OWN COMPUTERS. That we bought. With our own hard-earned money. To use for grown up reasons. I’M A GROWN-ASSED MAN DAMMIT!

THE HOW

Anyways, that’s the why; here’s the how:

  • Press Windows + R, type regedit and hit Enter
  • Got to HKLM > HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System
  • Right-click EnableLUA, click Modify... and set to 0

After that you’ll need to restart and all should be well with the world.

Cannot Find or Edit Hosts File on Windows

So today on a computer I’ve been working on for only a short period of time required me to set up a virtual host for a local Laravel project. The final part of that process is editing the hosts file. I’ve edited the hosts file on my laptop numerous times to block certain sites for better security. So I quickly navigated to the C:/WINDOWS/System32/drivers….what?! No etc folder!!! Hmmmm. So I went and opened Windows Explorer ( aka “a folder” ), clicked the Organize dropdown up on the top-left, opened the Folder and Search Options panel, went to the View tab and set Hidden Files and Folders to “Show hidden files, folders and drivers”. Then I unchecked “Hide protected operating system files” and clicked Apply.

Searched for it again and still no etc folder. Apparently this happens.

Solution

You need to force Windows to grant you access and unhide it via the commandline. So:

  1. Hit WindowsKey + R to bring up the Run dialog
  2. Type cmd and hit enter to open the commandline
  3. From the commandline type attr -H -S C:\WINDOWS\System32\dirvers\etc\hosts and hit enter
  4. The commandline should go to a new line but return no text
  5. This means the command has been successful. You can close the command prompt. Your etc directory with it’s files will be accessible now

Enjoy!