Build a LAMP Web Server with WordPress
Build a LAMP Web Server with WordPress
Projects
Learn to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Raspberry Pi and configure it to work as a web
server. You’ll download and install WordPress and set up a basic website which you can access on any device on
the same network as your Pi.
By following this resource and setting up a web server and WordPress website you will learn how to:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 1/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Hardware
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 2/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.
On its own, Apache can serve HTML files over HTTP. With additional modules it can serve dynamic web pages using
scripting languages such as PHP.
Install Apache
Open a terminal window by selecting Accessories > Terminal from the menu.
Install the apache2 package by typing the following command into the terminal and pressing Enter:
By default, Apache puts a test HTML file in the web folder that you will be able to view from your Pi or another
computer on your network.
Open Chromium by selecting Internet > Chromium Web Browser from the menu.
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 3/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
You will also be able to open this web page from any other computer on your network using the IP address of your
Raspberry Pi, e.g. http://192.168.1.10.
To find out your Raspberry Pi’s IP address, type hostname -I into the terminal window. Your Raspberry Pi’s IP
address (https://www.raspberrypi.org/documentation/remote-access/ip-address.md) is a really useful and
will allow you to remotely access it.
This default web page is just a HTML file on the file system. It is located at /var/www/html/index.html.
Navigate to this directory in the terminal and have a look at what’s inside:
cd /var/www/html
ls -al
total 12
drwxr-xr-x 2 root root 4096 Jan 8 01:29 .
drwxr-xr-x 3 root root 4096 Jan 8 01:28 ..
-rw-r--r-- 1 root root 177 Jan 8 01:29 index.html
This shows that there is one file in /var/www/html/ called index.html. . refers to the directory itself
/var/www/html, and .. refers to the parent directory /var/www/.
As you can see, the html directory and index.html file are both owned by the root user, so you’ll need to use
sudo to edit them.
If you make a change to the file, save it, and refresh the browser, you will see your change appear.
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 4/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
PHP is a preprocessor: it’s code that runs when the server receives a request for a web page via a web browser. It
works out what needs to be shown on the page, and then sends that page to the browser. Unlike static HTML, PHP
can show different content under different circumstances. Other languages are also capable of doing this, but
since WordPress is written in PHP, that’s what we need to use this time. PHP is a very popular language on the web:
huge projects like Facebook and Wikipedia are written in PHP.
Test PHP
sudo rm index.html
Refresh your browser. You should see “hello world”. This page is not dynamic, but it is still served by PHP.
If you see the raw PHP above instead of “hello world”, reload and restart Apache like so:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 5/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
MariaDB is a popular database engine. Like PHP, it’s widely used on web servers, which is why projects like
WordPress use it, and why those projects are so popular.
Install the MariaDB Server and PHP-MySQL packages by entering the following command into the terminal window:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 6/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
You can download WordPress from wordpress.org (http://wordpress.org/) using the wget command. Helpfully,
a copy of the latest version of WordPress is always available at wordpress.org/latest.tar.gz (https://wordpress.o
rg/latest.tar.gz), so you can grab the latest version without having to look it up on the website. At the time of
writing, this is version 4.5.
In case you’re wondering, .tar.gz stands for ‘gzip-compressed tar archive’. gzip is a tool for compressing
files, which means reducing their size so they can be stored or distributed more easily. .tar stands for tarball,
which is a computer file format that combines and compresses multiple files. Software is often available for
download in .tar.gz format, because downloading a tarball is a lot faster than downloading the non-
compressed files.
Change directory to /var/www/html/ and delete all the files in the folder.
cd /var/www/html/
sudo rm *
Move the contents of the extracted wordpress directory to the current directory.
sudo mv wordpress/* .
Tidy up by removing the tarball and the now empty wordpress directory.
Running the ls or tree -L 1 command now will show you the contents of a WordPress project:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 7/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
.
├── index.php
├── license.txt
├── readme.html
├── wp-activate.php
├── wp-admin
├── wp-blog-header.php
├── wp-comments-post.php
├── wp-config-sample.php
├── wp-content
├── wp-cron.php
├── wp-includes
├── wp-links-opml.php
├── wp-load.php
├── wp-login.php
├── wp-mail.php
├── wp-settings.php
├── wp-signup.php
├── wp-trackback.php
└── xmlrpc.php
3 directories, 16 files
This is the source of a default WordPress installation. The files you edit to customise your installation belong in the
wp-content folder.
You should now change the ownership of all these files to the Apache user:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 8/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Set up MySQL/MariaDB
To get your WordPress site set up, you need a database. This is where MySQL and MariaDB come in!
sudo mysql_secure_installation
You will be asked Enter current password for root (enter for none): — press Enter.
Type in a password at the New password: prompt, and press Enter. Important: remember this root
password, as you will need it later to set up WordPress.
When complete, you will see the message All done! and Thanks for using MariaDB!.
Create the database for your WordPress installation at the MariaDB [(none)]> prompt using:
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 9/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Now grant database privileges to the root user. Note: you will need to enter your own password after
IDENTIFIED BY.
For the changes to take effect, you will need to flush the database privileges:
FLUSH PRIVILEGES;
sudo reboot
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 10/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Open the web browser on your Pi and goto http://localhost, you should see a WordPress page asking to
pick your language.
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 11/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
Fill out the information: give your site a title, create a username and password, and enter your email address. Hit
the Install WordPress button, then log in using the account you just created.
Now you’re logged in and have your site set up, you can see the website by visiting your http://localhost/wp-
admin.
To log in from another computer, open a browser and go to http://PI-IP-ADDRESS/wp-admin, using your
Pi’s IP address.
hostname -I
Friendly permalinks
It’s recommended that you change your permalink settings to make your URLs more friendly.
You’ll also need to tell the virtual host serving the site to allow requests to be overwritten.
<Directory "/var/www/html">
AllowOverride All
</Directory>
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 12/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
<VirtualHost *:80>
<Directory "/var/www/html">
AllowOverride All
</Directory>
...
Restart Apache.
Customisation
WordPress is very customisable. By clicking your site name in the WordPress banner at the top of the page (when
logged you’re in), you’ll be taken to the Dashboard. From there, you can change the theme, add pages and posts,
edit the menu, add plugins, and lots more. This is just a taster for getting something interesting set up on the
Raspberry Pi’s web server.
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 13/14
30/09/2024, 15:07 Build a LAMP Web Server with WordPress
https://projects.raspberrypi.org/en/projects/lamp-web-server-with-wordpress/print 14/14