Skip to content

J. Web Server

Bogdan Tudorache edited this page Jan 17, 2021 · 3 revisions

Apache

Can serve HTML files over HTTP and also over HTTPS protocols. With additional modules such as PHP it can also server dynamic content. Apache is one of the most popular web servers available for Raspberry PI, alternatively we can use Nginx web server, but for this exercise we will stick to LAMP framework.

# But wait?! What is this LAMP?

Funny enough, you've been already using it and we already installed 75% of it.

L - Linux

A - Apache

M - MySQL/MariaDB

P - Python/PHP/Perl

Citing Wikipedia:

"LAMP (Linux, Apache, MySQL, PHP/Perl/Python) is a very common example of a web service stack, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system (RDBMS), and the PHP programming language. The LAMP components are largely interchangeable and not limited to the original selection. As a solution stack, LAMP is suitable for building dynamic web sites and web applications."

A. Installing Apache

Luckily, we already did this here. So we can skip this step.

Proof:

  1. Open a terminal and type:

    $ hostname -i

  2. Now take that ip (192.168.x.x) , in my case 192.168.1.31 and paste it in any browser.

  • What do you see?

  • I think we're both going to be greeted with the same page and message: It works!

Sure it does, we're smart like that ๐Ÿš€๐Ÿ”ฅ.

Apache_proof

B. Configuration

I'm going to be using the sambullet pointsts from above we this is more of a continuation, not a separate chapter.

  1. We must set up permissions to be able to make changes within the /var/www/html without using root.

    a. First, we must add our user: ubuntu to the www-data group. Ubuntu should be default, but if you you don't know your user or you changed it in the meantime just type in the terminal $ whoami.

    b. Second, we must give ownership to all the files from the folders in /var/www/html directory to the www-data group.

    ubuntu: ubuntu/ :sudo usermod -a -G www-data ubuntu

    ubuntu: ubuntu/ :sudo chown -R -f www-data:www-data /var/www/html

  2. Close your terminal and reopen for the changes to take effect.

C. Testing

  1. You can now make changes to the default web page by using nano or vim.

    vim /var/www/html/index.html

Result ๐ŸŽ–:

Welcome_Apache


                                            **Congrats, you're done!**

Conclusion

We have learned about the LAMP stack and finished implementing it.

We have also learned how to give permissions to modify the index.html in order to create our own webpage.

If you hit a problem or have feedback (which is highly welcomed) please feel free to get in touch, more details in the footer.