JAMES
LOPER

How to set up Apache & PHP on Digital Ocean

Follow this massive guide to run a world-class server on the cheap. If you've never even set up a server before, don't fret as it takes about 30 mins to follow this crash course. I recommend to follow the steps down to the popular modules and skim the rest if you're curious. Google if you get stuck. Good luck!

Quick Reference

Restart Apache service apache2 restart
Digital Ocean Reboot reboot
Digital Ocean MX records See Email
Digital Ocean Install Curl See Enable Popular Apache2 Modules
Digital Ocean Remote MySQL Access See Install PhpMyAdmin
Digital Ocean Install PhpMyAdmin See Install PhpMyAdmin
Digital Ocean vhosts See Running Multiple Websites

Initial Setup

Remote Access

Mac users can enter the following command into Terminal to login to their Droplets. Once logged in, the commands you enter will be executed on the Droplet:

Windows users can download Putty and do the same thing. If you're having trouble with this step, it is most likely your ISP needs to be told to unblock port 22. Run these two commands to make sure the server has the most up to date information.

Specify Your Hostname

Install Apache

Apache plays the defining role of a server; to reply to requests coming from the web. Now you can navigate to your-domain.com and see the default website. To upload your actual site, use a good SFTP client like Coda (Mac) or FileZilla (Windows) to login using the credentials from step two. The default folder is /var/www.

Install PHP & MySQL

PHP adds the ability to create web pages programmatically, and MySQL is used to store larger data sets where a file wouldn't necessarily be the best option.

Install PhpMyAdmin

After this is installed you will be able to administrate your MySQL database by navigating to your-domain.com/phpmyadmin.

Enable Popular Apache2 Modules

Rewrite lets you make vanity URLS and countless websites depends heavily on it. Headers lets PHP modify webpage headers, and CURL lets you pull in data from external websites.

Email

This section now has its own guide!

Enable SSL

Running Multiple Websites

To run multiple websites, open the vhosts file in /etc/apache2/sites-available/000-default.conf. Assuming you pointed the domain example.com at your Digital Ocean account, you can add the following code to serve files in /var/www/example to example.com and www.example.com
<VirtualHost *:80>
	DocumentRoot /var/www/example
	ServerName example.com
	ServerAlias www.example.com
</VirtualHost>
If you would like each user's code to run as the user and not a privileged user like www-data, you'll need to install MPM-ITK. Then create a user for each website. Each user will not be able to access the other user's files and thus your server is more secure. The Adduser command will create a new home folder, sftp user and password. Use mkdir to create a www folder in the home directory.