Access Forbidden! – XAMPP on macOS Sierra

I just installed a fresh installation of Sierra on my Hackintosh and couldn’t for the life of me get XAMPP to run properly! I got “Access Forbidden” on my localhost and vhosts.I figured I’d write a few notes for people that run into this issue running XAMPP on your Mac. Please comment below if you don’t agree with or see a flaw in my notes and I can test and update your feedback. This guide assumes you already know basics behind XAMPP/WAMP stacks and are stuck getting it running on OSX.

Are they rebranding OSX to macOS? I digress…

Setting Up httpd.conf & httpd-vhosts.conf

1.) Open up XAMPP and click the tab Manage Servers. Highlight Apache and click Configure. Click Open Conf File. This will open your httpd.conf file.

2.) In httpd.conf find the follow line of code and change it daemon to your OS X username.
User daemon

3.) In httpd.conf find the following line and uncomment it (by removing the #)
#Include etc/extra/httpd-vhosts.conf

Save the file, don’t close TextEditor

4.) In TextEditor, goto File -> Open. You should start out in xamppfiles/etc. Click into the extra directory and then open httpd-vhosts.conf

5.) Remove the example code -or- comment all of it out.

6.) Use the following code to base your vhosts on, keep in mind I kept the default localhost example just to access the default htdocs location.

7.) Restart Apache services in XAMPP’s Manage Servers tab.

Solving Access Forbidden in XAMPP

This part is the one thing many would disagree with and I’m not 100% a way around this in macOS Sierra. Previously I’ve simply chmod 644 -R my working folders but I couldn’t for the life of me get around the forbidden error. If you know a better way around this please comment below.

1.) Open Terminal (Applications/Utilities/Terminal)

2.) cd to your directory and give execute read write permissions, example below
$ sudo chmod -R +xrw wordpress/

If you’re new to this, the $ is just signifying the command line beginning and we’re not su. This should set execute/read/write permissions reclusively to all files and folders within our working directory. I haven’t tried it but you can also try chown but these directories are already owned by my user…

Setting Up Hosts File in OSX Sierra

If you’re not familiar with vhosts on a local XAMPP stack, the hosts file allows you to overwrite local DNS routing on your machine. In our scenario, we will one for our local wordpress environment.

1.) In terminal, simply use this command to open up the hosts file:
$ sudo nano /private/etc/hosts

2.) At the bottom of the file add this to your hosts file:
127.0.0.1 wordpress.dev

This will now route traffic from http://wordpress.dev to your localhost. If your httpd.conf and httpd-vhosts.conf files are setup correctly, you can now access your local WordPress developer environment. Try to refresh http://localhost -or- for example http://wordpress.dev

Read More

How To Tweet From CLI On Windows 10 w. Node.js

Always working from PowerShell, CMD, Git Bash, or Git Shell? Ever want to tweet from the command line while your pushing code to your Github repository? I was interested in doing this on my laptop, making it easy to tweet on the go while I’m coding away at a coffee shop. I’d like keep my phone face down or in my pocket to avoid distractions… But that urge to tweet happens to often. Windows Store Twitter app is crap, and Twitter.com in browser is always sluggish… Let’s just tweet from the command line!

Tweet from CLI with Node.js

1.) Download & Install Node.js

2.) Run cmd.exe or PowerShell. I prefer to use Git Bash.

3.) Install cli-tweet by typing this command in:

npm install cli-tweet -g

4.) Now we need to see where npm installed the npm_modules folder.
npm root
It will return a path that we need.


5.) Open File Explorer, Right Click “This PC” -> Properties, click Advanced system settings, then click Environment Variables. Copy and paste the path that npm root gave you into your Windows 10 Systems PATH.

6.) Close your CLI window and run it again in Administrative Mode.

7.) Type the following:
tweet config

8.) It will give you an authorization URL that you have to copy and paste into your browser. Once the page loads, login and authorize RaedsLab app and it will give you a token to enter.

9.) With cli-tweet configured, try typing

echo "Hello Universe" | tweet

Do you like this awesome cli tweet tool? Go star the repo over on Github! If you don’t want to use RaedsLab Twitter app, you can create your own Twitter app and clone cli-tweet repository. In main.js line 13-14 you should see the key and secret for your Twitter App. You can install cli-tweet with your own key with the command: npm install /path

Read More

301 Redirect Subdomain Forwarding On AWS Route 53

amazon-web-services-logo-large

UPDATED: fixed missing/broken gist link with the code snippet.

Recently I decided to ditch registrar DNS Managers like GoDaddy’s in favor of Amazon’s Route53. I really like their console and the DNS is snappy and responsive, not to mention the handy features when creating and pointing to Load Balancers for your TLD. However, one draw back of Route 53 is the lack of subdomain forwarding. Below is a quick solution.

All you will need is an Amazon S3 bucket, the static website end-point, and a Route 53 CNAME.

1.) Create an S3 Bucket: Name the bucket ie: subdomaintoForward.mydomain.com. It has to be the exact subdomain you wish to forward otherwise Route 53 won’t resolve. Choose the region and create!

create-a-bucket

2.) Enable S3 Website Hosting: Open your new bucket and click the “Properties” tab. Open up “Static Website Hosting” than select “Enable website hosting” and make the “Index document” simply index.html. After that, click “Edit Redirection Rules” to open up a text box.

bucket-properties

Paste in the XML below:

This breaks down a regular URL that you want it to forward too. In this example, I want subdomaintoForward.mydomain.com to 301 redirect to http://domaintoforwardto.com/anything/after/thedomain/index5.html – compare this URL to the XML above, you should be able to figure out the syntax.

Click Save!

3.) Create A CNAME in Route 53: Make note of the “Static Website Hosting” End-point, copy that, then open up Amazon Route 53. Select your Hosted Zone and click “Go to Record Sets”. Click “Create Record Set” and configure your Record. In this example, domaintoForward is the subdomain, use CNAEM, and paste in the Static Web Hosting End-point into Value. Create the record.

amazon-route-53-301-redirect

Read More

Monokai For Google Chrome – Inspect Element

monokai-chrome-developer-tools

I found an interesting repository that web developers might find useful. Monokai for the Chrome Developer Tools! Honestly, this makes the Inspect Element UI more readable for me. I often find myself staring at the source code for hours until my eyes bleed. Now if only I could remember how to style view-source…

Link to the repository:

https://github.com/bjmatt/monokai-theme-chromedevtools

Read More

Transferring WIX Domain To Another Registrar

sad-wix

Googling around, I found this to be buried in random forum posts. I figured I’d document this for future reference.

To transfer your Wix domain from Wix:
1. From your Domain Manager, under My Domains, next to your Wix domain, click Manage.
2. Under Domain Summary, click the Advanced tab.
3. Next to Transfer Away from Wix, click Transfer.

wix-domain-transfer-1

4. In the Transfer window, click Send.

wix-domain-transfer-2

5. An email with a code will be sent to you. Forward this code to your new domain registrar.
You may not receive the email immediately, but you can expect to receive it on the same day.

Source: Dana from WIX Support, Screen Caps: myself.

At this point, you will have to go to a new registrar, such as Namecheap.com and create an account. On the registrar side, you can initiate the domain transfer. Note: Be sure to jot down all DNS Zone information in the WIX Domain Manager panel. Be sure to update the new registrar with DNS information.

Read More

How To Push To Github And WordPress.org

I think this is really important and not many people are aware of this. Evan Solomon deved a tool called Scatter. There are a lot of us that favor utilizing Git > SVN, I feel like SVN is stepping backwards in time. Everyone that is current on Git or started out primarily on git may be turned off by SVN. Welp, kick it in the nuts.

http://evansolomon.me/notes/git-wordpress-plugins-and-a-bit-of-sanity-scatter/

Read More

Varnish HTTP Accelerator Presentation Notes

varnish-cache-image

Poul-Henning Kamp discusses Varnish HTTP Cache at TYPO3 2010 in Frankfurt. In this post, I will provide detailed notes of his presentation. This is for learning purposes and may contain inconsistencies. I will do my best to keep it sharp.

Varnish HTTP Accelerator Presentation Slides

Notes From Varnish HTTP Cache @ TYPO3 w. Poul-Henning Kamp

Content creation can be automated, you have a master copy and you want to distributed it as much as possible. You really want it to be faster than the Linotype, and a step beyond the Heidelberg Print Machine. Varnish’s Elevator Pitch, “Varnish delivers content faster & reliably, reduces the load on your CMS database, cheap hardware does 100+ kreq/s, can assist in content composition, can fixx stupid mistakes, fast, is Free & Open Source Software, has commercial support.”

After 15 years contributing to the FreeBSD project, Poul-Henning Kamp was approached by VG.no to write a web server. VG.no utilizes a slow CMS which needed a caching system that speeds up the HTTP accelerators. With Varnish, Kamp was able to reduce the use of 12 Squid cache services to a mere 3 Varnish cache servers and greatly reducing the response times.

Poul-Henning Kamp’s goals for Varnish started out simple

  • Varnish is only a HTTP Accelerator.
  • Better configuration.
  • Much Faster
  • Content Management Focused Feature Set

