Linux Cheat Sheet for Web Developers

Checking Disk Space

Use either command:

  •  df
  •  du –max-depth=1 | sort -n -r

DNS

  • cd /var/lib/named is where you should find the DNS entries for the web server.
  • Restarting /etc/init.d/named restart

Check Log Messages on the Mail Server

  • Use the command:
    tail -f  /var/log/messages

Show Deleted Files

  • Use the command:
    ls -ld /proc/*/fd/* 2>&1 | fgrep ‘(deleted)’

Checking Memory

Use either command:

  • free -m (in MBs)
  • cat /proc/meminfo

Checking Directory Size

  • du -c
  • du -h gives the size better
  • du -h -S | sort -n -r (no sub folders)

Tip:   check /var/lib/psa/dumps directory if you are using Plesk. That Plesk dumps aren’t filling up the drive

Checking Processes

Use either command:

  • ps aux
  • top

Restart Apache / MySql

Tip: If you have change the Apache configuration it’s always best to use the command
/etc/init.d/apache2 configtest to check before restart for any mistakes or typos.

  • /etc/init.d/apache2 restart
  • /etc/init.d/mysql restart

Finding Files

  • find / -name somefilename…

Restarting Plesk

  • /etc/init.d/psa start   Tip: a good way to see what is slow to start up.

Renaming a batch of Files to another file extension

  • for i in *.html; do mv “$i” “${i/.htm}”.html; done

Shutdown and Scan disk

  • shutdown -Fr now

List User / Groups

  • /etc/passwd
  • /etc/group

Add User to Group

  • gpasswd -a USERNAME groupname

Delete User

  • userdel username

Turning On and Off Safe Mode in PHP

  • Edit the Conf/httpd.include for the line php_admin_flag Safe_mode off

Installing Pear so you can send mail via GMAIL

-wget http://pear.php.net/go-pear.phar
php go-pear.phar
pear install Mail

Check if PHP is using Pear
php -c /path/to/php.ini -r ‘echo get_include_path().”\n”;’

Checking PHP
php –ini

Editing the PHP.INI
vi /etc/php5/cli/php.ini
vi /etc/php5/apache2/php.ini

Make sure the variable is set…
include_path = “.:/usr/share/pear”

Installing a Perl Module

  • perl -MCPAN -e ‘install Time::Piece’
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *