How to Generate SSH/SSL Public and Private Keys

By: Kevin | December 6, 2016

SSH

  1. ssh-keygen -t rsa -b 2048 -f keyName
    Tap enter twice to skip the passphrase, or enter one if you like.
    This will output keyName and keyName.pub

SSL with self-signed Certificate Authority (CA)

  1. Create CA key without passphrase openssl genrsa -out rootCA.key 2048 add -des3 if you want a passphrase
  2. Self sign the CA, openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem. Now you have a self signed SSL named rootCA.pem

 

Use the CA just created to sign other SSL certificates.
  1. Create a private key, openssl genrsa -out device.key 2048
  2. Create a certificate signing request (CSR), openssl req -new -key device.key -out device.csr. Its important to note when answering the prompts, Common Name (eg, YOUR name) []: must match the host name of the web server you are using.
  3. Sign the CSR with your CA.openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 500 -sha256
    .

Notes to self about WinRM

By: Kevin | August 22, 2016

Notes to self about WinRM.

On WinRs (client side) box, need to add ‘TrustHost’ to use CLI
winrm set winrm/config/client '@{TrustedHosts="machineA,machineB"}'

Trust all
winrm set winrm/config/client '@{TrustedHosts=“*”}’

List WinRm Listener IP and Port
Winrm enumerate winrm/config/listener
winrm e winrm/config/listener

Enable-PSRemoting
https://technet.microsoft.com/en-us/library/hh849694.aspx

Disable-PSRemoting
https://technet.microsoft.com/en-us/library/hh849690.aspx

 

Check running services

net start

  1. http://www.hurryupandwait.io/blog/understanding-and-troubleshooting-winrm-connection-and-authentication-a-thrill-seekers-guide-to-adventure
  2. https://blogs.technet.microsoft.com/askperf/2010/09/24/an-introduction-to-winrm-basics/
  3. https://msdn.microsoft.com/en-us/library/windows/desktop/aa384470(v=vs.85).aspx

How to enable curl, on Ubuntu LAMP installation

By: Kevin | September 9, 2014

So you installed LAMP but you’re missing the cURL library. I had the same problem. By default cURL is not included with the basic installation of LAMP on Ubuntu Server 14.04. To add the cURL library simply execute this command

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

Once the installation is complete be sure to restart Apache2.

sudo /etc/init.d/apache2 restart

OR

sudo service apache2 restart

Cheers!

How to load php_curl.dll module in Apache – fixing Unable to load dynamic library

By: Kevin | June 9, 2014

While setting up my development environment I ran into a situation where I needed to use the php_curl.dll module to make http requests. However I kept getting the following error message from Apache in the error.log:

 

PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\\PHP\\ext\\php_curl.dll’ – The specified module could not be found.\r\n in Unknown on line 0

 

My Environment:

Windows 7 64-bit

Apache 2.2.2

PHP 5.3.25

 

A Google search revealed that curl is dependent on two other files. Requires: libeay32.dllssleay32.dll (bundled) Source here. OK great, I need those two files, but the documentation doesn’t say anything else. The Bundled only hinted that I already have these files, and I did. So I looked in the root of my installation location of PHP and voila. However, obviously this still wasn’t doing the trick. This is what I did to get php_curl.dll module loaded in Apache.

 

1. Uncomment php_curl.dll in your php.ini file.

2. Copy  libeay32.dll and ssleay32.dll from the root of your PHP folder then paste them into the bin subdirectory in Apache

3. Restart Apache services.

4. Call phpinfo() and make sure cUrl was loaded properly.

Presto! You should be hooked up! Happy cUrling!

How to set time zone in PHP ini file

By: Kevin | June 4, 2014

If you ever use the date() function in php you’ve likely ran into an error message like this:

Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for ‘-5.0/DST’ instead

As the error/warning message suggests you can set

date_default_timezone_set()

at the top of your php script however that gets to be very repetitive and unnecessary. You could also just silence the warning with the @, however again this doesn’t really solve the problem. To get to the heart of the issue you need to edit the php.ini file. Go ahead and open the php.ini with a notepad editor. *NOTE* On Windows you need to first right click and “Run as Administrator” the on the text editor your choice otherwise sometimes it will not let you save. Add the following to  line to the file then restart Apache for the changes to take affect. A full list of time zones can be found at https://php.net/manual/en/timezones.php

 

