Web Development Cheatsheet

Webdev Cheatsheet

Check the Apache Log for Errors

sudo tail -f /var/log/apache2/error.log 

Common Unix Commands

Change the permissions on a file with chmod

Allow all users write permissions to the file settings.php

sudo chmod a+w settings.php

Allow only owner (user) of file write permissions to file

sudo chmod a-w settings.php
sudo chmod u+w settings.php 

Change Owner of File

chown <username> <filename>

sudo chown moe secret-codes.txt.pgp

See what user you are logged in as

$ whoami

Search for a File on the Server

for example seach all of the files on server for a file named, "httpd.conf"

sudo find / -name httpd.conf -print

use Grep to search all files in current directory for pattern

grep 'VirtualHost' *

History Shows Your Command History


search history for a specific command you ran with grep

history | grep mysqldump

download and uncompress a file

sudo wget http

edit cron

crontab -e


  • pushd <directory>

    this adds a directory to the stack and cd's into that directory
  • dir -v

    this lists the directory stack
    $ dirs -v
     0  /var/www/knitsy/drupal-7.7
     1  /etc/apache2/sites-available
     2  ~/public_html/mu
     3  ~
     4  /var/www/theprecarious/drupal-7.7
  • cd ~2

    this cds into the 3rd directory on the stack

Block an IP Address with iptables

iptables -A INPUT -s -j DROP

Apache Configuration

Add a new VirtualHost to the Apache Config file

sudo vi /etc/apache2/sites-available/default

A simple VirtualHost entry

<VirtualHost *:80>  
  ServerName majorursa.net
  ServerAlias www.majorursa.net
  DocumentRoot /var/www/majorursalia/

A VirtualHost for a Drupal Site

<VirtualHost *:80>  
  ServerName majorursa.net
  ServerAlias www.majorursa.net
  DocumentRoot /var/www/majorursalia/drupal-6.22
  <Directory /var/www/majorursalia/drupal-6.22/>
    AllowOverride All
    Options None
    Order allow,deny
    Allow from all

Gracefully Restart Apache webserver

sudo apache2ctl graceful


Sign in to Mysql

mysql -uroot -p 

Create a new Database

In this case a database called derailer.

create database derailer

Create a New User and Grant Privileges on derailer Database

create user 'moe'@'localhost' identified by 'tuff-!@#?ing-passwword';
GRANT ALL PRIVILEGES ON derailer.* to 'moe'@'localhost' identified by 'tuff-!@#?ing-passwword';
flush privileges;

Back Up a Mysql Database

The following commands runs mysqldump as user "moe" and backs up "derailer" db to file derailer-backup.sql

mysqldump -umoe -p derailer > derailer-backup.sql
  • Should have a script that does this at least once a week, and is launched via cron

Restore a Mysql Database from a Backup

This command will restore database from backup made in previous section.

mysql -umoe -p derailer < derailer-backup.sql


At a shady cafe with a public wifi that you don't trust? Need to surf
the web anyway? Set up an SSH tunnel and be at ease.

Create an ssh tunnel

ssh -2qTnN -D 8080 boris@vladivostok.edu

(change boris@vladivostok.edu to your username on a remote computer.)

Use Foxy Proxy in Firefox or Proxy Switchy in Chrome to surf securely

SOCKS Host:, Port: 8080, Socks v5 [X]

or Enter Proxy Manually in Firefox

Edit > Preferences > Advanced > Connections > Settings > Manual Proxy

SOCKS Host: Port: 8080 Socks v_5 [x]


A DNS entry

<subdomain-name> <time to cache> <protocol: "in"=internet> <"a" record points at IP address> <ip-address>

courtwatch 10800 IN A

Check DNS entry exists or is up

> host -a majorursa.net

the A record is the IP address for the domain
the NS records are the Name Servers for the domain
the MX records are the mail server for the domain

Bash aliases

  • this is .bashrc on linux
  • .bash_profile on Mac OSX

add an alias to ssh to server

alias dtech 'ssh moe@denvertech.org'

add alias on server to get to drupal directory

alias mu 'cd /var/www/majorursalia/drupal-6.22/'

Debian System Administration

Install Apache Webserver, PHP and MYSQL on Debian Server

This is nice and simple thanks to Debian's brilliant package management system apt-get.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 apache2-doc apache2-utils
sudo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache
sudo apt-get install php5-suhosin
sudo apt-get install php5-mysql
sudo apt-get install mysql-server libmysqlclient16 libmysqlclient-dev mysql-client mysql-common

Browser Plugins


  • Firebug plugin
    • hit F12 to pull up interface


  • Developer Tools
    • hit F12 to pull up and dismiss interface (or S-C-i)
    • right click on element and select inspect element from menu
  • Manipulate CSS on the Fly
    • Double click in the CSS pane of elements menu to change CSS property.
    • Tab completion: hit tab for tab completion
    • To add a new element to css, click on gear menu at top of CSS menu.
    • Developer Tools keeps track of revisions, any css file with an arrow
      by it, has a revision history of your changes
      • To see revision, click the Resources tab, any css files listed
        with arrow next to name, have revision history.
        • If you click on a file name, the css file will be displayed and
          any changes from original will be highlighted.
      • Right click on it, and select "Save as.." to save a revision of
        the css file.
      • Drag and drop the revision into most editors.
      • You can right click on a revision to revert to that version of the
        CSS history.
  • Command Line API
    • dir()
    • inspect()
    • $0
    • copy()



Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.