Friday, May 30, 2014

Host Your Own Website On Your Raspberry Pi

Host Your Own Website On Your Raspberry Pi
By Christian Cawley

Need to run a website but can’t afford the hosting costs? One way around this is with the Raspberry Pi, which is more than capable of running basic web server software. Best of all, setting it up is simple.

Why Use A Raspberry Pi?

We’ve previously looked at the many amazing uses for the Raspberry Pi – but who knew it could run as a web server? Whether you’re looking for an Internet-facing site (perhaps as a basic home page), a small-scale corporate intranet, or a test machine you run a WordPress development system on (or even the new Ghost blogging platform), it’s easy to setup.
There are various good reasons to setup a Raspberry Pi as a webserver. For instance, your desktop computer may not have the available system resources to serve pages reliably. Alternatively you might be interested in using it as an always-on web server offering content that anyone can access, which means leaving the device switched on for lengths of time. As the Raspberry Pi has a very low energy footprint, this makes it an ideal choice.
Other reasons exist. The size of the computer makes it useful as a portable device, something that might prove useful if you are trying to run a web server in a territory where this isn’t usually allowed, or if hosting is expensive for you.
muo rpi mediaready   Host Your Own Website On Your Raspberry Pi

Getting Started: Setup Your Server Hardware!

Before you get started, ensure you have all of the necessary hardware. Our guide to the basic Raspberry Pi setup should help you here. In addition, you should ensure your device is connected to your local network. This might be via Ethernet or you can setup Wi-Fi with a suitable dongle.
You should also have a suitable distro installed to your SD card. Several are available; the steps in this guide were performed using Raspbian.
It is worth taking the time to setup SSH on your Raspberry Pi too, as well as TightVNC.

Configuring Your Raspberry Pi As A Webserver

Before you upload your HTML pages to your Raspberry Pi, you’ll need to configure the server and its software.
muo raspberrypi webserver apt get   Host Your Own Website On Your Raspberry Pi
Begin by running an update using sudo apt-get update. You’ll then need to install Apache and associated libraries, which can be done by entering:
sudo apt-get install apache2 php5 libapache2-mod-php5
Finally, enter:
sudo service apache2 restart
Next, open a browser on your computer and enter the IP address in the address bar. You’ll see confirmation that Apache is installed.
Your Raspberry Pi is now setup as a basic web server. All you need to do is add pages!

Configuring FTP On The Raspberry Pi

While you can check in the browser that your Pi is running as a web server, the page on offer will be very basic. This is a typical placeholder index.php file, one that you will have to replace with your own PHP or HTML document.
This will be far easier with FTP installed, and you can do this by first creating a suitable www directory and then installing the FTP software:
sudo chown -R pi /var/www
sudo apt-get install vsftpd
With the FTP application vsftpd (“Very Secure FTP Daemon”) installed you’ll need to make some changes to the configuration. First, open the config file in nano…
sudo nano /etc/vsftpd.conf
muo raspberrypi webserver nano   Host Your Own Website On Your Raspberry Pi
…and make the following permissions/security changes:
Update
anonymous_enable=YES
to
anonymous_enable=NO
Uncomment the following lines (remove the # symbol)
#local_enable=YES 
#write_enable=YES
Finally add this line to the end of the file:
force_dot_files=YES
This will force the display of server files starting with a “.”, such as .htaccess.
Press CTRL+X to save and exit, confirming with Y and Enter.
You should then restart FTP with
sudo service vsftpd restart
Using a standard desktop FTP you will then be able to connect to your Raspberry Pi. Files should be uploaded to /var/www.

Want More Than HTML? Raspberry Pi Also Supports LAMP!

The Raspberry Pi isn’t only capable of serving basic HTML pages. The LAMP server configuration can be installed if you want full MySQL with PHP support using
sudo apt-get install mysql-server mysql-client php5-mysql
As with any web server project, you need to first determine if the method you plan to use will be suitable for your needs. While it is possible to setup WordPress to run on the Raspberry Pi, adding a multitude of plugins and multiple daily updates will make it extremely slow. The website you plan to run – at least with a sole Raspberry Pi – should be light on resources and software requirements. By all means use a database driven solution if necessary, but limit the number of pages/volume of content that can be viewed.

Security & Technical Considerations

You’re unlikely to get anything nearing production-level speed when using the Raspberry Pi as a web server for anything resembling a popular website.
There are ways you can improve performance, however, such as setting up your server software on a USB hard disk drive rather than on the SD card in order to reduce degradation through regular read/write processes. Alternatively, using your device RAM for temporary read/write file storage is an option too. This is something you will perhaps want to change when you have decided how you’re going to use your very small web server.
muo raspberrypi webserver hello   Host Your Own Website On Your Raspberry Pi
Although suitable for setting up a test version of a database-driven PHP website, the Raspberry Pi’s online duties are probably best suited to a small collection of static pages.
Note that if you do plan to open access to your Raspberry Pi as an Internet-connected web server, you’ll need to setup your router with a static IP address.
Finally, take the time to change your Raspberry Pi’s default password. This can be done in the command line via SSH using

passwd
You will then be prompted to input and confirm a new password. Doing this will stop anyone familiar with Raspbian from being able to access the backend of your web page.

Conclusion: A Portable Website!

The potential for using a Raspberry Pi as a web server is considerable. While it is unlikely you’ll be able to host games or a website like MakeUseOf, by employing some portable tools (such as a battery pack and mobile Internet dongle) you could use the mini-computer to host a website wherever in the world you may find yourself.
Alternatively, you might host a home intranet!
Try it out, and let us know how you used your Raspberry Pi web server.
Image Credits: Johan Larsson Via Flickr Source: www.makeuseof.com

1 comment:

Offshore Web Hosting Servers said...

Best offshore hosting and DMCA ignore Hosting with 99.9% Up time Guarantee Offshore host by webcare360.com

Stream for free

I was written to because I cited Roku on  this page  at Balunywa Bytes.  Here at KillTheCableBill.com, we're helping people beat inflati...