Raspberry Pi Foundation made a fan following of millions of people because of its advanced device “Raspberry Pi”. Numerous individuals, tech-specialists, hobbyists, students, etc. use Raspberry Pi in their daily life because of its advanced features and components. One of the common questions that come from the majority of the users is about the process of installation of a web-server on Raspberry Pi. If you are one of them then you can get detailed information to install the web server in 6 easy steps.
Why should I install a web-server on Raspberry Pi?
If there are enough service providers that have the advanced machines and technology for web-hosting then why is there a need to install a web server on Raspberry Pi?
If we look at the process of installing a web server then, first of all, it is affordable and easy to use. It allows the user to cut off the middle agencies and directly set-up the server on their Raspberry Pi Board. If you take the service of web-hosting from the third parties or service providers for which the service providers would charge on a monthly or yearly basis. If we look at the pros of installing a web server on Raspberry Pi then the user has the option to customize the features of the services like memory size that would make the modifications in the existing system.
How many people want to establish a web server on Raspberry Pi after getting an understanding of the pros of Raspberry Pi-based web server.
Know more about Apache
If we look at the popularity of the web-webserver package among the users then Apache is one of the most desirable web-servers. It provides an efficient and advanced way to the people that would make the user perform their tasks in an immaculate course of action. Web-server has the work to handle the request(in HTTP form) of the user and provide corresponding data related to the request.
Books and courses
If we look at the coverage of Apache then more than 65% of people use Apache as a web-server that made more people curious about this web-server. Numerous publications helped people to enhance their skills with documentation and books.
Firstly, update the system of the machine to make the installation easy. A user needs to have the administrator rights to access the system. One can use the following methods to perform the operation.
- sudo apt-get update
- sudo apt-get upgrade
- sudo apt-get update
The above process will update the system and after this, the Apache server is ready to install.
- sudo apt-get install apache2
If you want to easily govern your sites, provide read/write access to html folder, then run the following commands
Status of Apache
Now you have successfully installed the Apache webserver on your system. A user can test the status of the web server so that they can start using the server. One needs to use Port 80 of Raspberry Pi to access the Raspberry Pi. Now open the browser of Raspberry Pi and type “http://127.0.0.1” or “localhost” in your browser. A page will be opened with a message like “It works!. You can check the status of the web server by the above method to start working with the help of the server.
You can use the following command if you do not have the GUI on your Raspberry Pi or if you use the SSH then apply the following method.
- wget -O check_apache.html http://127.0.0.1
When you run the above command then the HTML code of the page will get saved in the file “check_apache.html” in the current directory.
You can read the file by the following command
- cat ./check_apache.html
A page will get opened with the text “It works! ” which means the Apache is working well. A user needs the PHP to make the interaction between the site and user like make them a path to register themselves on the website that we will explain in detail in our upcoming blog.
How to install PHP on Raspberry Pi?
There are mainly two types of websites, static and dynamic, that people use in their life as per their requirements. If we look at the usage percentage then dynamic websites have a vast usage for the users. PHP is an open-source scripting language that makes the website dynamic that enhances the efficiency of the website. One of the biggest cons of a static website that does not adapt to the information that is provided by the user. One can follow the methods that are mentioned below to install the PHP on your system.
First, use the administrator access to install the PHP with the usage of below command line
- sudo apt install php php-mbstring
Like Apache server, the method to check the status of work of PHP is similar in which a user has to delete the file named index.html” in the directory “/var/www/html” by using the following command
- sudo rm /home/546626.cloudwaysapps.com/muxfghuehd/public_html/index.html
Now create an index.php file in the same directory with the command.
- echo “<?php phpinfo ();?>” > /home/546626.cloudwaysapps.com/muxfghuehd/public_html/index.php
Now the process is same as the Apache that will make the user to do the further process. You will see php configuration at the screen.
MySQL Database for your websites
One more thing that needs to be done is to install MySQL data for the website to store the information to make the website work better. MySQL helps the user to store the data like if one wants to check the results on their university website then the university will link the marks with the ID of the students such as their roll no and name that they can check anytime by entering their ID. One can use the following command to install MySQL.
Firstly, we will install the mariadb- server and php-mysql to make it work as a connection between the php and mysql.
- sudo apt install mariadb-server php-mysql
User need to check the status of the operation of MySQL and for that one need to follow the below command
- sudo mysql –user=root
One main thing that the user need to take care of is that the user should delete the default mysql root user and then create a new mysql root user because the default mysql root user can access only from the linux that becomes a major problem for the user. When you get connected with the MYSQL then run the below commands.
- DROP USER ‘root’@’localhost’;
- CREATE USER ‘root’@’localhost’ IDENTIFIED BY ‘password’;
- GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ WITH GRANT OPTION;
A user can change the password as per their need in the above command.
Now the web server is connected to the both PHP and MYSQL and you can use it for the further operations.