How to Turn Your Raspberry Pi into a Fully Functional Web Server
First we will start with the shopping list. You will need one of each of the required items. This list is assuming you already have a USB keyboard and USB mouse.
|1||Micro USB cable||$5.79|
|1||SD Card (class 10, minimum 4GB recommended)||$7.63|
|Total Including Optional Items: $80.25|
*Prices are subject to change
After you’ve collected your hardware, you need to flash your operating system onto your SD Card. For this tutorial we will be using Raspian. I recommend it because it is an optimized version of Debian built specifically for Raspberry Pi’s. The last stable downloads can be found here.
To flash your SD Card, you will need to unzip the image and write it your SD card using Win32DiskImager. This tool can also be used to after our initial setup to create an image of our finalized implementation(very useful as a backup).
After the image is flashed, you can boot your device. At this point you can use your HDMI Cable/Mouse/Keyboard for your initial configuration, or you can use an SSH Client like Putty to connect. The default hostname, login, and password are as follows:
For this tutorial, I will be using putty. On first boot, you will be prompted with a configuration tool called Raspi-Config. If the raspi-config doesnt load automatically, just enter the following command from the shell to get started.
The settings I recommend you update are
The usual distribution images are 2 GB. When you copy the image to a larger SD card you have a portion of that card unused. expand_rootfs expands the initial image to expand to fill the rest of the SD card, giving you more space. By default, 64mb is reserved for the Graphical UI. Since we plan on using this as a web server, I reduce this to 32mb with the memory_split command.
After you finish your changes to the raspi-config, you should reboot your pi using the following command:
sudo shutdown -r now
At this point you have a fully functional linux server, but we still need to install apache, php, and mysql. This part is actually rather straightforward.
First, run the following commands from the shell to install Apache and PHP.
sudo apt-get update
sudo apt-get install apache2 php5 libapache2-mod-php5
The Locations of the Apache and PHP files are respectively
Next, run the following command to install MySQL.
sudo apt-get install mysql-server mysql-client php5-mysql
You will need to create a password for the MySQL Root Account
After this is completed, give it a try! To test Apache, navigate to the IP or Hostname of your Rasberry Pi in your browser, and you should see the famous “It works!” Screen.
To test the PHP, create a text file under your /var/www/ directory called phpinfo.php with the following contents:
Navigate to the file:
And that’s it! You’re done. You’ve got a fully functionally Raspberry Pi Web Server!
For ease of use you might want to install an FTP Server. You have a few options PROFTP, VSFTP. I prefer VSFTP and that can be installed with the following commands:
sudo chown -R pi /var/www
sudo apt-get install vsftpd
The configuration file for vsftp can be found here:
If you are in a windows environment, you might find it useful to install SAMBA for network shares. To install samba, use the following commmands
sudo apt-get install samba
The configuration file for samba can be found here:
Raspberry PI Full Specs:
•Broadcom BCM2835 700MHz ARM1176JZFS processor with FPU and Videocore 4 GPU
•GPU provides Open GL ES 2.0, hardware-accelerated OpenVG, and 1080p30 H.264 high-profile decode
•GPU is capable of 1Gpixel/s, 1.5Gtexel/s or 24GFLOPs with texture filtering and DMA infrastructure
•Boots from SD card, running a version of the Linux operating system
•10/100 BaseT Ethernet socket
•HDMI video out socket
•2 x USB 2.0 sockets
•RCA composite video out socket
•SD card socket
•Powered from microUSB socket
•3.5mm audio out jack
•Size: 85.6 x 53.98 x 17mm”