“We don’t do FTP, we do HTTP and we do it damn well,” Kamps continues “This is not a cache to put on the client side, this is a cache to put on the server side. It’s important to understand one thing here, the controlling standard for HTTP is still RFC2616, and if you read it real carefully you will find one place where it mentions a cache on the server side,” “then they realize, actually a cache on the serverside is just another web server.”

Cache on the client size has constraints, you cannot cache per user, private cache, crypto, etc. Varnish as a web server can cache anything we want server side, including crypto!

Understanding Varnish and VCL

Varnish aims to make the configuration process simple in VCL or C language. It’s important to understand the operations of Varnish according to the diagram below.

varnish-state-machine

An example of receive VCL code below.

sub vcl_recv {
if(req.url ~ “\.\.|\.exe”) {
error(999, “Bugger off.”);
}
if(client.ip ~ editor_ip) {
set req.http.x-cms = “no stats”;
return(pass);
}
if(req.url ~ “\.(jpg|png|gif|css)$”) {
unset req.http.cookie;
unset req.http.authenticate;
set req.backend = static_backend;
}
if(req.url == “hotstory.hmtl”) {
set.url = “hotstory.html”);
}
}

Understanding Why Varnish Cache Language Is Epic

  • Compiled to binary/shlib via C-code
    • Runs full speed
  • You can have multiple VCL’s loaded at the same time
    • Switch between them without restart
    • Instantaneous
  • Allows you to do anything you might fancy
    • Inline-C code, ’nuff said.
    • Modules/shlib will make it easier (3.0 feature)

Wikia has broken the 4000+ lines of VCL code and is available online via SVN for all to study.

An example of how Wikia’s VCL code utilizing multiple varnish servers. In this example there are two Varnish servers, one in Germany and one in England. The client is located in Germany attempted to access a server in the US. The client hits the Germany varnish server first, but the German Varnish server tells the client to connect to England Varnish than to the US because England’s pipe to the United States is bigger. This speeds up the load times since Germany’s direct tube to the US is clogged. You can’t just dump stuff on it, it’s a truck.

sub vcl_recv {
if (client.ip == “varnish1”) {
set req.backend = usa;
} else {
set req.backend = england;
}
}

Managing Varnish

Varnish is a daemon process on your computer and utilizing Command Line Interface for real-time control. The Management/Working process split. The manager allows (re)start the worker proc. Allows privilege separation. It also contains multithreading to worker process.

varnish_architecture_shah_anand

Image Source: shah-anand.com (thx bro).

Looking over the Varnish architecture we have one binary program that contains two processes, the Managing Process and Cacher process. The managing process will take your VCL code, send it to the C-compiler, and off to shared object for the Cacher process loads. Varnish Cache also has a cluster control concept that can control 10 different instances of Varnish is separate geolocations. The cluster control is still a concept and is not built out.

One thing to note: Varnish does not write .lock files – it has a shared memory segment, it places lock information and statistics in there and other applications will pull from the shared memory.

Brief CLI Management

Example of CLI Management below (I am a bit lost on this because on param.show I get an error on my instance.

$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’
param.show
200 675
default_ttl 120 [seconds]
thread_pools 5 [pools]
thread_pool_max 1500 [threads]
thread_pool_min 1 [threads]
thread_pool_timeout 120 [seconds]
overflow_max 100 [%]
http_workspace 8192 [bytes]
sess_timeout 5 [seconds]
pipe_timeout 60 [seconds]
send_timeout 600 [seconds]
auto_restart on [bool]
[…]

Performance & Speed

Programmed for performance since day one. They wanted to make sure they were aiming for wire speed. Performance is not something you do after the fact, you do it from day one and don’t add things that will bog it down. Writing the code for Varnish aims for today’s complex hardware. This isn’t designed for your dad’s computer anymore!

Use modern features:

  • Virtual Memory
  • sendfile(2), accept_filters(2), kqueue(2)
  • and ever other trick in the book

Performance price list has changed, we can execute 100,000,000+/s per cpu. Disk I/O is behind on response time, stored memory is instead placed in virtual page memory (RAM). Classical logging is horribly expensive. (Examples in slides).

Where does my traffic come from?

Below are a few commands that you can use to access information on a live Varnish instance.

$ varnishtop -i Rxheader
$ varnishtop -i Rxurl
$ varnishhist

Varnishhist is real-time histogram that shows the cache-miss (#) / cache-hit (|) on an x & y axis.
$ varnishstat

Varnishstat pulls real-time statistics from shared memory

Content Management Features

  • Instant action purges/bans (regex or exact match)
  • TTL/Caching policy control in VCL
  • Load/Situation mitigation in VCL
  • Header washing
  • Vary
  • Edge-side-includes (ESI)

27:14

Read More