Optimizing Drupal sites on shared hosting: A Case Study
The first web hosting I signed up for was ANHosting's "All Inclusive Mega Package" shared hosting. Going with an $8/per month plan made a lot of sense while I was learning to build web sites. I chose ANHosting after finding it recommended for Drupal sites on John Forsythe's blog. Over my first year building web sites I have built many sites on that hosting (and many others including some similar hosts, Pair Networks hosting, and a VPS I rent from vps.net).
Recently I learned how to optimize my sites on the shared host by using a custom
So the first part of this tip, is to investigate whether you are actually are allowed any
If you are still reading, log into your shared hosting with a command-line like (ignore the line number "1."):
- ssh -l username mydomain.com
Enter your password when asked. At this point, you should be presented with some sort of UNIX prompt. Even if you have this much access, you probably do not have the permissions needed to use the very handy command-line tool
The task now, is to locate the
- php -i | less
The "
What you are looking for is a line in the output like this:
Loaded Configuration File => /usr/local/lib/php.ini
[Note: Experienced UNIX users will immediately see many precise ways to search for such a line (e.g. with the command
Now all one has to do is to transfer that file to the root of one's Drupal install (where my host, at least, will use it in place of the default one. Then you can modify whatever you need to to make Drupal run smoothly.
To transfer it there, try returning to you local machine's command line with:
- exit
and then use the command:
- sftp username@mydomain.com
to start the secure version of the ftp command.
At the
get /usr/local/lib/php.ini
cd public_html/drupal
put php.ini
The last task is to modify the file you have copied into the root of the Drupal install the way you need. I use CPanel's "File Manager" and its "Edit" button to do this. The lines I change look like the following:
upload_max_filesize = 10M
post_max_size = 20M
That gets my Drupal sites on my shared host humming along. The beauty of this process is that you can modify any of PHP's starting configuration and keep all the good things that your hosting already had set up for you in the default

Comments
PHP Configuration of Drush on a Shared Web Host
Download and extract Drush (http://drupal.org/project/drush) to a place under your user home directory.
Example: /home/user1/bin/drush
Prepare a php.ini for use with Drush based on the guidelines given above and place it in your Drush directory.
Edit .bash_profile in the user home directory by adding an alias for Drush.
Example:
alias drush='php -c /home/user1/bin/drush/php.ini /home/user1/bin/drush/drush.php'
Start or restart a bash session.
Perform the 'drush status' command and you will see /home/user1/bin/drush/php.ini under the Drush PHP configuration.
See the Drush project page for more information on the usage and configuration of Drush.
Drush now works for me on my shared host!
Gisele Benjamin's tip above, worked for me on my shared host. Now I can use drush there -- which REALLY improves my life. Thank you, Gisele, for contributing that tip here. If anybody else has state-of-the-art tips for shared hosting, please share here, too!
I'm given a jailshell which doesn't run .bashrc, so I have to do
when I log in to make the drush alias, but then drush works and I used it to add the External Links module to a site with
I am thrilled.
UPDATE June 2, 2010
Well, I spoke a little too soon. Drush is not really useful on my particular shared host because of various security restrictions and practices. YMMV (Your Mileage May Vary), and I hope it does!