Sunday, 04 May 2014 20:43
Setup a Raspberry Pi PHP web server
Lighttpd is a lightweight web server, with all the essential functions of a web server, PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. This is a quide on how to install Lighttpd and PHP on a Raspberry Pi.
Connect the Raspberry Pi to the computer via a network cable, the monitor, keyboard or mouse does not have to be connected, everything is remotely controlled by the computer through SSH software. The Raspberry Pi is automatically set to obtain an IP address from your wired or wireless network. You must find its IP address before you can SSH to Raspberry Pi.
There are many ways to find the IP address , I'm preferring the SoftPerfect Network Scanner software which is available here.
Select Options>IP address>Detect Local IP Range from menu as shown in figure below:
I'm select 192.168.0.138 for the network's IP range, it is the IP address of my computer
After select the network's IP range, click on Start Scanning icon to start the scanner
The IP address of Raspberry Pi is detected as 192.168.0.223 as shown in figure below
Launch PuTTY and SSH to Raspberry Pi, you can start the web server software installation now. The login user and password is pi and raspberry respectively
Lighttpd is a lightweight web server, with all the essential functions of a web server
sudo apt-get update #download package lists from the repositories
sudo apt-get -y install lighttpd
After the installation is complete, you should have ../www in the /var directory, the Lighttpd web server is ready.
Open up a browser and navigate to http://192.168.0.223 (use your Raspberry Pi IP address), a Placehoder page should appear as shown in figure below:
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language.
sudo apt-get -y install php5-common php5-cgi php5
sudo lighty-enable-mod fastcgi-php #Enable the Fastcgi module which will handle the PHP pages
sudo service lighttpd force-reload #restart the Lighttpd service
The /var/www is the root directory of the website, it is currently owned by the “root” user. We must ensure the "Pi" user account can write files to /var/www directory.
sudo chown www-data:www-data /var/www #chown username:groupname directory
sudo chmod 775 /var/www #permission to write to this directory
sudo usermod -a -G www-data pi #add the “Pi” user to the “www-data” group
Reboot the Raspberry Pi. After boot up the Raspberry Pi, your PHP web server is ready. You should able to transfer web pages to /var/www directory.
Testing web server
To access the web pages from server, enter http://192.168.0.223 (use your own web server IP)
By default web servers communicate over port 80. You can easily change it by editing the lighttpd.conf file:
|server.port = 8000|
Restart needed for update to take effect
|sudo /etc/init.d/lighttpd restart #restart the lighttpd service|
Enter http://raspberryPi_IP:port (eg. http://192.168.0.223:8000) to access web pages from web server
Transfer files with WinSCP
With WinSCP you can manipulate remote files directly on the Raspberry Pi web server.
After login to Raspberry Pi web server, transfer your web pages to /var/www directory.
Please click here on how to use WinSCP