This article will walk you through the process I followed to setup Statamic on a new DigitalOcean droplet. I will detail the steps in configuring a Linux (Ubuntu 14.04), Apache, and PHP stack (LAP)—no MySQL since I’m using Statamic—that I used to get my own site deployed.
The initial steps in setting up Ubuntu were borrowed from one of DigitalOcean’s own tutorials. They have a vast number of helpful tutorials for users, one of the main reasons I decided using them as a host. It’s made the process much easier for a newb like me.
When creating a new DigitalOcean droplet, you’re given the options of which Linux distro image you’d like to use. I’ve chosen Ubuntu 14.04 x64 for my setup and this tutorial. Of course, others are available.
SSH login as root
The first step in configuring your new server is to login as root with SSH. During the creation of a new droplet, an email will be sent to you with your server’s password. You will need this password to login as a root user. You will also need your server’s public IP address which can also be in that email, or in the DigitalOcean control panel. Open up a new terminal window and enter the following:
You will see the following warning.
The authenticity of host '18.104.22.168 (22.214.171.124)' can't be established. ECDSA key fingerprint is 79:95:46:1a:ab:37:11:8e:86:54:36:38:bb:3c:fa:c0. Are you sure you want to continue connecting (yes/no)?
yes to continue. This warning is due to an unrecognized server, since this is the first time you are connecting. You should now be logged in.
Changing the root user’s password
Next, you’ll want to change the password of your root user to something more memorable. The command to do so is as follows:
Type in your desired password, hit enter, then repeat your password. The terminal window will not reveal the password as you type for obvious reasons.
Adding a new user
As an added layer of security we need to create a new user that has root privileges.
username in the following should be changed to your preferred username.
To allow this user to have root privileges we need to add a line to a configuration file. Open this file with the following command:
Once the file is open you will need to scroll down and locate the following lines:
# User privilege specification root ALL=(ALL:ALL) ALL
Copy the line
root ALL=(ALL:ALL) ALL and paste it on a new line, changing
root to your username.
# User privilege specification root ALL=(ALL:ALL) ALL username ALL=(ALL:ALL) ALL
Once you’ve added this new line, press CTRL-X to exit, type “Y” to save the file, then press “ENTER” to confirm the file location. Your new user will now have root privileges.
Changing the SSH port and restricting root login
To add an additional layer of security, we should change the port that we use to login through SSH. We can do this by opening up the SSH configuration file:
Once that file is open find the following line:
22 to any number between 1025 and 65536. For example:
Next we will restrict the ability to login as the root user. Find the following line in the same file as the port we just changed:
We need to disallow root login, so change
Lastly, in this same file, add the following line to only allow the username you’ve created.
Once you’ve added this line, restricted root access, and changed the port, press CTRL-X to exit, type “Y” to save the file, then press “ENTER” to confirm the file location. You can now only login to your server through SSH on the port you’ve chosen with the newly created user.
Almost done: Restart SSH and test your login
We’ve added a new user with root privileges, restricted the root user, and changed the port through which we connect. Now we need to restart SSH and test out our connection with the new user.
service ssh restart
Now, open a new terminal window so we can test the connection. In the new window we will connect through SSH with our newly created user:
username, on the port we’ve chosen:
-p 45600. Here’s what it should look like:
ssh -p 45600 username@server_ip_address
If all is properly configured you should now be connected to your server. Congrats. Type
exit to logout of the previous window logged in as root, and continue with this new user.
Well, we’ve configured our Ubuntu user, so now we’ll install Apache, the popular software that runs most web servers. Do this through Ubuntu’s
apt package manager command:
sudo apt-get update sudo apt-get install apache2
You will be prompted for your password since we are running a
sudo command that allows root privileges.
You can check if this install was successful by visiting your public IP in a web browser:
You should see a default Apache2 Ubuntu page, which will indicate you’ve correctly installed your web server. Cool, now let’s configure Apache in preparation for installing PHP.
Configurations for PHP
By default, HTML files are preferred over PHP. let’s change this to prefer PHP files first:
sudo nano /etc/apache2/mods-enabled/dir.conf
Find the following lines and note the order of each index file:
<IfModule mod_dir.c> DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm </IfModule>
To prefer PHP files move
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
As always, press CTRL-X to exit, type “Y” to save the file, then press “ENTER” to confirm the file location. After you restart Apache, it will now look for PHP files first and foremost.
sudo service apache2 restart
In order for Statamic to rewrite URLs, we need to make some Apache configuration changes to allow our .htaccess file to work. Let open the Apache configuration file:
sudo nano /etc/apache2/apache2.conf
Find the following lines:
<Directory /> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>
Change the line
AllOverride None to
<Directory /> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory>
Press CTRL-X to exit, type “Y” to save the file, then press “ENTER” to confirm the file location.
Next enable the following Apache modules
a2enmod rewrite a2enmod headers
That should be it for Apache configurations. On to PHP.
Most sites run on PHP. Statamic is not an exception, so let’s install PHP. Again, we’ll do this through Ubuntu’s
apt package manager command:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
Hooray! Done. Well sorta, we still need to install Statamic. Let’s do that with GIT.
My site is version controlled with GIT and I’ll be installing it on the server with GIT’s
clone command. You’ll just need your repo’s HTTPS url for cloning. My repo is hosted on GitHub.
cd to the directory where we’d like to clone our repo. By default, Apache only allows public html to reside in
Next we’ll clone the repo using our HTTPS repo url:
sudo git clone https://github.com/username/repo-name.git
Great, now our website is on the server, but we need to make one more small configuration to Apache before the site can be accessed.
Change Apache’s default site directory
We need to point Apache to the newly created directory; by default it points to
/var/www/html/. Let’s edit another Apache configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Locate the following lines:
ServerAdmin webmaster@localhost DocumentRoot /var/www/html/
html directory to your public folder within the cloned directory name, e.g.
ServerAdmin webmaster@localhost DocumentRoot /var/www/repo_name/public
Press CTRL-X to exit, type “Y” to save the file, then press “ENTER” to confirm the file location. Apache should now point to your Statamic website. Restart Apache for the changes to take effect.
sudo service apache2 restart
Now, to change some permissions on a few Statamic folders.
cd to the
public directory then run the following commands:
chmod -R 775 _cache chmod -R 775 _logs chmod -R 775 _content chmod -R 775 _config/users
Lastly, we need to change the owner of the files within our
chown -R username:www-data /var/www
Great! That should be it. Test it out by visiting your public IP. If everything’s setup correctly you should see a working Statamic site. If not, well, shitfire!, I may have left out a crucial detail.
This is kind of a headache of a process to go through the first time as a newb, but it’s a cool learning experience. Also, it allows you to take advantage of powerful developer hosting which beats a crappy shared hosting plan any day. Welp, if I’ve done anything stupid you can let me know in the comments.