Aug 21

How many user accounts are there on your hosting server? You can look up the number of server user accounts by the following command via SSH:

wc -l /etc/passwd

And it may output something like this:

76 /etc/passwd

Which means there are a total of 76 active users in the system. However, the actual number of human users of the server should be lower than the amount because there are system users created to carry out certain tasks.

Multiply the amount by 5 and you may get a rough number of websites hosted on your server.

Aug 02

wget command should be available in most hosting companies who offer SSH access to your hosting account. It is usually used to download stuff from the remote server, for example, to download something:

wget http://www.google.com/money.zip

However, there’s yet another hidden trick of wget that could enable you to make a mirror backup of any website – well, not actually any website but wget feels more comfortable with certain sites. WordPress blogs are perfect candidates for wget to mirror. Mirroring a WordPress blog can be done by a very simple switch of the wget command through SSH:

wget -mk http://www.example.com

All the documents relationships and HTML links will be taken care of so that local browsing of the mirrored copy will be completely no problem.

Jun 21

The default php configuration comes with a hard cap of 2MB on the size of uploaded file determined by the php.ini directive upload_max_filesize in conjunction with post_max_size. The maximum uploading size of a file is the lower. Therefore, to increase the uploading cap and raise uploading limit, you will need to edit those 2 directives in php.ini.

The location of php.ini varies distribution by distribution, in this example, with Ubuntu 9.04 Jaunty, php.ini is located at /etc/php5/apache2/php.ini, so

sudo vi /etc/php5/apache2/php.ini

Press / to find upload_max_filesize and change it to, say 8M:

upload_max_filesize = 8M

Press ESC, :, wq and Enter. Now the php.ini is saved with the new uploading file limit. Reload apache2 to read the new configurations:

sudo /etc/init.d/apache2 reload

Now you should be able to upload any file up to 8MB in size, in case you need larger uploading limit, in addition to change upload_max_filesize to, say, 16M, you must also edit post_max_size to more than or equaling to 16M because file uploads are processed through HTTP POST method.

Jun 16

mod_rewrite is universally acknowledged as one of the best modules of Apache, simple yet powerful. It’s one of the top reasons why Apache is the best web server. These are some books found at Amazon on Apache mod_rewrite and how to use it in .htaccess directives.

Web Developers / Designers’ Books:

  1. Best HTML Books
  2. Best CSS Books
  3. Best JavaScript Books
  4. Best PHP Books
  5. Best MySQL Books
  6. Best Linux Books
  7. Best Apache Books (mod_rewrite Books)
  8. Best Web Hosting Books

The Definitive Guide to Apache mod_rewrite

The Definitive Guide to Apache mod_rewrite

Jun 06

To trace and know where a website is hosted physically (server location), you will first get its IP address and then query it for the geo location. Many online tools and IP databases offer such free services such as IP to Location. It not only converts the IP to a physical location but also tries to give the institution (companies, data centers, national organizations, etc.) that’s responsible for the IP address based on IP ranges distribution table with an option to map the IP geographically.

Oh wait, I think I forget about how to get the IP address of a website. All after all, you can ping the domain name to get the IP address of the site from command line. Or, you can use domain IP lookup tools such as this one. It not only gives you the IP address of the particular domain URL but also pokes the server around and guesses what other sites are possibly being hosted on that IP.

Actually, there’s a much simpler one to consult when you need to know the physical location of a site and where the website is hosted: Domain Tools. By querying a domain, it gives you the IP where the domain / site is currently hosted and also the organization or data center (might be a hosting company) that’s administering the IP. Very good tool to know where a site or domain is hosted.

May 30

This kind of redundancy is encouraged to protect potential loss of important data, such as essential website programs and databases.

After installing rsync on all peer hosting servers you own, you can easily backup stuff and synchronize them among the servers for a safe data redundancy.

rsync -e 'ssh -p 25000' -avl --delete --stats --progress user1@123.45.67.890:/home/user1 /backup

This simple command will take care of everything for you, the rsync command connects to the remote server 123.45.67.890 as user1 and backups or synchronizes everything in /home/user1 from the remote server to the local directory /backup. The –delete switch indicates that files that previously existed at /home/user1 on the remote server but not now will be also deleted in /backup at the local server.

