The Raspberry Pi is a versatile tool, and one of its popular uses is as a local web server. This guide will walk you through setting up a web server on your Raspberry Pi, perfect for an intranet or small development server.
Requirements:
- Raspberry Pi connected to your local network
- Raspbian operating system (recent version)
Instructions:
- Open the terminal:
- On the Raspbian desktop, press CTRL+ALT+T.
- Alternatively, connect remotely via SSH.
- Update packages:
- Type:
sudo apt-get update
- Type:
- Install Apache web server:
- Type:
sudo apt-get install apache2 -y
- Type:
- Install PHP:
- Type:
sudo apt-get install php libapache2-mod-php -y
- Type:
- Install MariaDB database (optional):
- Type:
sudo apt-get install mariadb-server
- After download, run:
sudo mysql_secure_installation
- Set a root password (optional).
- Type:
- Install PHP-MySQL connector:
- Type:
sudo apt install php-mysql
- Type:
- Restart Apache:
- Type:
sudo service apache2 restart
- Type:
- Test your server:
- Open http://localhost on the Raspberry Pi itself (test page).
- From another device on the network, try http://raspberrypi.local or http://raspberrypi (assuming the hostname is “raspberrypi”).
- Build your website:
- Place HTML or PHP files in the
/var/www/html
directory.
- Place HTML or PHP files in the
Changing the Hostname (Optional):
- Open Raspberry Pi Configuration tool:
- Type:
sudo raspi-config
(or navigate through menus).
- Type:
- Select “Network Options” -> “Hostname.”
- Enter your desired hostname and confirm.
- Reboot the Raspberry Pi (select “Finish” -> “Yes”).
Setting Up FTP (Optional):
- Enable SSH:
- Use raspi-config or navigate through menus.
- Change permissions for /var/www/html:
- Type:
sudo chown pi /var/www/html
- Type:
- Use an SFTP client on your PC:
- A popular option is Filezilla (free).
- Username: “pi”, Password: “raspberry” (default).
Note: This guide provides a basic setup. You can customize it further based on your specific needs.