In this tutorial we will see how to make LAMP web server with WordPress by using Raspberry Pi 4. we will setup LAMP (Linux, Apache, MySQL, PHP) stack on our Raspberry pi and configure it to work as a web server. In addition, setup basic website by downloading & installing WordPress. You can access your website on any device connected on same network as your raspberry pi. So let’s get started.

Components Required:

  1. Raspberry pi 4,
  2. Dual Fan Heat Sink aluminium Armor Case. (Optional)

Apache Web Server:

open terminal and type.

sudo apt update

Install Apache2 by following command

sudo apt-get install apache2 -y
Test Web Server:

Open web browser and type http://localhost in raspberry pi. If you want to access this web page from another computer on same network as of raspberry pi. Type IP address of Pi in web browser. You can find IP address of pi by typing command in terminal hostname -I

You can see this web page means apache is working.

Apache is working

Install Leafpad:

Leafpad is an open source text editor for Linux. If you haven’t installed leafpad yet, you can install it by typing following command.

sudo apt-get install leafpad
Edit Web Page:

You can edit the web page, for editing web page you need to go directory /var/www/html/

cd /var/www/html

You can edit file by using leafpad.

sudo leafpad index.html

Edit and click save file. Refresh web page to see changes.

Installing PHP:

Install PHP package type command.

sudo apt-get install php -y
Testing PHP:

First go to directory /var/www/html/

cd /var/www/html

Creating a file index.php

sudo leafpad index.php

Enter some content for PHP.

<?php echo "hello world"; ?>

Save the file and Delete index.html file because it takes precedence over index.php

for removing index.html file you need to type following command.

sudo rm index.html

Refresh your web page, you can see “hello world” in your web page.

If you don’t see “hello world”. Restart Apache.

sudo service apache2 restart

Installing MySQL:

Type this command:

sudo apt-get install mysql-server php-mysql -y

Most probably you will get error like this. So I am installing alternative of MySQL. i.e MariaDB

Error when Installing MySQL

Installing MariaDB:

Installing MariaDB so that you can use a mysql database with your website. Type following command.

sudo apt-get install mariadb-server

After downloading, you must do formal install by typing this command

sudo mysql_secure_installation

You will be asked Enter current password for root (enter for none): — press Enter.

Type in Y and press Enter to Set root password?.

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.

Type in Y to Remove anonymous users.

Type in Y to Disallow root login remotely.

Type in Y to Remove test database and access to it.

Type in Y to Reload privilege tables now.

When complete, you will see the message All done! and Thanks for using MariaDB!.

Installing php-mysql connector:

Installing the php-mysql connector so php pages can access the DB.

sudo apt install php-mysql

Restart apache2 so that all the changes are running.

sudo service apache2 restart

Downloading WordPress:

Go to directory and delete file in html folder.

cd /var/www/html/
sudo rm *

Download WordPress using wget, type this command.

sudo wget

Extract the WordPress tarball to get at the WordPress files.

sudo tar xzf latest.tar.gz

Move the contents of the extracted WordPress directory to the current directory.

sudo mv wordpress/* .

Clean up by removing the tarball and the now empty WordPress directory.

sudo rm -rf wordpress latest.tar.gz

Running this command will show you WordPress content.

tree -L 1

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

sudo chown -R www-data: .

Create the WordPress database:

Go to directory var/www/html

cd /var/www/html/

Run mysql in the terminal window:

sudo mysql -uroot -p

Enter the root password you have created earlier.

Create the database for your WordPress installation at the MariaDB [(none)]> prompt using:

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.


For the changes to take effect, you will need to flush the database privileges:


Exit the MariaDB prompt with Ctrl + D.

WordPress configuration:

Open web browser in Raspberry pi and type http://localhost. You will see WordPress web page asking for select language, click continue.

Configure page

Database Name: wordpress

User Name: root


Database Host: localhost

Table Prefix: wp_

Click Submit to proceed.

Database connection

Fill out the information and Click the install WordPress button.

Install WordPress

Friendly permalinks:

change your permalink settings to make your URLs more friendly.

To do this, log in to WordPress and go to the dashboard.

Go to Setting, then Permalinks.

Select the Post name option and click Save Changes.

You’ll need to enable Apache’s rewrite mod:

sudo a2enmod rewrite

You’ll also need to tell the virtual host serving the site to allow requests to be overwritten.

Edit the Apache configuration file for your virtual host:

sudo leafpad /etc/apache2/sites-available/000-default.conf

Add the following lines after line 1.

<Directory "/var/www/html">
    AllowOverride All

Ensure it’s within the <VirtualHost *:80> like so:

Add these lines in Config file

Save the file and exit.

Restart Apache.

sudo service apache2 restart

Customize Website:

You can add posts, pages & change theme many more.

raspberry pi 4 wordpress


For more content like this please subscribe to my YouTube Channel for latest updates. Till Then Keep Learning Keep Making.