Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

How to set up a web server on your Raspberry Pi? When setting up the server, it is necessary to install updates, but as you may know, the default mirror source for Raspberry Pi is in the UK, which can be slow to access from within China. Therefore, you need to change the mirror source to a domestic one. The official website provides 9 domestic mirror sources, Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Connect to the Raspberry Pi via SSH over the network, and use nano to open the /etc/apt/sources.list file for editing.

First, back up the source file before editing.

Change the system’s mirror source to domestic using the cp command to back up the source file /etc/apt/sources.list to /etc/apt/sources.list.old.

Change the contents of sources.list as follows; change to the domestic Tsinghua University mirror site, then press ctrl+O to save and ctrl+x to exit.

Nowadays, Apache has slowly become the most popular web server software on the Internet, so we will use apache2 to set it up. First, install apache2.

In the command line terminal, enter the command sudo apt-get install apache2 -y.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Enter your Raspberry Pi’s IP address in the browser. If the following test page appears, it means the Apache software is working properly.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

In fact, the entire displayed interface is an html file located in the /var/www/html folder.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

You can edit the html file, refresh the browser page, and see the changes.

Delete the original test index.html file and create a new index.php.

You can write the following code:

<?php echo "hello world,welcome!"; ?>

Save and exit, then refresh the browser.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Modify the content of index.php to show the time, allowing dynamic refresh to observe changes in the browser.

If you need our Apache server to process PHP files, you need to install PHP5.

The installation command is:

sudo apt-get install php5 libapache2-mod-php5 -y

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Install mysql.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Enter the password.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Restart apache2.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

We also need WordPress, so download and install WordPress.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Unzip.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Create a database and set a password if possible.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Press ctrl+D to exit the MySQL command line.

Configuration:

In the browser, enter your PI‘s IP address and wait for the language selection to appear below.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi Click continue and fill in the username and password.

Step-by-Step Guide to Setting Up a Web Server on Raspberry PiStep-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Log in Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi Edit the configuration file.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Restart apache2.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi All done, refresh the browser and test our results.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Add new interfaces and change the background color. You can also add more elements to make your site more attractive.

Step-by-Step Guide to Setting Up a Web Server on Raspberry Pi

Alright, this proves that our setup is successful. This tutorial contains a lot of content and requires various software installations and configurations. Those interested should study it thoroughly. Stay tuned for more exciting content from the Embedded Programmer.

Leave a Comment