‘ssh -p 25000′ prescribes rsync to connect via SSH on port 25000.

May 30

The default colors for comments (texts in /* */ or following // or #, …) in vi code highlighting are a little too dark. Ever wanted to make it more recognizable in SSH console?

Find and edit /etc/vim/vimrc with vi:

vi /etc/vim/vimrc

And add in this line:

colorscheme desert

Wherein desert is one of the available color schemes vim comes with. Now we will need to edit the actual color scheme file and change the highlighting colors:

/usr/share/vim/vimcurrent/colors/desert.vim

Change:

hi Comment ctermfg=darkcyan

To:

hi Comment ctermfg=blue

Save the change and exit. Run:

source /etc/vim/vimrc

And the changes will now take effect.

The default directory color of ls –color is also too dark, you can learn how to change the default directory color of ls –color.

May 30

After you have enabled the color switch of ls command in shell console, it’s nice but some may complain that the deep blue color of the directories are too dark to recognize sometimes. Let’s change that.

Just open up the .profile or .bash_profile file under your home directory and put this line in it:

export LS_COLORS='di=01;34'

Done! Now the color of the ls directory listings is much lighter and easier to recognize. There’s also a tip of how to change the default dark color for comments in vi text editor.

May 30

Add the following snippet in the .profile or .bash_profile under your home directory:

export PS1='[\[\e[1;31m\]\u\[\e[0m\] - \[\e[32m\]\w\[\e[0m\]]$ '
export LS_COLORS='di=01;34'
alias ls='ls --color -l'

If you are ‘supergirl’, your Linux home directory would be located at: /home/supergirl, and the file you should add the above lines to is: /home/supergirl/.profile or /home/supergirl/.bash_profile.

What is LS_COLORS doing here?

May 30

Below are a few general commands found in most popular Linux distros which you can use via SSH to check the status of your hosting server.

To show used and available RAM memory and swap space usage:

free -m

To show current disk storage usage by mounted device:

df

To show disk usage statistics of the current directory by directories and files:

du

To show the hard disk space a directory or a file takes up:

du filename

To show the length of time this server has been up and the server loads in the past 1 minute, 5 minutes and 15 minutes:

uptime

To display a real-time updated server resource usage including: server uptime, user logged on, load average, current tasks, CPU usage, memory usage and swap usage:

top

To display a list of real-time active or sleeping processes your server is up to:

ps

To show some information about the current status of virtual memory, CPU usage, I/O usage:

vmstat

This is also a good tool to find out system performance bottlenecks.

To display currently logged on users on the system:

w

Or

who

To print a full screen text graph of the server load refreshed every few seconds:

tload

If you are on shared hosting, chances are your server usage has been imposed some hard limits such as the largest amount of files / directories possible and the hard storage limit. View them by:

quota

May 25

256MB being the startup plan from most VPS providers will be no better than a shared hosting plan from affordable hosting providers. 384MB may seem to be a 128MB extra but actually just slightly more.

As a result of the nature of VPS, an entire operating system (such as Linux distributions: Ubuntu, Debian or Centos, and so forth) resides in it with a complete web server package: Apache, PHP, MySQL and potentially a lot of necessary modules and extensions, making the mere hosting slice of 256MB a frugal choice to cover all the overheads, much like the sunk cost in Economics. It is after the threshold of 256MB that every additional MB of RAM you purchase will be consumed by your own websites rather than by the system. Well, not precisely all of 256MB will be used for the system, but you are left with like 50MB – 100MB from the whole 256MB pie after installing everything WWW and getting your slice ready for websites.

So if you are going to switch to a VPS, make sure you board on at least 512MB memeory for a start or it won’t be worth the while and it may just be good enough to spread your sites across various shared hosting plans (preferrably from various distant hosting comapnies) for some SEO advantage.

Apr 13

Take on a trial which DreamHost offers or ask a friend at some hosting company to do some tests on SSH:

  1. Check for the number of server processors or CPUs
  2. Check for the average load the server is experiencing

Get the 3 load average figures divided by the number of CPU they have on the server, add them up and further divide them by 3. With the final result:

  • result <= 1 ( definitely an honest and great host)
  • 1 < result <= 2 (good one, but questionable)
  • 2 < result <= 5 (overselling, overselling, overselling, …)
  • result > 5 (are you crazy?!)

Apr 13

Some of the hosting providers out there are infamous for overselling who try their best to stuff in as many users (websites) as possible into a single web hosting server. High server load is an indicator of how your server is performing and whether it is laboring too much thus jeopardizing the performance of your websites. You can get to know the average load in the last 15 minutes of your server by the simple Linux command below (via SSH):

uptime

Which will typically return a line of data similar to this:

21:39:33 up 10:45, 3 users, load average: 4.46, 3.92, 3.64

That says there are currently 3 users logged on and the load average of this server in the last minute, last 5 minutes and last 15 minutes are 4.46, 3.92 and 3.64. These figures represent the number of runnable processes at the same time on average for the CPUs (processor) to process. Combined with number of processors of the server, you may know how many processes are being processed by any single CPU.

Considering the fact that any CPU can only take on one process at any given time, there will possibly be processes waiting in the queue – meaning server is overloaded. Therefore, if the number of processors of your hosting server is 4, in the last minute, it is overloaded by ( 4.46 / 4 ) – 100% = 11.5%.

Apr 13

One of the first things that may concern you is that whether your web hosting company has equipped enough CPUs or Processors on your server as they have allegedly done. Or you are on shared plans and are simply curious whether your web hosting provider is overselling by overloading your server a lot.

First make sure you have SSH access to your hosting server which majority of hosting businesses are now providing. Then create an SSH account and log it in to the server.

A rather simple linux bash command will help you determine how many CPUs your host has on your server:

cat /proc/cpuinfo | grep processor | wc -l

This combination of pipeline command extracts server processors information from /proc/cpuinfo that contains CPU details each per line, returning a plain number which will usually be 1, 2, 4 or even more.

There you go. Now find out whether your host is cheating on you with this tip in addition to checking your server load! ;)