How to pass PHP array via POST

By: Kevin | May 5, 2014

I was working on a site which had two databases and different domain names. My problem was I needed to pass information from one database (domain) to another. I wasn’t sure the best way to approach this but finally came to this conclusion. So here it is.

//Select your data from the source
$sql = "Select * from orders where Id='$orderid'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);//$row is an array

So now we have our data in $row.

Next we will use the PHP function serialize. This function takes our array and turns it into a string representation of the data, or a bit stream. More on the serialize function here.

This doesn’t quit get us there. By using the serialize function we caused another problem. Our array is now a string with a lot of quotes (“) in it. The quotes don’t mesh well within a form and prevent a large amount from being passed to the other page.

To remove the quotes I use another php function called urlencode. urlencode is a straight forward function, it takes a string and replaces the quotes with html safe characters. More on urlencode here.

<form action="somepage.php" method="post">
//I have nested my calls to urlencode and serialize
//in the value below
<input name="row" value="<?=urlencode(serialize($row))?>" />
<input type="submit" value="Save">
</form>

After this form is submitted, we do the opposite to get our original array back. Be sure to do this in reverse order.

//unserialsize data coming from previous page
$row = unserialize(urldecode($_POST['row']));

Ta-Da! Now you have the original array and the data from the previous database.

How to enable / disable word wrap in Dreamweaver

By: Kevin | May 1, 2014

The longer I work with Dreamweaver the more I find out things it can do. A simple yet annoying thing I came across recently was code that was wrapping. I program in PHP a lot and found that word wrapping makes things look more confusing than it has to. My first thought to turn this feature on or off was to head over to “Preferences” however I found out it is located in a not so obvious place.  Go to View -> Code View Options -> Word Wrap”

How to change Apache settings to get custom WordPress permalinks working

By: Kevin | December 12, 2013

I recently installed WordPress on my site. One of the first things I wanted to do was to change the URL’s from the default mcgilln.com/blog/?cat=1 to a more fun, http://mcgilln.com/blog/2013/12/how-to-get-apache-settings-working-for-wordpress-permalink/, which is better for search engine optimization. When I first went into settings and flipped the switch to use the new permalinks I kept getting a server 404 error! I googled around and found out that you need to have  the following code in the .htaccess file in the root folder of your wordpress install location. Sometimes this is generated automatically and other times you need to manually add it (bug?). Do yourself a favor and just open the .htaccess file and make sure the below code is in it.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

This was step one of my problem.

The second problem was an Apache setting itself. After a few hours I finally realized the above code was trying to use an Apache module called mod_rewrite.c.. Then I remembered in my httpd.config Apache file (the main Apache settings file) there are tons of lines that are commented out. I did a quick CTR+F and found that the module was commented out and therefore wasn’t being imported for use by Apache! I un-commented the import and restarted Apache but it STILL wasn’t working.
#**This allows writing to .htaccess files so blog permalinks work**
LoadModule rewrite_module modules/mod_rewrite.so

The third and final step was to change permission to the directory where WordPress is located (can be in httpd.config or in the .htaccess file). Change/add the below code and make sure AllowOverride is set to ALL

<Directory "C:/path/to/wordpress/root/directory">
AllowOverride All **<--This is key**
Order allow,deny
Allow from all
</Directory>

After making these changes my WordPress permalinks started working! Hopefully this can help some one save time in the future.

How to make your own web server

By: Kevin | December 12, 2013

If you’re a tech nerd like me then you wanna know how everything works, start to finish. This is my attempt to tell you how to create your own server and host it from the comfort of your own home.

When I started researching how to build my website, every Google search pointed me to different companies offering web hosting and site builders like GoDaddy.com or Wix.com. Although these options work for many people, they are almost too easy – you don’t get the full sense how or why things work. So, I changed my search to “how to create your own server”.

Here’s what you’ll need to build your own server to host your own web site.

  1. A solid internet connection
  2. An “always-on” PC (monitor not needed after setup)
  3. Apache server software (free download)
  4. Domain name service provider (DNS), covered more in a minute

Your PC doesn’t need to be top-of-the-line, and in fact, virtually and PC will do. My server is a hand-me-down Dell tower my parents were going to throw out. Ideally, the PC you use will only be used as a server. Reason being, if you want your site accessible 24/7 then it needs to be powered on 24/7. Since I only use my server/tower machine as a server I did a clean wipe of windows before I started – just to have a clean slate.

