RaspberryPi 4 - webserver
For a few years I have had a RaspberryPi 3 running with php 5.6, 7.1, apache, webmin and virtualmin. On it some scanning software, websites and a package repository. This was all working very well webmin and virtual min were very pleasant .
The RaspberryPi 3 took me a month to setup, trying everything from noobs to ubuntu. I ended with the minimum raspbian version and as mentioned above, with webmin and virtualmin. Most packages installed flawless on the Pi3 as it had been there for a while. The raspberry pi4 did not have that history yet, so support is not always found. But the raspberry by supports php 7.1 – 7.4, and in the end it took me a month to set that up as well.
- PHP 7.1 and 7.4
- Let’s encrypt, mail etc
- Multiple domains
- SSL support
- ease of use
It took me a month to set up what I wanted, and you will not be able to do it in an hour, but these pointers should get ypu somewhere in between:
Start by prepping your SD
I have used:
- SDFormatter to format the SD and set FORMAT SIZE ADJUSTMENT to on. This way raspbian can expand the use of the SD to it’s full capacity.
- I used belenaEtcher to flash the latest downloaded Raspbian version on the SD.
- You could place a file on the SD with the name SSH and no extension in the boot partition, this would enable you to connect to the RaspberryPi with ssh (user: pi, password: raspberry).
- It is time consuming, but to save having to start from scratch I recommend making backups of your progress with Win32DiskManager after every mayor step.
Setup the Raspbian OS
After inserting the SD in the Pi and plugging in the power supply you can boot it up. Next you will either have to login with a keyboard and mouse on the RaspBerryPi or connect with ssh. Either way here are some of the tasks you could run:
- Most setups wil ask to change the password for pi but you can also create a new user and remove pi or rename the user pi.
- If you run ‘raspi-config’ in a shell you can:
- under advanced options: expand the filesystem ( use full capacity sd)
- under update, update the raspbian config
Before more steps it might be advisable to do a system update. Run the following commands over ssh:
- sudo apt-get update
- sudo apt-get dist-upgrade
Start setting up the server
First off we change the hostname:
- sudo nano /etc/hosts
Add a line with the ip for the pi, a fulldomain name and the subdomain one more time
example: 192.168.2.10 server.test.com server
- sudo nano /etc/hostname
add only the subdomain: server
Now the commands
- sudo hostname
- sudo hostname -f
Second the following commands:
- For postfix: sudo apt-get -y install postfix postfix-mysql postfix-doc
Give an enter if anything is asked (indernet-site for the first answer en the result you got for hostname -f for the second)
- For mariadb: sudo apt-get -y install mariadb-client mariadb-server
- Some bundle: sudo apt-get -y install openssl getmail4 rkhunter binutils
- And devcot: sudo apt-get -y install dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve dovecot-lmtpd
- Finish mysql setup: mysql_secure_installation
Rest from step 9: