Running SilverStripe On Nginx (LEMP) On Debian Wheezy/Ubuntu 13.04

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Mon, 2013-10-14 16:57. :: Debian | Ubuntu | Web Server | nginx

Running SilverStripe On Nginx (LEMP) On Debian Wheezy/Ubuntu 13.04

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 10/11/2013

This tutorial shows how you can install and run SilverStripe on a Debian Wheezy or Ubuntu 13.04 system that has nginx installed instead of Apache (LEMP = Linux + nginx (pronounced "engine x") + MySQL + PHP). nginx is a HTTP server that uses much less resources than Apache and delivers pages a lot of faster, especially static files.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I want to install SilverStripe in a vhost called www.example.com/example.com here with the document root /var/www/www.example.com/web.

You should have a working LEMP installation, as shown in this tutorial:

A note for Ubuntu users:

Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing

sudo su

 

2 Installing APC

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and XCache. It is strongly recommended to have one of these installed to speed up your PHP page.

APC can be installed as follows:

apt-get install php-apc

Reload PHP-FPM as follows:

/etc/init.d/php5-fpm reload

 

3 Installing SilverStripe

The document root of my www.example.com web site is /var/www/www.example.com/web - if it doesn't exist, create it as follows:

mkdir -p /var/www/www.example.com/web

Next download SilverStripe from the SilverStripe web site (I'm using the "CMS & Framework" version here) to your server, uncompress it and place it in your document root:

cd /tmp
wget http://www.silverstripe.org/assets/releases/SilverStripe-cms-v3.1.1.tar.gz
tar xvfz SilverStripe-cms-v3.1.1.tar.gz
rm -f SilverStripe-cms-v3.1.1.tar.gz
cd SilverStripe-cms-v3.1.1
mv * .htaccess /var/www/www.example.com/web/

It is recommended to make the document root and the SilverStripe files in it writable by the nginx daemon which is running as user www-data and group www-data:

chown -R www-data:www-data /var/www/www.example.com/web

If you haven't already created a MySQL database for SilverStripe (including a MySQL SilverStripe user), you can do that as follows (I name the database silverstripe in this example, and the user is called sstripe_admin, and his password is sstripe_admin_password):

mysqladmin -u root -p create silverstripe

mysql -u root -p

GRANT ALL PRIVILEGES ON silverstripe.* TO 'sstripe_admin'@'localhost' IDENTIFIED BY 'sstripe_admin_password';
GRANT ALL PRIVILEGES ON silverstripe.* TO 'sstripe_admin'@'localhost.localdomain' IDENTIFIED BY 'sstripe_admin_password';

FLUSH PRIVILEGES;

quit;

Next we create an nginx vhost configuration for our www.example.com vhost in the /etc/nginx/sites-available/ directory as follows:

vi /etc/nginx/sites-available/www.example.com.vhost

server {
       listen 80;
       server_name www.example.com example.com;
       root /var/www/www.example.com/web;

       if ($http_host != "www.example.com") {
                 rewrite ^ http://www.example.com$request_uri permanent;
       }

       index index.php index.html;

       location = /favicon.ico {
                log_not_found off;
                access_log off;
       }

       location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
       }

       # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
       location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
       }

       client_max_body_size 100M;

       location ^~ /assets/ {
                try_files $uri =404;
                expires max;
                access_log off;
                log_not_found off;
       }
       location ~ \.ss {
                allow 127.0.0.1;
                deny all;
       }
       location ~ web\.config {
                deny all;
       }
       location ~ \.(ya?ml|bak|swp)$ {
                deny all;
       }
       location ~ ~$ {
                deny all;
       }
       location ^~ /silverstripe-cache/ {
                deny all;
       }
       location ^~ /vendor/ {
                deny all;
       }
       location ~ /composer\.(json|lock) {
                deny all;
       }
       location ~ ^/framework/(.+/)?(main|rpc|tiny_mce_gzip)\.php$ {
                try_files /6c1ec1bb21001dd913db95cfb05d78d7.htm @php;
       }
       location ~ ^/(cms|framework|mysite)/.+\.(php|php[345]|phtml|inc)$ {
                deny all;
       }
       location ~ ^/(cms|framework)/silverstripe_version$ {
                deny all;
       }

       error_page 404 /assets/error-404.html;
       error_page 500 /assets/error-500.html;

       location / {
                 if (!-f $request_filename) {
                    rewrite ^/(.*?)(\?|$)(.*)$ /framework/main.php?url=$1&$3 last;
                 }
       }

       location ~ ^/(index|install)\.php/ {
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       }

       location ~ \.php$ {
                try_files /6c1ec1bb21001dd913db95cfb05d78d7.htm @php;
       }

       location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                fastcgi_temp_file_write_size 10m;
                fastcgi_busy_buffers_size    512k;
                fastcgi_buffer_size          512k;
                fastcgi_buffers           16 512k;
                fastcgi_read_timeout 1200;
       }
}

To enable the vhost, we create a symlink to it from the /etc/nginx/sites-enabled/ directory:

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/www.example.com.vhost www.example.com.vhost

Reload nginx for the changes to take effect:

/etc/init.d/nginx reload

Now we can launch the web-based SilverStripe installer by going to http://www.example.com/install.php - fill in your database details and click on Re-check requirements:

Afterwards fill in a password for the admin account and select your language. Then scroll down...

... and select your theme (you can select an empty template to start from scratch or the Simple template which contains some demo data to start with). Then click on Install SilverStripe:

SilverStripe is now being installed. After a few seconds you should get an Installation Successful message:

The index.php and install.php files are no longer needed, so you can delete them:

rm -f /var/www/www.example.com/web/index.php /var/www/www.example.com/web/install.php

This is how the SilverStripe site looks (with the Simple them which contains some demo data):

The backend can be accessed under http://www.example.com/admin - this is how it looks:

 

4 Links

 

About The Author

Falko Timme is the owner of nginx WebhostingTimme Hosting (ultra-fast nginx web hosting). He is the lead maintainer of HowtoForge (since 2005) and one of the core developers of ISPConfig (since 2000). He has also contributed to the O'Reilly book "Linux System Administration".


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Max (not registered) on Thu, 2013-11-07 04:49.

Hi Falko!

I was just curious, can this process be used for ANY CMS? I was looking to install something smaller (snews17 for example) but I dont want to mess up my install of LEMP. Lots of love for all the work you've done so far!