Raspberry Pi as web server
my first project is to turn my Raspberry into a small web server. For this I was to use the following things:
- Apache2 as web server
- PHP 5 as script language
- MySQL as database
- FTP Server
First we have to check if the user group for the web server exists:
sudo groupadd www-data sudo usermod -a -G www-data www-data
Normally this step is not needed.
After that, we can install Apache with a packet manager:
sudo apt-get install apache2
Done. Now with localhost in our Browser on the Raspberry Pi we should se a message.
Php 5 can also be installed easily with the packet manager:
sudo apt-get install php5
Thats all! But for a web server you may need some additional packets that works with PHP 5:
sudo apt-get install libapache2-mod-php5 libapache2-mod-perl2 php5 php5-cli php5-common php5-curl php5-dev php5-gd php5-imap php5-ldap php5-mhash php5-mysql php5-odbc
MySQL is a very popular database for web servers. I personally use PostgreSQL. You can install MySQL with the following command:
apt-get install mysql-server
During installation the root password for the database is needed.
If you want to avoid problems, you should reboot you Raspberry now. I wanted to skip this step and got error messages like ‚packet mysql-server-5.5 is not yet configured‘.
PHPMyAdmin is a smart web client for MySQL. It can be installed the following way:
apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
Here we get a dialog where we use Apache2 as web server.
PhpMyAdmin also needs to create tables in your database. So there will be a dialog where it is asked if it is allowed to do that. We want this and we also need to set a new PhpMyAdmin password.
To get our program source code to the server we need a FTP connection. For this we install ProFTP.
sudo apt-get install proftpd
During installation we choose ’standalone‘.
For our FTP server we don’t need real Unix users, but some virtual ones. For this we change the following file:
sudo nano /etc/proftpd/proftpd.conf
we add the following lines at the end:
DefaultRoot ~ AuthOrder mod_auth_file.c mod_auth_unix.c AuthUserFile /etc/proftpd/ftpd.passwd AuthPAM off RequireValidShell off
Now we create a virtual User (for me the username is hansi):
cd /etc/proftpd/ sudo ftpasswd --passwd --name hansi --uid 33 --gid 33 --home /var/www/ --shell /bin/false
Now you will be asked to set a password for the FTP user. This FTP user now has read and write permissions for your web server root directory. We only need to set some rights:
sudo chmod g+s /var/www sudo chmod 775 /var/www sudo chown -R www-data:www-data /var/www
The last thing is to restart out FTP server daemon:
sudo /etc/init.d/proftpd restart