1. Install Apache and PHP
Before you can install WordPress, you need to install Apache and PHP on your Raspberry Pi. To do this, open a terminal window and type the following command:
sudo apt-get install apache2 php5 libapache2-mod-php5
2. Install MySQL
WordPress requires a database to store its data. To install MySQL, type the following command in the terminal window:
sudo apt-get install mysql-server php5-mysql
3. Create a Database
Once MySQL is installed, you need to create a database for WordPress. To do this, type the following command in the terminal window:
mysql -u root -p
You will be prompted to enter a password. Once you have entered the password, type the following command to create a database:
CREATE DATABASE wordpress;
4. Download WordPress
Now that you have installed Apache, PHP, and MySQL, you can download WordPress. To do this, type the following command in the terminal window:
wget http://wordpress.org/latest.tar.gz
5. Extract the Files
Once the download is complete, you need to extract the files. To do this, type the following command in the terminal window:
tar -xzvf latest.tar.gz
6. Move the Files
Now that the files have been extracted, you need to move them to the correct directory. To do this, type the following command in the terminal window:
sudo mv wordpress /var/www/html
7. Configure WordPress
Now that the files have been moved, you need to configure WordPress. To do this, type the following command in the terminal window:
sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
8. Edit the Configuration File
Now that the configuration file has been copied, you need to edit it. To do this, type the following command in the terminal window:
sudo nano /var/www/html/wordpress/wp-config.php
9. Install WordPress
Now that the configuration file has been edited, you can install WordPress. To do this, open a web browser and go to http://localhost/wordpress. Follow the instructions to complete the installation.
WordPress is an interesting tool to manage a website (I know what I’m talking about, this website is running on WordPress!). It’s possible to install it on Raspberry Pi, and I will share with you an ultimate guide to install a functional WordPress on Raspberry Pi from scratch.
To install WordPress on a Raspberry Pi, three services should be installed first: Apache, MySQL and PHP.
Then WordPress can be downloaded on the official website and the files extracted into the web directory of the Raspberry Pi (/var/www).
I’m going to assume that your Raspberry Pi is empty, or that you want to reinstall one just for WordPress.
So, here you have the necessary information to start from scratch.
If this isn’t the case, and you’ve already completed some steps, you can use the summary below to start where you left off.
If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
Install Raspberry Pi OS
I have an entire article on how to install Raspberry Pi OS that you can check first if you want, but I’ll give you the short version here.
Download Raspberry Pi OS
First, you need to download the latest version of Raspberry Pi OS from the official website.
If you only want to install WordPress, the lite version may be enough. You’ll have to install it without the GUI, but it shouldn’t be too complicated.
Download the image and continue.
Flash an SD Card with Raspberry Pi OS
Then I recommend using Etcher.
If you haven’t installed it yet, get it from the official website.
It’s a tool that allows you to flash an SD card easily on Linux, Mac, or Windows.
- Start Etcher.
- Select the location of the Raspberry Pi OS image.
- Choose your SD card.
- Click on Flash.
Once the SD card is ready, eject it and insert in your Raspberry Pi.
First Boot
The installation is automatic, you just have to start your Raspberry Pi, and Raspberry Pi OS will launch.
GUI
If you chose the Desktop version, a welcome menu will open:
- Choose your language preferences.
- Change the default password.
- Connect to the Wi-Fi if necessary.
- Accept system updates.
- Reboot the Raspberry Pi.
If everything works fine, you can move on.
Otherwise, it will be required at least to succeed to connect the network and to change the password (the following paragraph can help you).
Lite
If you chose the lite version, you’ll have to do the same thing but by hand.
- Login:
- Default login: pi
- Default password: raspberry
- Change the password:
passwd
- Use raspi-config to configure network and change language preferences if needed (nothing to do if Ethernet with DHCP):
sudo raspi-config
- Once connected to the Internet, update your system:
sudo apt-get update
sudo apt-get upgrade - Reboot.
If everything is ok, you can move on.
Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.
Enable SSH
SSH is a secure remote connection protocol, which allows you to launch commands from another computer on the network.
Unless it isn’t possible for you, I strongly recommend using SSH for the rest of this guide.
It will be much simpler to copy commands, test, etc. from your usual computer.
By default, the service doesn’t start on Raspberry Pi.
So we will enable SSH and connect to it before continuing.
GUI
To enable SSH through the GUI, go to the applications menu, then Preferences > Raspberry Pi Configuration > Interfaces.
Check Enabled for the SSH line.
Terminal
You can also launch the terminal and type this command:sudo service ssh start
Autorun at each boot
The SSH service doesn’t start automatically when the Raspberry Pi is started.
If necessary you can start it with each reboot, by typing this command:sudo crontab -e
And adding this line:@reboot /usr/sbin/service ssh start
Connect
You can now connect to your Raspberry Pi in SSH.
If you aren’t familiar with SSH, I recommend you read my two articles about it before continuing:
– How to connect in SSH?
– What is the IP address of my Raspberry Pi?
Install a web server (Apache, PHP)
Introduction
WordPress is a web application, written in PHP.
We need a web server to make it available so that we will set up all the components of a LAMP server:
– L: Linux (Raspberry Pi OS)
– A: Apache
– M: Mysql (MariaDB)
– P: PHP
We already have the “L” in place with our Raspberry Pi OS installation, so let’s go to Apache.
Install Apache
Apache is the most popular web server on the internet.
Its role is to provide visitors with HTML files that will then be interpreted by browsers.
Install Apache with apt:
sudo apt-get install apache2
It works!
You can now navigate to the default web page by typing the IP address of the Raspberry Pi into a browser (http: //X.X.X.X).
You should see something like this:
Install PHP
PHP is a programming language, which will allows you to create dynamic web pages (e.g. display to add your name dynamically in the page).
We need to install PHP and allow Apache to use it:
sudo apt-get install php
Hello world
To make sure that PHP is active, we will do the following test:
Then go to http://X.X.X.X/test.php and watch.
It should display only “Hello World!”.
If so, everything works fine so far; you can move on.
Install a database server (MariaDB)
Introduction
We are now able to create a website in HTML and PHP.
But WordPress needs a little more; it requires a database to store all posts, pages, and configurations
For that, we will install MariaDB, a free fork of MySQL which exists since the acquisition of MySQL by Oracle
Installation
To install it, nothing more simple, let’s use again apt:
sudo apt-get install mariadb-server
It takes a little longer than the previous ones :).
Configuration
Access to the database is protected by a password, which may be different from the one of the users.
By default, only the root user has access without a password from their account. So, we will connect to it and create a new account for WordPress.
- Connect to the MySQL CLI:
sudo mysql -uroot
- Create a new user:
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
- Create a new database:
CREATE DATABASE wordpress;
- Give WordPress user all privileges on the new database:
GRANT ALL ON wordpress.* TO 'wordpress'@'localhost';
- Quit the MySQL CLI:
quit
PHP MySQL package
To allow PHP to connect to MySQL, a last small package must be installed:
sudo apt-get install php-mysql
Restart Apache to apply:
sudo service apache2 restart
Test
Again, let’s do a quick test to make sure the connection is functional:
- Try to connect to MySQL.
mysql -u wordpress -p
- Enter the user password.
- Check if the user can view the new database:
SHOW DATABASES;
- Quit:
quit
If you see at least the WordPress database, then you can continue and move to the WordPress installation itself.
If you want to learn more about the database server, I have an entire article about it that you can find here.
Install WordPress
Download
WordPress offers its software under two versions:
- A version hosted on their servers, WordPress.com.
- A version to download, WordPress.org.
So you have to use the second option to use it on your Raspberry Pi.
Download WordPress from the official website.
Copy the link (right click on it) and download it to the Raspberry Pi via SSH:
sudo wget https://wordpress.org/latest.zip -O /var/www/html/wordpress.zip
Uncompress
Move to the web folder and uncompress the file:
cd /var/www/html sudo unzip wordpress.zip
Permissions
To avoid permissions problems with WordPress, and to avoid using the sudo later, we can modify the rights on the WordPress files:
sudo chmod 755 wordpress -R sudo chown www-data wordpress -R
This will give full permissions to Apache, and read/execution to others.
Configuration
The WordPress code is now in place; it remains only to configure it, i.e.:
- Configure the connection to the database.
- Create a login for the administration of WordPress.
Access the installation wizard by pointing your browser at http://X.X.X.X/wordpress:
Click Let’s Go Button.
On the next screen, fill the form with the MySQL user created before.
You should have something like this:
Validate, and the wizard will ask you to run the installation.
Click the button and wait.
On the next screen you have to choose the site name, and create the administrator user:
Fill in the fields with what you want, then validate.
It will take a few moments.
Here we are!
The configuration is complete! You can go back to the address http://X.X.X.X/wordpress to see your WordPress website live!
The wizard offers you to go directly to the administration page, which we will talk about next.
Extra Tips for WordPress
WordPress introduction
I won’t go into much detail in using WordPress; this is not the goal here.
But now that it’s installed, I will give you two or three tips to get started.
Admin and Front
WordPress is composed of two parts:
- Administration: accessible by adding /wp-admin to the URL, it allows you to configure your site and add content.
- Front: this is the part visible to all visitors.
When you are logged in, the top bar allows you to switch from one to the other easily.
Appearance
WordPress comes with a basic design, but it’s possible to customize your site as you wish.
To get started, go to Appearance> Themes.
Here you can add free themes from the list.
In the Appearance menu, you can also manage your site menus and widgets.
A widget is a block that can be integrated into the sidebar for example to display a search engine or an image.
Plugins
Similar to Raspberry Pi, WordPress provides a scalable foundation.
You can install plugins, to add additional features to your website or your admin.
Go to Plugins > Add new to see a list of all plugins available.
Pages and Posts
Once your site is personalized, it’s time to add content.
For this you can create two types of content:
- Pages: These are static pages, which contain content. For example your homepage or a contact form.
- Posts: that’s all the rest of the content, they are grouped into categories to make it easier for users to search later.
You will be able to add your pages and categories to your menus, and the posts will appear automatically.
Services management
Let’s go back to our services that allow you to run WordPress: Apache, PHP, and MySQL.
You need to know that there are commands to start or stop these services.
This may be useful in case of a crash, or if you want to stop them to cut access to the site.
Here are the commands:
sudo service apache2 start | stop | restart | reload sudo service mysql start | stop | restart | reload
As I said above, PHP is a module of Apache, so there is no particular command to launch.
If Apache is running, the PHP pages will be displayed correctly.
Services configuration files
I will also tell you where to find the configuration files if you ever want or need to make changes:
Apache : /etc/apache2
PHP : /etc/php
MySQL : /etc/mysql
In a WordPress installation, you normally don’t need to touch the configuration.
But if this article makes you want to try other things, it could be useful.
PHPMyAdmin
PHPMyAdmin is a handy tool that you can use on a LAMP installation.
This is a web interface that will allow you to access your MySQL databases in a more intuitive way.
You will be able to view and modify the data, create users, manage rights and supervise the MySQL server.
To install it, use the following command:
sudo apt-get install phpmyadmin
Choose apache2 as your web server when asked.
You can skip database configuration.
Once the installation is complete, the interface is available at http://X.X.X.X/phpmyadmin.
Log in with your WordPress account to see the WordPress database.
Share the website on the Internet
If you want to share this newly created website on the internet, it is quite possible.
You simply have to redirect a port from your internet box on the port 80 of Raspberry Pi = to be able to connect to the site by using the public IP address of your Internet connection:
Public IP:PORT => Raspberry Pi IP: 80
So you can access the website with http://Y.Y.Y.Y:PORT/wordpress.
Y.Y.Y.Y is your public IP, and PORT the port you choose.
If you do not have a fixed IP address, you can inquire about dynamic DNS services that allow you to use a web address that will be constantly updated with your new IP address.
Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.
Conclusion
So you learned to install a LAMP server on Raspberry Pi and to install WordPress to use it.
You also had some tips to go further with your installation of WordPress.
I was pleasantly surprised to see that WordPress works pretty well on Raspberry Pi, while it happens to be rather slow on some professional web hosting.
Can be a project idea to think about!
If your WordPress site is important, like with real traffic from remote users (not only you), it’s probably a good idea to put something in place to monitor it. You can read my article on the topic here: The Definitive Guide To Monitor A Website On Raspberry Pi
Additional Resources
Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now.
Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.
Download the e-book.
VIP Community
If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.
Need help building something with Python?
Create, understand, and improve any Python script for your Raspberry Pi.
Learn the essentials step-by-step without losing time understanding useless concepts.
Get the e-book now.
You can also find all my recommendations for tools and hardware on this page.
Step-by-Step Guide to Install WordPress on a Raspberry Pi
WordPress is one of the most popular content management systems (CMS) in the world. It is used by millions of websites and blogs, and is a great way to create a website or blog quickly and easily. If you have a Raspberry Pi, you can install WordPress on it and use it as a web server. This guide will show you how to install WordPress on a Raspberry Pi.
Step 1: Install Raspbian
The first step is to install Raspbian, the official operating system for the Raspberry Pi. You can download the latest version of Raspbian from the Raspberry Pi website. Once you have downloaded the image, you can write it to an SD card using a tool such as Etcher.
Step 2: Configure Raspbian
Once you have installed Raspbian, you need to configure it. This includes setting up the network connection, setting the timezone, and enabling SSH. You can do this by running the raspi-config command in the terminal.
Step 3: Install Apache
The next step is to install Apache, the web server software that will be used to serve the WordPress website. You can install Apache by running the following command in the terminal:
sudo apt-get install apache2
Step 4: Install MySQL
WordPress requires a database to store its data. The most popular database for WordPress is MySQL. You can install MySQL by running the following command in the terminal:
sudo apt-get install mysql-server
Step 5: Install PHP
WordPress is written in the PHP programming language. You can install PHP by running the following command in the terminal:
sudo apt-get install php libapache2-mod-php php-mysql
Step 6: Download WordPress
The next step is to download the latest version of WordPress. You can do this by visiting the WordPress website and downloading the latest version. Once you have downloaded the file, you can extract it to the /var/www/html directory.
Step 7: Configure WordPress
The final step is to configure WordPress. You can do this by running the following command in the terminal:
sudo mv wp-config-sample.php wp-config.php
This will create a new configuration file for WordPress. You will need to edit this file and enter your database details. Once you have done this, you can access the WordPress website by visiting http://localhost in your web browser.