Setting up my server in the new year.
Here are my notes from initial server setup to migrating two domains and one Perch Runway site.
Goal in the end is a fast and secure website. I'll use some online tools to test and fine tune my sites. By running my own server I can get A+ on ssl test and using Perch Runway run a blistering fast website. I also ran some web speed tests at pingdom, web page test and google page insights.
I was pleasantly surprised to discover that my previous notes were helpful. Helpful for me. So now I know. Writing is a great technology to remember important facts.
My goal is to move from Ubuntu 14 to Ubuntu 16 on a LAMP stack. Rather than run a system upgrade on the server I decided it would be easier to start fresh with default installation of PHP 7 and Python 3 and these
It wouldn't cost much extra. I'd only need to run two servers for a day or two and as soon as the new server is working o.k., I can delete the old droplet. It's cheap and easy in 2017 to spin up new droplets. Droplets, by the way, are virtual private machines. Not sure where DigitalOcean came up with that term, but I've adopted it and think its kind of cute.
Step One: Spin up droplet
- Login to the DigitalOcean
- Create new droplet
- Choose LAMP on 16.4 One-click apps
- Choose a droplet size
- Choose a data center region. SF01
- Add SSH keys. I had an ssh key from DeployBot available.
- Name your droplet and and then
- Create it
I like that. That was easy.
Step Two: Initial Server Setup with Ubuntu 16
This is when things get a little more complicated. Fortunately for me, DigitalOcean’s community of writers provide great documentation. Its one of the reasons I choose to host my sites here. I pretty much followed the steps in this article Initial Server Setup with Ubuntu 16.04 by Mitchell Anicas, software engineer at DigitalOcean with some slight variations based on my particular setup.
Create user with root privileges
- adduser username
- usermod -aG sudo username
Add Public Key Authentication
ssh-copy-id user@your_server_ip
Disable password so only can use ssh keys to login to server.
sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
sudo systemctl reload sshd
test login from local
ssh scott@your_server_ip
Setup up Basic firewall
sudo ufw app list
sudo ufw allow OpenSSH
sudo ufw status
Setup MySQL
Now we’ve got the basic server setup. We’re getting there. Next up was configuring MySQL with a database and user.
- mysql_secure_installation
- enter mysql root password
- create db_database
- create db_user and assign rights to db_database
Several quick tasks
Set timezone
sudo dpkg-reconfigure tzdata
Choose America/Los_Angeles
Configure Network Time Protocol Synchronization
sudo apt-get update
sudo apt-get install ntp
Setup mod_rewrite
sudo a2enmod rewrite
sudo service apache2 restart
Setup mod_headers
sudo a2enmod headers
sudo service apache2 restart
Edit php.ini file
cd /etc/php7.0/apache2/
Then use nano our friendly text editor to open php.ini and make two quick changes.
post_max_size increased to 128M
upload_max_filesize increased to 128M
Setting up 3 domain with apache2
I’m hosting three websites on one server and ran the setup following these instructions.
mkdir -p /var/www/scottgruber.me/html
mkdir -p /var/www/robertpavlovich.design/html
mkdir -p /var/www/conservationactionresearch.net/html
Step 2: Set permission to current user logged in. In this case me!
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/test.com/html
sudo chown -R $USER:$USER /var/www/conservationactionresearch.net/html
Step 3: Create separate conf files
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/scottgruber.me.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/robertpavlovich.design.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/conservationactionresearch.net.conf