Introduction: Setup a Raspberry Pi PHP Web Server

About: A place for DIY projects

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 tutorial on how to install Lighttpd and PHP on a Raspberry Pi.

Step 1: Prerequisite

Step 2: Connect the 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.

Step 3: Find the IP Address of the Raspberry Pi

There are many ways to find the IP address , I'm preferring the SoftPerfect Network Scanner software which is available here.

Launch SoftPerfect Network Scanner

Select Options>IP address>Detect Local IP Range from menu as shown in figure above:

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

Step 4: SSH to Raspberry Pi

Launch PuTTY and SSH to Raspberry Pi, from here you can start the web server software installation. The login user and password is pi and raspberry respectively.

Step 5: Install Lighttpd & PHP

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 .



Install PHP

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



Permmission

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

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, your Raspberry Pi web server is ready.

Step 6: Testing Web Server

To access the web pages from server, enter http://192.168.0.223 (please 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

Step 7: Transfer Files With WinSCP

Transfer files with WinSCP

With WinSCP you can manipulate remote files directly on the Raspberry Pi web server.

Please click here on how to use WinSCP