This is a quick reference notes I keep just in case I need to re-install and re-configure my FreeBSD server system.

  • Initial FreeBSD installation

    Download OS from the FreeBSD website, etc.
    Use sysinstall to get running the initial desired FreeBSD configuration.
  • Update ports collection from the FreeBSD site:

    - For the first time:
    portsnap fetch
    portsnap extract
    
    - Afterwards, instead of two two above:
    portsnap update
    
  • Install and configure text editor ne:

    cd /usr/ports/editors/ne
    make install clean
    
    Start ne, press F1(menu), chose /Pfers/Save Def Prefs - it creates a file ~/.ne/.default#ap.
    Edit file .default#ap: add line EscapeTime 250, copy file to other users' ~/.ne/ directory.
    From now you can use ne instead of vi editor.
    So use ne to set EDITOR=ne and shell aliases for users (edit ~/.profile files), so ne becomes your default editor on FreeBSD system:
    EDITOR=ne;      export EDITOR
    PAGER=less;     export PAGER
    
    If using PuTTY SSH shell to access the system - set backspace Key to Ctrl-H.
  • Change your shell to bash:

    Simply run the chsh (Change Shell) program, and change the Shell: line:
    Shell: /usr/local/bin/bash
    
  • Beautify/colorize directory listings:

    Add following alias lines or the ~/.profile file:
    alias ls='ls -G'
    alias ll='ls -lG'
    alias la='ls -lGAFo'
    
    This will add colors based on file type when viewing directory listing using commands la, ll and la.
  • Install text-based mail reader mutt:

    I couldn't do it though ports collection using make utility, neither mutt nor mutt-lite.
    Pull and install pre-compiled package from the FreeBSD repository website:
    pkg_add -r mutt-lite
    
    After initial try of the mutt, set its split-window option by editing file /usr/local/etc/Muttrc and adding pager_index_lines=10 there.
  • Configure ntpd Network Time Protocol (NTP) daemon:

    Select public time servers from ntp.org website.
    Create /etc/ntp.conf file and add a list of the few time servers there that is close to you location, for example:
    server 0.north-america.pool.ntp.org
    server 1.north-america.pool.ntp.org
    server 2.north-america.pool.ntp.org
    server 3.north-america.pool.ntp.org
    
    You can also set other systems on your network to use your FreeBSD Server for time synchronization. To make this more secure, add the following line to the /etc/ntp.conf file:
    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    
    (change IPs as required). This will allow access to the ntpd daemon only from the computers on your local subnet.
    Add ntpd daemon to the /etc/rc.conf so it starts starts at boot time:
    ntpd_enable="YES"
    
    Type command ntpd to start daemon manually with default parameters.
  • Install Apache (apache22) port:

    This and few other steps below are described in details in other documentation - I may add some additional details here later.
  • Install MySQL port:

    That is mysql(XX)-server port.
    Afterwards don't forget to change/set MySQL' admin password:
    mysqladmin -u root password XXXXXXX
    
  • Install php5 port:

    cd /usr/ports/lang/php(5?)
    make isntall clean
    
    Ensure Apache is selected in the UI.
    Assign a php.ini file:
    cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
    
    You can see differences between php.ini-dist and php.ini-recommended versions using diff utility:
    diff /usr/local/etc/php.ini-dist /usr/local/etc/php.ini-recommended
    
    Edit php.ini file:
    short_open_tag=On
    upload_max_filesize=6M
    error_log=syslog
    

    To configure Apache for PHP, install additional ports (as required):

    • Install PHP PCRE port:
      cd /usr/ports/devel/php5-pcre
      make isntall
      make clean
      
    • Install PHP5 Mysqli
      dc  /usr/ports/databases/php5-mysqli
      make isntall
      make clean
      
    • install php5-ctype
      cd /usr/ports/textproc/php5-ctype
      make config
      make install
      make clean
      
    • install php5-gd
      cd /usr/ports/graphics/php5-gd
      make install
      make clean
      
      (accept default checkboxes settings)
    • install php5-zlib
      make install
      make clean
      
  • Enable Apache, PHP and MySQL at boot:

    Edit /etc/rc.conf and add the following lines:
    apache22_enable="YES"
    mysql_enable="YES"
    
    To avoid warning when apache starts, also add this line:
    accf_http_load="YES"
    
  • Configure newsyslog.conf to rotate Apache httpd logs:

    Monthly (see man newsyslog.conf for more info):
    add lines to the /etc/newsyslog.conf:
    /var/log/my_log_filename.log       644  10000 *    $M1D0 J
    ...
    
  • Tips for create a backup script on FreeBSD/Linux:

    I needed to create a simple script that periodically makes backup copy of some working directories and files. This can be dine using newsyslog which will rotate log files (0...9), however I would prefer if log filenames have a date in them. Here is how it can be done in the script:
    	#delete archives older than X days:
    find /bkpdir/ -name '*.tbz2' -maxdepth 1 \! \( -newermt '20 days ago' \) -delete
    	# make 'dated' backup:
    tar -cyf /bkpdir/system_bkp_$(date +%Y-%m-%d).tbz2 /bkpdir/bkp
    
    To setup periodic backup procedure that executes your run_bkp backup script, add lines to the /etc/crontab file:
    15      6       *       *       1       root    /root/run_bkp
    15      6       *       *       4       root    /root/run_bkp
    

 .