Installing Statamic

Statamic is a new PHP CMS with relatively small community. This website currently runs on Statamic. When it comes to setup, Statamic documentation provides very brief instructions on how you can install Statamic. Normally installing Statamic is quite easy. This is a quick rundown on how you can install Statamic on Ubuntu with Apache as web server.

For sake of simplicity we are gone assume that you will run Statamic into your website’s document root.

  • Provision a new Ubuntu server on you favourite VPS or cloud hosting provider. I currently use Digital Ocean. SSH as root user and perform update,
ssh root@XYZ.XX.YY.ZZ
apt-get update
  • Install Apache.
apt-get install apache2
  • Install PHP (PHP 5.3.6+, compiled with the mcrypt extension) and other modules.
apt-get install php5 php5-common php5-cli libapache2-mod-php5 php5-mcrypt php5-gd php5-curl
  • Enable mod_rewrite and mod_headers Apache modules
a2enmod rewrite 
a2enmod headers
  • Add a new Apache user (vagrant), give appropriate permissions on document root (in my case /var/www)
adduser vagrant 
usermod -a -G www-data vagrant
chown -R vagrant:www-data /var/www
  • Setup GIT as we want to version control all Statamic files as well content created by Statamic.
apt-get install git
  • Add following to /etc/apache2/httpd.conf. First one is typical Apache server name. Then we added the Cache-Control header to enable client-side caching. Feel free to change max-age value according to your requirements.
ServerName localhost

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=7776000, public"
  • To make .htaccess files work, edit your site (default site in my case /etc/apache2/sites-available/default). For /var/www/, you need to modify the line containing AllowOverride None to read AllowOverride All.
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all

You may also want to add following rewrite rule in your site if you are redirecting old .html urls.

# Redirect .html to non .html slug
RewriteEngine on
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ $1 [R=301,L] 

Then restart Apache,

service apache2 restart
  • Now open new terminal window and SSH as Apache user, and setup GIT config
ssh vagrant@XYZ.XX.YY.ZZ
git config --global “Your Name” 
git config --global “” 
  • As Apache user, copy the Statamic files within into your website’s document root (FTP or SFTP) and initialise the GIT repository. Statamic comes with the with sample .gitignore and sample.htaccess rename them.
    cd /var/www/
    git init
    mv sample.gitignore .gitignore
    mv sample.htaccess .htaccess
    git add -A
    git commit -m "First Commit"
    git remote add origin
    git push origin master

Otherwise you can always clone an existing GIT repo in website’s document root,

cd /var/www/
git clone .
  • Make sure that the following folders1 are writable by the Apache user:
  1. _cache, to enable caching and it is a must
  2. _logs, to enable message logging
  3. _content & _config/users - to use the Control Panel
chmod -R 775 _cache
chmod -R 775 _logs

Once more as root user run following,

chown -R vagrant:www-data /var/www
  • If you want to run Statamic from sub-directory (let say statamic) you will need to update _site_root in your _config/settings.yaml file to reflect the correct subdirectory.
 _site_root: /statamic/

That’s it. Your Statamic website should be up and running. In next post I will discuss how you can enable Varnish, PageSpeed and CDN to accelerate your content delivery using Statamic.

  1. Optionally, create _cache, _logs, _cache/_app, _cache/_add-ons folders if they are missing (requires when you clones a GIT repo with .gitignore