Head over to http://www.apache.org/dyn/closer.cgi and download the server software. Apache is an open source software that was started back in the 90’s. It has evolved and is used by many servers all over the world. The full history can be found on apache.org, (which I recommend reading to get a full appreciation of Apache).

Apache is the software that turns your computer into a server, an HTTP server to be exact. Simply put, its the software that listens for requests, finds the file that was asked for, and then sends it back to you. If you’re reading this article, it means that my server sent your computer this page (file) when you clicked the link to get to here. Simple, right? This is how the entire internet is in existence. Servers all over the world, connected.

Install the server and follow the typical instructions. One recommendation is to install Apache in a root folder, like C:/Apache. This way it’s easy to find later. Apache also needs to know where to listen for requests, so when your’re going through the installation be sure to specify your computers IP address in “Network Name” and “Server Name”. To find yours (on a Windows machine) go to Start and type “cmd” into the search, then type in “ipconfig”. This will bring up some random information, but what you want to know typically starts with 192.168…. This is the case if you are connected to the internet through a router of some sort.

homemade server

If you are using a router, you’ll need to do something called port forwarding. Picture this, every internet connection has an IP address assigned by your internet service provider (ISP).

Most people these days have multiple devices (wired or not). Your home router uses the IP address provided by your ISP then assigns all devices in your home their own local IP (usually starting with 192.168.). Doing this allows you to use multiple devices with a single IP address from your ISP. This is important to understand for port-forwarding. When you go to a web address, ie. mcgilln.com, what is really happening is you’re getting pointed to an IP address. Domain names are just a human-friendly way to remember numbers. So, typing in mcgilln.com really brings you to the IP address assigned to me by my ISP. Here is where port-forwarding comes in. Think of the IP as a street address of a big apartment complex that you need to deliver a package. You may get GPS directions to 1212 12th Street but that doesn’t help you get to your desgination because there could be 100 apartments at that address. What apartment does it belong to? Apache, by default, listens for requests on port 80. So what you need to do is log into your router and find the tab for port-forwarding. You need to explicitly tell your router what to do when it gets a request on port 80, which is to relay that request somewhere. Thats your servers local IP address (remember that 192.168….. you used earlier). Set your router to forward requests on port 80 to the 192.168…… You usually select something like “allow From port to port”, just put 80 on both. Save the settings in your router and you’re almost set.

Back to Apache. After you have Apache installed, don’t expect much. It’s extremely light weight and little to no user interface. You should see a small feather on the bottom right of your machine. If you have a red square then the server is not running. Double click and then click Start – if its green then you’re good to go. Open a browser and type in your computer IP address(192.168….). If your server is working properly you should get a page that says “It Works!”. Congrats!

Now, your IP address (192.168..) is for your local network, meaning that it will only work if you’re connected at home. So how do you get to your web server from the rest of the world? You need your ISP IP. (Confused yet?). To find this, open a web browser and type “whats my ip?”. A quick Google search will tell you what your public IP address is. Now as a quick test, grab your smartphone and type in “http://” then the public IP address Google just told you. (MAKE SURE YOUR SMARTPHONE IS NOT CONNECTED TO YOUR LOCAL WIFI OR IT WON’T WORK) If all goes well, you should again get the “It Works!” page. Congrats! And just like that, you’re live to the world.

Now that you’re live you’ll want to update your home page to something a little nicer than the “It Works!”. Your public root folder is called “htdocs” and inside is where you installed Apache. Change the files in there to something awesome that you created…and you’re off!

Lastly, you should know a majority of ISP’s use dynamic IP addresses. This means that even though today you may have a public IP of 172.172.172.172, tomorrow , without notice, it could change to 1.1.1.1. This presents a new problem of hosting your own site. If you use a godaddy.com or something similar to buy a domain name and want to point it to your home server, you’ll soon be SOL (when you IP changes and your domain is pointing to the wrong place).

You need a DNS service to handle the changes for you. I use a DNS service called no-ip.com which offers both free and paid services. The free service gives you a domain name to use to reach your server and provide an easy download that will keep your public IP address and domain name synced.

There you have it!

The Making of McGilln.com

By: Kevin | November 22, 2013

Soon I will be putting together a tutorial on my server set up! check back!