How To Raspberry Pi

How to: Beginners guide to setup a website on Raspberry Pi

A Raspberry Pi

The Raspberry Pi is a tiny and affordable computer that you can use to learn programming through fun, practical projects. Given it’s low cost the Raspberry Pi is also used by tech enthusiasts to do a myriad of cool and useful project. 

How to: Beginners guide to setup a website on Raspberry Pi 1
Raspberry Pi 3b+ – a pocket sized computer

In this step by step guide we look at setting up a website on a Raspberry Pi. 

This can be done using several methods but we’re going to use the LAMP stack to configure a locally hosted website.

LAMP is a collection (called stack) of open-source software that is used to setup a web server, it’s an acronym that stands for

How to: Beginners guide to setup a website on Raspberry Pi 2

L – Linux

A – Apache

M – MySQL

P – PHP


Step 1 – Update Raspberry Pi

Update the Raspberry Pi software by running the following commands in the terminal

sudo aptitude update && sudo aptitude upgrade && sudo aptitude dist-upgrade

Step 2 – Install LAMP 

Install the LAMP webserver components by running 

sudo aptitude install apache2 php7.0 mysql-server php-mysql -y

You can test the config by opening you browser and typing http://localhost as the address (as shown below)

How to: Beginners guide to setup a website on Raspberry Pi 3

This will load the default Apache index.html page (as shown below)

How to: Beginners guide to setup a website on Raspberry Pi 4

Step 3 – Download WordPress

Next we download the WordPress application 

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

Unzip the tar file

sudo tar xzf latest.tar.gz

Move the extracted folder to the /var/www/

sudo mv wordpress /var/www/wordpress

Step 4 – Configure webroot

We first delete the existing html folder containing apache files and rename the wordpress folder to html

sudo rm -rf html
sudo mv wordpress html

Configure file ownerships

sudo chown -R www-data:www-data html

Step 5 – Configure MySQL

Start the MySQL configuration 

sudo mysql_secure_installation

You will be asked:

Enter current password for root (enter for none):

Press Enter

Set root password?

Type Y and then press Enter
Then type in the new password for your MySQL database, and do the following when prompted

Remove Anonymous Users – Type Y
Disallow root login remotely – Type Y
Remove test database and access to it – Type Y
Reload privilege tables now – Type Y

We now will create a WordPress database

Login in to MySQL

sudo mysql -u root -p

Enter the MySQL Root password you created earlier (this is not your Raspberry Pi account password)

You will get a prompt “Welcome to the MariaDB monitor”

How to: Beginners guide to setup a website on Raspberry Pi 5

Now create a database 

create database wordpress;

Ensure everything is in lowercase and note the semi-colon.

Grant priviledges,

GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'YOURPASSWORD';

You need to replace ‘YOURPASSWORD’ with the password that you created for MySQL root user earlier.
Now flush and apply the priviledges, note the spelling of “privileges” below.

FLUSH PRIVILEGES;

Type exit and press enter to exit MariaDB

Step 6 – Configure WordPress

Open your browser and type http://localhost to open the WordPress configuration, first it will ask for language selection

How to: Beginners guide to setup a website on Raspberry Pi 6

Select the language you want to setup your website in and press continue, for this example we’re assuming you selected English (United States), this will bring up the welcome screen. Click on let’s go

How to: Beginners guide to setup a website on Raspberry Pi 7

Now fill up the following details when asked for

How to: Beginners guide to setup a website on Raspberry Pi 8

Replace “username” and “password” with the database username (“root”) and the password that was created earlier

Click “Submit”  and then “Run the Install”

Fill up the login details and click on “Install WordPress”

How to: Beginners guide to setup a website on Raspberry Pi 9

Now type http://localhost/admin in the browser to access the WordPress admin area to make changes.

How to: Beginners guide to setup a website on Raspberry Pi 10

That’s it!

The default wordpress theme and Hello Word page can be opened by typing http://localhost in the browser.


ALSO READ  Use Serveo.net to access your Raspberry Pi from internet

Leave a Reply

avatar
  Subscribe  
Notify of