The Raspberry Pi is a powerful tool that offers many benefits at a low cost. It can be configured for a multitude of projects, including a web server.The Raspberry Pi has established itself as one of the best single-boards on the market thanks to its powerful features, versatile hardware and wide range of applications that make it an indispensable tool for thousands of developers and hobbyists alike.
However, what you may not know is that you can also configure the Raspberry Pi board into a web server . This way, you can test your website or manage your own files and make them accessible in the cloud in a secure and private way.
Steps to create a web server with Raspberry Pi
It should be noted that to convert your Raspberry Pi into a server for your website , you will need some essential elements, such as the single board, any model, but the Raspberry Pi 4 is recommended .
A microSD card of at least 8GB to install the 64-bit operating system and web server files. It is important to mention that you must download and flash the Raspberry Pi system image instead of an ARM Ubuntu image , this is essential.
- Step 1: Setting up the web server. Start by downloading and installing the Raspberry Pi OS (64-bit) to your microSD card. You can find the OS image on the official Raspberry Pi website . Follow the installation instructions.
- Step 2: Run sudo apt update and then sudo apt upgrade to ensure you have the latest system updates.
- Step 3: Once the operating system is installed and updated to the latest version, it is time to configure the Apache web server. To do so, open the terminal and run the following command: sudo apt install apache2 -y .
- Step 4: Install MariaDB server: sudo apt-get install mariadb-server -y .
- Step 5: If you plan to run PHP scripts on your web server, install PHP and the Apache module for PHP with the following command: sudo apt install php libapache2-mod-php -y .
- Step 6: Next up is adding the PHP-MySQL module. This is for web pages written in PHP to store and retrieve data from MariaDB logs, so type the following: sudo apt install php-mysql -y .
- Step 7: Now, it’s time to configure all the web files that will be inside the Apache web server. Open the File Manager and go to the directory: /var/www/html/ .
- Step 8: You must grant permissions to modify the files in the html folder, and this is achieved with the chown command: sudo chown -R pi_user /var/www/html .
- Step 9: At this point you need to replace pi_user with the username you set during the OS setup and paste all your project files inside this folder.
- Step 10 : It is time to run the Apache server with this command: sudo service apache2 start .
Now, after the above, the most important moment of the procedure has arrived, which is to carry out the connection to the web page hosted on the single board.
The first step is essential, and it is to know the IP address of your Raspberry Pi, in this case, you must type ifconfig in the terminal and copy the number that appears next to inet .
The next step is to use a Windows PC and open any web browser, then type the IP address in the address bar. Alternatively, if you are on the single board, you can access the web using the URL: localhost.Once your web server is up and running, you can host your website on the Raspberry Pi . Simply place your files in the /var/www/html/ directory in the file manager, and you can access your website from any device connected to the same network.