How to Turn Raspberry Pi Into Web Server

Eswar
2 min readMay 23, 2021

You can use google cloud or Amazon Aws to host your script but if you like building things this project for you.

Table of Contents

After your personal web server is complete, you can use it to host a custom HTML or PHP resume, or a WordPress site on your Raspberry pi

How To

Run WordPress on Raspberry pi

Installation

  • Install Apache
sudo apt-get install apache2 -y
  • Install PHP
sudo apt install php libapache2-mod-php -y
  • Install MariaDB
sudo apt-get install mariadb-server php-mysql -y     sudo service apache2 restart
  • Download WordPress

Change directory to /var/www/html/ and delete all the files in the folder.

cd /var/www/html/
sudo rm *

Download WordPress using wget.

sudo wget http://wordpress.org/latest.tar.gz

Extract, Move, remove tarball

sudo tar xzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz

change the ownership of all these files to the Apache user:

sudo chown -R www-data: .

Set up WordPress Database

  • Set up MySQL/MariaDB
sudo mysql_secure_installation
  • Create the WordPress database
sudo mysql -uroot -p
create database wordpress;

If this has been successful, you should see this: Query OK, 1 row affected (0.00 sec)

Now grant database privileges to the root user. Note: you will need to enter your own password after IDENTIFIED BY.

GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'ENTER-YOUR-PASSWORD';

For the changes to take effect, you will need to flush the database privileges after that exit Ctrl + D. and then reboot

FLUSH PRIVILEGES;

WordPress configuration

http://localhost

keep it like this

Database Name:      wordpress
User Name: root
Password: <YOUR PASSWORD>
Database Host: localhost
Table Prefix: wp_

Click Submit to proceed.

Click the Run the install button.

Run PHP or Html script on Raspberry pi

  • Install Apache
sudo apt-get install apache2 -y
  • Install PHP
sudo apt install php libapache2-mod-php -y

Test the webserver

http://localhost/ or http://Enter your ip address

you will see a default web page is just an HTML file on the filesystem. It is located at /var/www/html/index.html

Navigate to this directory, remove the file and create a new PHP file

cd /var/www/html
sudo rm index.html
sudo nano index.php

paste and click Ctrl+ O

<?php echo "hello world"; ?>

Any doubts feel free to ask, help you to set up your own web server on raspberry pi.

--

--