Currently displaying posts in category Development...
Phusion Passenger on cPanel/WHM
Phusion Passenger is an excellent resource which makes deploying your Ruby or Rails app extremely easy. It has suport for both Apache and Nginx. There are plenty of guides online for installation, however we came across a scenario where we needed to deploy an app to an apache2 environment with WHM/cPanel installed.
First you must install the passenger gem:
gem install passenger
Then you need to run the passenger installer. Assuming it runs without errors, it will give you 2 pieces of code to put in various places, which is what I'm going to talk about in this tutorial.
passenger-install-apache2-module
The first block of code that the installer will tell you to put is the following into your apache configuration file:
# Load Passenger LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.11 PassengerRuby /usr/local/bin/ruby
Note: Your version may be different than what is above. I'd recommend you copy and paste it directly from the output of the installer.
While you could put it into your httpd.conf, you will lose these changes when an update takes place, thanks to cPanel. So, instead of placing this in httpd.conf, place the above 3 lines of code into /usr/local/apache/conf/includes/pre_main_global.conf
The second part of the installer is going to tell you to input the following code into your apache config file
<VirtualHost *:80>
ServerName www.domain.org
DocumentRoot /home/username/path-to-app/public
<Directory /home/username/path-to-app/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
If you look in httpd.conf, you will see all the virtual host blocks that are in there. Find the one for your domain, and you will see the following:
# To customize this VirtualHost use an include file at the following location # "/usr/local/apache/conf/userdata/std/2/username/domain.org/*.conf"
So instead of modifying httpd.conf directly, we need to create a config file, tell apache to check for includes, automatically update httpd.conf, distill, then restart. Instead of using vi, you can also use vim, pico or the editor of your choice. The filename doesn't matter, I used extra.conf here.
mkdir -p /usr/local/apache/conf/userdata/std/2/username/domain.org/ vi /usr/local/apache/conf/userdata/std/2/username/domain.org/extra.conf
Then put the following into this file:
DocumentRoot /home/username/path-to-app/public
<Directory /home/username/path-to-app/public>
Allow from all
Options -MultiViews
</Directory>
Next run the following:
/scripts/ensure_vhost_includes --user=username /usr/local/cpanel/bin/apache_conf_distiller --update /usr/local/cpanel/bin/build_apache_conf /etc/init.d/httpd restart
That's it! You should now visit your url and see the Passenger screen if there are any errors, or you'll see your app live if you've set it up correctly!
View CommentsThrottling Bandwidth in OS X
When you've got a low latency 20 megabit connection that load pages in an instant, it's impossible to see how our unfortunate internet brethren may see your page load. This particular set of commands that throttle bandwidth proved extremely useful to me when getting certain javascript functions to work before the page was fully loaded. "ipfw" is shipped with OS X and is probably present in some linux distros.
sudo ipfw pipe 1 config bw 40KByte/s
This creates a pipe that only allows up to 40KB/s to go through. If you want to simulate dial-up, set it to 5KByte/s!
sudo ipfw add 1 pipe 1 src-port 80
This will attach that pipe on port 80, effectively throttling its bandwidth.
sudo ipfw delete 1
When you're all done you'll want to remove the bandwidth restriction, unless you're old and miss the days of having slow internet, revelling in anticipation as jpegs slowly load.
There you have it! No need to download extra software to throttle your bandwidth.
View CommentsSearch Within Files
Are you ever modifying a theme or plugin, and you want to find one simple element inside someone else’s code, but can’t be bothered sifting through hundreds if not trillions of files doing "find" to search for that one little bit of text? This command will solve that problem - It allows you to search within files on your server, as opposed to searching just the filenames which is the default on most FTP programs.
Say are modifying a Wordpress gallery plugin to display a caption underneath where it's outputting a title. After using Firebug to find that the title is called "portfolio_title," you look through a few obvious files in the plugin folder and can't seem to find where it's located.
First you need to SSH into your server as root via something like Terminal for OS X, or PuTTY for Windows. Replace the example IP below with your actual server IP. Use domaintools.com to find the IP of your server if you don't already know it.
ssh root@208.28.14.187
After you enter your password, you need to run the following command. When you enter your password, you likely won't see the cursor moving, this is normal. Replace the * wildcard below with the name of the cPanel account. Also replace xyz with whatever folder you are searching in.
find /home/*/public_html/xyz/ -exec grep -l "portfolio_title" {} \; | xargs grep "portfolio_title"
Alternatively, you can just leave the * in the command and have it search through all accounts.
View Comments

