how to make Raspberry Pi a Webserver
From Petr Sladek
Todays tutorial will show you how to turn your Raspberry Pi into a Webserver.
These are a few pros of making Raspberry Pi into a Webserver:
- very good price: you can get one for $25 or $35
- no movable parts: no disk, no fans, results in no noise and higher reliability
- very low power consumption (less than 5 Watts) means very low operation costs
- huge community support and fan base
Of course, not everything is perfect, so we have to consider a few cons also:
- limited processing power performance
- limited data storage space
So this device is perfectly suitable for low cost projects with a few users and a limited data throughput.
The precompiled Linux distribution Raspbian bundle comes with all the graphics stuff, that is not needed to run a stand alone web server and we have to get rid of it.
The unnecessary software packages, if kept installed, would:
- reduce available memory
- reduce processing performance
- increase the start up time
The packages to be removed include:
- X server and windowing software
- multimedia players
- Scratch language
The other step is finally installing the needed packages.
Step by Step
In this section follow the steps needed to make Raspberry Pi into a Webserver.
First you need an operating system, so follow instructions in the how to install Linux on Raspberry Pi tutorial.
To perform all of the following steps, we will be using the command line. Use SSH login to connect to your device. From now on, we will be working in the command line, entering the various commands described bellow.
To make sure we work with the current software version, we have to perform the software update.
Enter these two commands:
sudo apt-get update sudo apt-get upgrade
Web server installation
To install the Apache web server
sudo apt-get install apache2 php5 libapache2-mod-php5
now to restart the web server service, you can do one of the following
sudo service apache2 restart
sudo /etc/init.d/apache2 restart
MySQL database installation
To install the database server, run the following command:
sudo apt-get install mysql-server mysql-client php5-mysql
If you finished all of the above installation steps, now comes the time to verify that everything is up and running.
Start your web browser and to the address line enter the IP address of your Raspberry Pi.
You should see the message
It works! This is the default web page for this server. The web server software is running but no content has been added, yet.
Ta daa! :-D Now we are happy and we can use are new web server!
If you want more features, you can install Java and Tomcat application server.
Check out other Raspberry Pi tutorials! ;-)