How do I auto-launch a custom webserver on BeagleBone Black?

Dave picture Dave · Jun 25, 2013 · Viewed 14.5k times · Source

I'd like my BeagleBone Black to start up and start web-serving with a custom web server, without the need to log in and configure/launch/change anything.

I suppose this question is two-fold:

  • How do I remove all of the default, redundant, or conflicting startup web server behavior? I am running stock Angstrom, 3.8.13.

  • Assuming I have my own web server executable (in my case a twistd web server), how do I configure it to launch automatically upon board startup?

Thank you very much for any help you can give me.

Answer

Biggsy picture Biggsy · Mar 16, 2017

Intro

I think you are trying to do the same as me, i.e. change the webpage that you see in a browser when you navigate to the BBB's IP address from its default bone101 page to your own custom webpage written in HTML or whatever.

Based partly on the answers on this page plus my own trial and error, I have worked out how to do that and I provide a full and complete answer below.

Clarification of Confusing Points in Other Answers

But first, to clarify some confusing points in the other answers on this page:

  • When you plug the BBB into your computer via USB and navigate your browser to the BBB's IP address (192.168.7.2 by default), you get the default bone101 page located (by default) at /usr/share/bone101/index.html

  • If you plug your BBB directly into your router via ethernet (or setup a wifi connection), you can then browse to the BBB's IP address on the network and you will get the same webpage.

  • If you then set up port forwarding on your router to forward incoming http traffic to the BBB and you then access your network's external IP address (either directly or via your domain (www.example.com) which points to that IP address), then you will also get the same webpage.

This is ultimately what I and, I believe, the OP are trying to change. I want to use my BBB as a web server to serve my own website and I don't want people going to www.my-website.com to see the default bone101 stuff.

The Solution

NB: I am running the latest Debian ARM image, not angstrom, so the default locations may be different.

First disable and stop the existing bone101 stuff, as per Bas Wijnen's answer:

systemctl disable bonescript.socket
systemctl disable bonescript.service
systemctl stop bonescript.socket
systemctl stop bonescript.service

Then edit the apache web server configuration. Start by editing the port listening configuration:

sudo vim /etc/apache2/ports.conf

and change this line:

Listen 8080

to this:

Listen 80

as port 80 is the default port for http traffic. Otherwise people would have to go to www.your-website.com:8080 which is just silly.

Then, as noted in the above file, you will also have to edit the sites enabled configuration:

sudo vim /etc/apache2/sites-enabled/000-default.conf

Edit the first line from this:

<VirtualHost *:8080>

to this:

<VirtualHost *:80>

Then either put your content in the directory noted in the DocumentRoot field (this is the directory to be used as the root of your website), which is by default /var/www/html, or change the DocumentRoot field to point to the directory you want to use. In my case, I left it as /var/www/html but then made that a symlink to a directory within a git repository where my website content is.

Or if you just want to do a quick test, symlink or copy the apache default test page into the DocumentRoot directory or change the field to point to the directory where the apache default test page is located (by default, /usr/share/apache2/default-site/index.html)

Then restart apache, et voilà:

sudo /etc/init.d/apache2 restart