
Raspberry Pi Server
(Raspian, Google Dynamic DNS Without Static IP Address, DDClient)
This tutorial is for users who wish to set up a simple website on there Raspberry Pi
affordably without a static IP address. I purchased my domain name at google.com for $12/year (the only expense) and set up ddclient on my Raspian distro.
How-To:
To begin, make sure your Raspberry Pi is up to date:
sudo apt-get upgrade
sudo apt-get upgrade
Next install all relevant packages:
sudo apt install apache2
sudo apt install mysql-server
sudo apt install php5 libapache2-mod-php5
sudo apt-get install phpmyadmin //used for sql editing
You should restart the server after all the installs:
sudo service apache2 restart
Open a web browser and navigate to http://localhost/. You should see an apache message saying it works!
You should also check if PHP is working.
php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
If either do not work, please repeat previous steps.
Make any additional html pages here:
cd /var/www/html/index.html
sudo nano new_page.html
Now you need to make a few edits in the apache.conf:
sudo nano /etc/apache2/apache2.conf
Add in at the bottom of the file:
Include /etc/phpmyadmin/apache.conf
Now press control-w to search for words.
Search for this portion of the apache.conf:
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
to
Options FollowSymLinks
AllowOverride None
Require all granted
and change this too:
Options Indexes FollowSymLinks
AllowOverride Off
Require all granted
to
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
I also recommend creating a .htaccess file in your /var/www/html/
It will be hidden when viewing from ls, because it is a .extension file.
.htaccess file will redirct your root domain search to a certain html file, and
controls many more features.
You can use this site to create a full .htaccess file (Make sure to DELETE //comments)
https://www.htaccessredirect.net/
Restart apache:
sudo systemctl restart apache2.service
You should also make apache2 boots at start:
sudo systemctl enable apache2.service
Now you are going to purchase your domain name (last time I checked it was $12/year for a .com website)!
Browse over to domains.google and purchase your very own domain!
Once there, follow these steps:
1. Navigate to Google Domains: domains.google.com/registrar.
2. Click the DNS tab for the domain.
3. Scroll down to Synthetic Records.
4. Select Dynamic DNS from the list of synthetic record types.
5. Enter the name of the resource you plan to have assigned a Dynamic IP,
either a subdomain or @ for your default domain (“root domain” or “naked domain”).
6. If you selected sub-domain, enter the name of the subdomain.
7. Click Add.
8. The Dynamic DNS record is created in your list of synthetic records. Click the
expand triangle to the left of the record to view its values.
9. Click View Credentials to view the user name and password created for this record.
10. Copy down the username and password created. You will need these for your
ddclient conf.
For photos of steps checkout: https://support.google.com/domains/answer/6147083?hl=en
Installing DDClient to update your IP address as it changes (Dynamic DNS):
Just click through and add information to the best of your ability.
You will be overwriting the conf file so dont worry.
sudo apt-get install ddclient
sudo nano /etc/ddclient.conf
Paste in this:
protocol=dyndns2
use=web
server=domains.google.com
ssl=yes
login=generated_username
password=generated_password
your_resource.your_domain.tld
Replace your_resource.your_domain.tld with your domain, in my case: samdoggett.com
Now run ddclient for the first time. After that lets use crontab to update it hourly!
sudo ddclient -debug -verbose -noquiet
sudo crontab -e
add the following line to the bottom of the document:
0 1 * * * /usr/sbin/ddclient --force
Finally, to make our website public you should set up port forwarding on your router!
Unfortunately, this is not uniform on all routers so google how to set up port forwarding
for your ISP. This should involve going to the firewall and adding port exceptions for
solely your raspberry pi. You should make available ports 80 and 443 for both UDP and TCP.
This will enable port access to your raspberry pi's webserver ports!
If you are interested in sshing to your raspberry pi to remove the need for a monitor or keyboard
enter the following commands. Also enable port access to your pi for port 22, both UDP and TCP
sudo systemctl enable ssh
sudo systemctl start ssh
You should now have a running website!
Optional: Let's Encrypt! Let's make our server SSL secured! Make it https:// certified.
If you are running Raspian stretch, follow these next steps (otherwise find your distro at
https://certbot.eff.org/all-instructions):
sudo nano /etc/apt/sources.list
Add this to the end of the file:
deb http://ftp.debian.org/debian stretch-backports main
Continue(https://certbot.eff.org/lets-encrypt/debianstretch-apache.html):
sudo apt-get install python-certbot-apache -t stretch-backports
sudo certbot --apache
Certbot should update automatically! You can test the renew feature by doing:
sudo certbot renew --dry-run
You do not need to enable anything to have auto-renew
You now have a working Raspberry Pi Webserver with Google Domain, SSL, and Dynamic DNS
I recommend doing some extra research after successuflly setting up the server to make it more secure.