Convert Pi to a personal web server
Making your Raspberry Pi to act as a personal web server is an excellent option as it allows them to deliver their contents on their personal website. If you are eager to create your own web server, then you should read this article that will lead you to transform your Pi to a personal web server.
To successfully convert your Pi into a personal web server, you will need to look at the below given steps which you will have to execute through the terminal of your Raspberry Pi device.
Step 1: Turn on your Raspberry Pi device through an external power supply and make sure that the power supply will be good enough in order to make Raspberry Pi running for a longer time. If the power supply won’t provide enough voltage to the device, it might turn off and your installation will stop during that time.
Step 2: Now, the next step is to ensure that your Raspberry Pi has the latest version of packages and in order to do that you should execute the below mentioned command in the terminal of Raspberry Pi:
Step 3: After the update, you will also be required to run the upgrade command to ensure that your packages will be upgraded and to perform this step, execute the below mentioned command in the terminal:
Step 4: After performing the above steps, you will now be required to install Apache in your Pi device as Apache will handle all your network traffic and ensure that you will run a website without any worry. In order to install Apache, you will need to execute the following command:
The above command will install the Apache in Raspberry Pi.
Step 5: Now, in order to ensure that your function on your website goes well, you will need to install PHP in your Raspberry Pi device as PHP will allow you the freedom to select your web server according to your choice and it will also help you to connect with your database. To successfully install PHP, you will be required to execute some commands which are given below.
Now, you will need to install GPG key which you will find in Repository of PHP and following command will be required to be executed in the terminal:
After successfully saving the key, you will now need to create a source file that will point towards this repository and to do this, execute the following command in the terminal:
After adding the packages, it will be necessary to execute the update command in the terminal:
Then, run the “upgrade” command to ensure packages are upgraded:
Now, you are ready to install PHP through its repository using the below mentioned command which will need to be executed in the terminal.
Step 5: Now you will need to integrate PHP with MySQL in the next step using the below mentioned command:
Step 6: Next, integrate PHP with Apache through the below given command:
Step 7: After performing the above steps without encountering an error, you will now need to download the MariaDB server, which will provide you with more storage engines. To have it downloaded on your Raspberry Pi device, you will need to execute the command mentioned below in the terminal:
Step 8: After the installation of MariaDB server, you will need to secure your database through executing the below mentioned command in the terminal:
When you execute the above command in the terminal, you will be asked to press “y” or “n” on some process, it’s up to your which you want to opt, in our case we first enter the password and in the next two steps we choose “n” option while in the rest option we select “y”. You can go with our choices if you are unaware of what to do. The images of our selections are provided below.
Step 9: Next, you will have to restart the Apache service using the below given command in the terminal:
Step 10: In the next step, it is necessary to check whether Apache is running or not and to do this you will need to execute the given command in the terminal:
Step 11: Now, you are required to enter the Raspberry Pi device IP address in order to check your website. To find the device IP address, you will need to run the below given command in the terminal.
After finding the host IP address, open any browser whether from the device or from your laptop or PC and add the above IP “192.168.43.96” into the browser’s address bar. As soon as you enter the IP address on your browser, you will see the default apache’s web page as shown below.
Step 12: Now, the next thing is to start creating your personal web page and in order to do that, you will need to find the html directory into your Raspberry Pi system. Enter “/var/www/html” in the Raspberry Pi directory search box.
Step 13: The website developing on your Pi device is possible through PHP and you can create a PHP webpage in the folder where your html file is placed. To perform this step, you will need to add the command in the terminal which is given below:
When you press enter, a file will be open on your terminal screen with the name “index.php”. You will need to write PHP code in it so that it will be displayed on your website.
After entering, you will then need to save it using “Ctrl+X” then enter “Y” and press enter again to save the changes to the file.
Step 13: In the final step, enter the same IP address on any browser along with the file name after forward slash and this time, you will see that your website has changed and the message will appear on your browser which you have typed in the above file as shown below.
Raspberry Pi device is all in one a handy tool that can be pretty cool if used as a web server where you can easily build your own websites through PHP. The aforementioned methods will provide significant guidance in creating your own webpage in a few minutes. To turn Raspberry Pi into a web server you will need to ensure that different technologies are installed properly such as Apache web server (to host a webpage), database management system MariaDB (database management system) and PHP (server side language). After having these technologies on Raspberry Pi you can easily develop and host a webpage. If you want to view the webpage from another desktop browser, you should provide an IP address with the PHP file name to access the webpage.