Testing a website from server before DNS switch

If we come across a scenario where we are migrating a high traffic site from a third party hosting provider like hostgator or godaddy to a IaaS host, we will come across a situation where we want to test if the site that we setup on the IaaS server is ready for us to do a DNS switch.

To accomplish that testing we can use ssh to the IaaS server and once all is setup we can test it using the curl command as below:

curl --verbose --header 'Host: www.mywebsite.com' https://ipaddress:port -k

–verbose will give you a detailed overview of the command

–header ‘Host: ‘ will allow us to tell apache2 which domain name are we trying to test.

Then we provide the https://[current ip]:[port] to tell curl that we want to check the response for the above domain name on this ip address and port.

-k will allow curl to ignore any SSL certificate issues if you havent finished transferring the SSL certificates to the server yet.

Apache2 Alias directive in different virtual hosts files

Situation: 

I have two Drupal / PHP websites / applications

https://qa.example.com/app1

https://qa.example.com/app2

I wanted to setup Apache2 to listen for SSL connection on port 9443 and need to have 2 seperate virtual host files or site files under “sites-available” folder in Apache2.

I created something like this for each

<IfModule mod_ssl.c>
<VirtualHost *:9443>
ServerName qa.example.com
ServerAdmin [email protected]

Alias /app1 /var/www/html/qa/app1
DocumentRoot “/var/www/html/qa/app1

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/app1-ssl-qa-error.log
CustomLog ${APACHE_LOG_DIR}/app1-ssl-qa-access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on

# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/example.pem
SSLCertificateKeyFile /etc/ssl/private/example.key

<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
# <Directory /usr/lib/cgi-bin>
<Directory “/var/www/html/qa/app1”>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

</VirtualHost>
</IfModule>

The issue: 

I need Apache to load App1 when app1 url is accessed and app2 when app2 url is accessed. But when setting up the two apps with seperate virtual host files like above, accessing the apps using either urls only loaded the first virtual host listed in Apache.

The Fix:

I had to merge the two aliases to one virtual hosts file like below to make it work how I want.

 

<IfModule mod_ssl.c>
<VirtualHost *:9443>
ServerName qa.example.com
ServerAdmin [email protected]

Alias /app1 /var/www/html/qa/app1
DocumentRoot “/var/www/html/qa/app1

Alias /app2 /var/www/html/qa/app2
DocumentRoot “/var/www/html/qa/app2

# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/app1-ssl-qa-error.log
CustomLog ${APACHE_LOG_DIR}/app1-ssl-qa-access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf

# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on

# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/example.pem
SSLCertificateKeyFile /etc/ssl/private/example.key

<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
# <Directory /usr/lib/cgi-bin>
<Directory “/var/www/html/qa/app1“>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

<Directory “/var/www/html/qa/app2“>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>

</VirtualHost>
</IfModule>

 

This way the problem is that we cannot disable one app and keep the other enabled. If anyone knows a solution for this please let me know.

Open link in different chrome profile window

Google chrome has this new feature to open links between chrome people which I think is cool.

Screenshot of new feature of chrome
Screenshot of new feature of chrome

Google’s Chrome Browser has this cool feature, which a lot of people do not know, where you can maintain different profiles with different set of bookmarks, themes, history and all other chrome features. You can either use your different gmail addresses to create the profiles or you can use it without associating with a gmail account.

If you are familiar with this “add person” / “manage people” feature on the Chrome browser , you will appreciate the “Open link as [person]” context menu item that seems to have been implemented recently. This is very helpful when you want to keep specific type of content on specific profile on chrome.

For example, If you have a profile [chrome person] for all your personal accounts like facebook and another profile [chrome person] for work, you would some times want to share a link from your work profile on the personal profile. So instead of going through the process of opening another browser on the other profile and then copying pasting the link from one profile browser to another you can just open in another profile using this link.

This was a new discovery for me today and will be using it a lot now on. If you are not familiar with the “add person” profile feature on chrome you should start using it soon! It helps you keep work and personal stuff seperate.

PHP 7.0 and Drupal 7 on Ubuntu 16.04 Xenial

Ubuntu 16.04 doesn’t natively let you install PHP5.6. It only lets you install PHP 7.0. It is a long process to install PHP 5.6 if your server is not allowed to connect to the internet.

Drupal 7, as of Drupal 7.44, (approximately July 2016) supports and works with PHP 7.0 .So you may install PHP 7.0 on Ubuntu 16.04 for Drupal 7 sites instead of jumping through the hoops to get PHP5.6 installed on the server.

 

Reference: Ubuntu Drupal 7 package 

Ruby on Rails Environment Setup on Windows 10

Windows with Ruby on Rails installed on Ubuntu Virtual Box

I am new to Ruby on Rails and I was asked to setup my Ruby on Rails local environment for work without any help from anyone. I spent a couple of weeks trying to install it on windows only to realize that there were too many gem unavailability issues in windows for the setup of the ruby application.

I tried the following before I ended up working almost completely from within a Linux Virtual Box Client.

  • Windows + Ruby + Source Code:
    • Install Ruby on Rails using the Rails installer and / or Ruby installer on Windows 10 with existing source code and gem bundles.
    • This failed because there were too many gems that were needed by the application that we were not available on windows version of Ruby.
  • Windows + (Linux Virtual Box + Ruby) + Source Code:
    • Install Ubuntu on Virtual Box. And Setup Ruby in Ubuntu while having the IDE and Source Code on Windows with the source code folder shared into the Virtual box using Guest Additions for running the WEBrick server and gem installations.
    • This failed because when doing the bundle install command from Linux Virtual Box on the shared windows source code folder failed due to permission issues.
  • Windows + (Linux Virtual Box + Ruby + Source Code):
    • Install Ubuntu on Virtual Box. And Setup your IDE, Ruby, and source code in Ubuntu. SSH into Virtual Box and access your application from your Windows Host using a host only virtual box network adapter.
    • This works for me because of the seamless mode in virtual box guest additions.
  • Ubuntu:
    • Install Ubuntu as a second OS with dual boot setup. And setup your IDE, Ruby, and source code in Ubuntu.
    • This works but doesn’t give the same comfort level or speed of development as Windows (to me).

So I am using the Windows + (Linux Virtual Box + Ruby + Source Code) setup for working with Ruby on Rails development now. I access the web application via browser on Windows and do all development on the Ubuntu virtual box using seamless mode.

Git Prune for Cleanup

When you or a team member removes a few branch from your remote git repository as part of cleanup and you still see the branches on your local environment you will have to run the git command below to remove (prune) all the branches from your local that do not exist on the remote repository anymore.

git fetch -p