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
Apache2
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
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
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
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.
FTP
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‘.
Configuration
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
Hi,
The configuration of ProFTP solved an issue I have had deleting files created by PHP using ftp.
I’m using this small web server to test a gallery, and a few other tools I have made, under Linux. Perfect little server for that. I only also had to install php5-gd.
Thanks a lot for the description.
Best Regards
Kenny
Hello,
Really appreciate this guide and instructions.
Having a problem when trying to run the PHPMyAdmin install.
pi@my-Pi:~ $ sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadminReading package lists… Done
Building dependency tree
Reading state information… Done
Package libapache2-mod-auth-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‚libapache2-mod-auth-mysql‘ has no installation candidate
Completely new to the RaspberryPi and not sure what to do next.
Machine model: Raspberry Pi 3 Model B Rev 1.2
Linux version 4.4.26-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #915 SMP Thu Oct 20 17:08:44 BST 2016
Thank you,
David
try to install without libapache2-mod-auth-mysql