Extra Tips

You can find plenty of other useful and interesting information about your hosting server and OS release at /proc. For example, for some RAM stats:

cat /proc/meminfo

For total seconds since the last reboot:

cat /proc/uptime

For Linux release and versions:

cat /proc/version

And much more. Just ‘ls /proc’ and try for yourself.

Apr 02

As SSH is inherently tunnel-enabled for setting up socks5 proxy servers, you can instantly turn your personal computer into a socks5 proxy server by the help of PuTTY through your web hosting server, breaking through firewalls. The idea is to direct all traffic from your local computer browser through PuTTY SSH session to the web hosting server and back from it.

Here we go:

  1. First, make sure your web hosting provider provides SSH access to your hosting server. DreamHost (use coupon CASH60 for $60 discount) as well as a lot of other hosting companies do.
  2. Second, download PuTTY, run it, and set up the SSH account by entering your hosting server address in Host Name (or IP address).
  3. Add SSH tunnels by:
    Connection -> SSH -> Tunnels ->  give it a random Source port (in this example, ’8844′), enter Desctination as ‘localhost’ and select Dynamic and Auto, and click Add. Now there should be an item of ‘D8844′ in the Forwarded ports list.
    putty tunnels proxy to set up socks 5 proxy server through web hosting server
  4. You may want to switch back to Session to save the session for easy access so that a simple double click would trigger the connection based on all the configurations you have done so far.
  5. Double click the saved session and log into your SSH account. Now you are in your web hosting server.

Leave the SSH session open and your personal computer has now become a socks5 proxy server. Open your favorite browser, for example, FF3:

  1. Tools -> Options -> Advanced -> Network -> Settings -> Manual proxy configuration -> SOCKS Host: localhost, Port: 8844 -> OK
    firefox-browser-proxy-settings
  2. You are now set. Fire up a tab and surf through the socks5 proxy on your local computer.

Remember though, that all traffic you use by browsing the web pages and downloading whatever stuff by the local proxy goes through your web hosting server and will be counted on the hosting bills.

Exciting! Now you’ve got your very own proxy server (socks5 server is the most versatile among all types of proxy servers including HTTP proxy and FTP proxy) that’s local, stable and in your perfect control for getting around all kinds of firewalls. Screw all those obsolete online proxy server lists with unusable proxy servers!