Install WordPress Blog on Raspberry Pi

*UPDATED* December 2017 for Raspbian Stretch. The Pi’s low power consumption makes it well suited to the role of always-on web server. This post describes how to install WordPress on the Raspberry Pi and get a blog going. Hosting your own blog means you keep ownership of your own data, and you are not dependant on blogger.com or whoever.

If you have already installed WordPress and just want to upgrade it, perhaps because a new version has been released, please see my article How to Upgrade WordPress on Linux

This procedure is designed for Pis running Raspbian 9 (“Stretch”), released in Summer 2017, and has been tested on the 29th November 2017 release.

Install Apache

Install the Apache web server with these commands. It might take 10 minutes or so to complete. A few other packages will also be installed.

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install apache2

Now install PHP by typing:

pi@raspberrypi ~ $ sudo apt-get install php7.0

A number of dependant and associated packages will also be installed.

Install the MySQL Database

WordPress keeps all of your posts and other data in a MySQL database. Install MySQL. We will use the “-y” flag this time, to automatically answers “yes” to the yes/no install question.

pi@raspberrypi ~ $ sudo apt-get install -y mysql-server

Be patient while the database installation completes. It can take about 10 minutes.

Increase MySQL Security

Now secure the MySQL installation. Run the script /usr/bin/mysql_secure_installation. It will first ask you to enter the “current password for root”. No password has been set yet, so just press return to log in. Next, it asks you if you want to set a root password. Answer “y“, choose a sensible password and make a note of it. Then answer “y” to all of the remaining questions, as below.

pi@raspberrypi:~ $ sudo /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
...
Thanks for using MariaDB!

Test the Database

Test the MySQL installation by logging into MySQL and out again. It will ask for the password chosen earlier:

pi@raspberrypi:~ $ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> exit
Bye

It works!

Create the Database

Create the database and create a user for WordPress. Again you must enter the password. In the example I have called the wordpress user “wpfred” with a password of raindrop. For your own installation, choose a different user name and password. Don’t forget to take a note of both.

pi@raspberrypi:~ $ sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user wpfred;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> set password for wpfred = password("raindrop");
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant all PRIVILEGES on wordpress.* to wpfred@localhost identified by 'raindrop';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit;
Bye

That does it for the database.

Install WordPress

Proceed as follows.

pi@raspberrypi ~ $ sudo apt-get install -y wordpress

WordPress will install, along with many associated packages.

Restart Apache

Now, restart the Apache web server so that it will work properly with the WordPress packages just installed. Use the command:

pi@raspberrypi ~ $ sudo service apache2 restart

Note that this command does not print any messages to the terminal.

Configure WordPress

Create a link from your Apache installation to the WordPress directory. Here, I have called the link “myblog”.

pi@raspberrypi ~ $ sudo ln -s /usr/share/wordpress /var/www/html/myblog

Copy the default configuration file into place and edit it:

pi@raspberrypi ~ $ sudo cp /usr/share/wordpress/wp-config-sample.php /etc/wordpress/config-default.php
pi@raspberrypi ~ $ sudo vi /etc/wordpress/config-default.php

(many thanks to Gene Shiau for the above commands. For more info, see /usr/share/doc/wordpress/ README.debian)

Change the lines for DB_NAME, DB_USER and DB_PASSWORD near the top of the file. In the example I have entered the user and password defined above.

So this part of the config-default.php file changes from

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

to:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wpfred');

/** MySQL database password */
define('DB_PASSWORD', 'raindrop');

Save the file.

Fill in the WordPress Welcome Form

Now start a web browser and surf to http://<ip address of your Pi>/myblog

For example, my Pi’s IP address is 192.168.1.90, so I surf to http://192.168.1.90/myblog

Note: If you see an error message in the browser like this: “Neither /etc/wordpress/config-pi.php nor /etc/wordpress/config-pi.php could be found. Ensure one of them exists, is readable by the webserver and contains the right password/username”.

… then please check again that you copied the default wordpress configuration file from /usr/share/wordpress/wp-config-sample.php to /etc/wordpress/config-default.php, as instructed above. Just check it by running more on the file now:

pi@raspberrypi ~ $ more /etc/wordpress/config-default.php

…and you should see the contents of the file.

Fill out the form, entering a title for your blog, and entering a name for the admin user. (Note: do not choose “admin”, as it is easy to guess. Choose something else, perhaps your own name, say followed by a number, like “mike382”). Enter a secure password and keep a note of it, or use the password already filled in. Enter an email address where indicated.

Next, click the “Install WordPress” button, and wait a couple of minutes while WordPress completes the installation.

Log in to WordPress

You will see a page saying “Success!” and a button to log in. Click that, and log in, with the user name and password you chose earlier.

The WordPress Dashboard will appear. Congratulations! You have successfully installed WordPress on your Raspberry Pi.

A Note on Speed

When a user visits your blog, a large post will load into their browser in about 2 seconds, if you are running WordPress on a Raspberry Pi 2 or 3. In order to make posts load faster, I would recommend using the wp-super-cache plugin for WordPress. Wp-super-cache will create and serve cached copies of each post, which will load into the visitor’s browser in less than a second. Even if you decide not to use caching, a load time of 2 seconds will still make your blog faster than many Internet sites.

Protecting your Site with TLS/HTTPS

If you want to protect your WordPress site by converting it from HTTP to HTTPS, please see my later article: How to Convert a Website from HTTP to HTTPS.

A Note on Security

If you plan on making the blog internet-facing, make sure that the WordPress user and password is properly secure and hard to guess.  There are many guides on the Internet offering more WordPress security tips.

50 thoughts on “Install WordPress Blog on Raspberry Pi

  1. Pingback: Raspberry Pi Basic Configuration | Unix etc.

  2. Pingback: Install Wordpress Blog on #RaspberryPi | Raspberry PiPod

  3. Hi, I’ve installed on my Pi but have no access forl internet. NAT is not the problem because I can visit my site on joomla, I’ve seen that I can access to my wordpress home site but when I try to go to another page it looks for my internal IP and as you can think that it’s not possible over external internet conection.

    Could you help me? Thank you.

  4. Hi Raspi. From the WordPress Dashboard, go to Settings->General. Near the top of the page you see two fields called “WordPress Address (URL)” and “Site Address (URL)“. Change both of these to be the URL of your WordPress blog. For example, change both to

    http://your_external_IP/myblog

    or if you have a domain name, change both to

    http://yourdomainname/myblog

    And save the changes. The URLs on your site will then point to the proper external address instead of your internal IP. Note: be careful when making the above changes, as entering the wrong thing can occasionally lock you out of WordPress.

  5. I get the following error message in the browser like this: Neither /etc/wordpress/config-localhost.php nor /etc/wordpress/config-localhost.php could be found.
    Ensure one of them exists, is readable by the webserver and contains the right password/username

    Any thoughts/help grateful received.

    Thanks for your help

    • Hi Simon. Try creating the following link

      pi@raspberrypi ~ $ sudo ln -s /etc/wordpress/wp-config.php /etc/wordpress/config-localhost.php

      It’s the same problem as noted in the original article (search the post for “exists”), except I guess the hostname on your pi is “locahost”, whereas mine is called “pi”. WordPress complains it cannot find /etc/wordpress/config-.php

  6. Pingback: Installer WordPress sur le raspberry pi »

  7. Thank you for this tutorial, it has been extremely helpful. Unfortunately I am stuck in the same place as Simon. I am getting Neither /etc/wordpress/config-.php nor /etc/wordpress/config-.php could be found. Ensure one of them exists, is readable by the webserver and contains the right password/username.

    I have tried the linking posted in your tutorial as well as what you wrote in response to simon — so both pi and local host. I am not able to get past this error. Do you have any suggestions?

    • Hi Joanna, it seems that WordPress might be a bit confused about the name of your system. Please post the output of the following two commands:

      # hostname
      # ls -l /etc/wordpress

      • I have the exact same problem.
        Hostname gives : Ghosting
        ls -l /etc/wordpress gives:
        lrwxrwxrwx 1 root root 28 Nov 13 23:08 config-127.0.1.php -> /etc/wordpress/wp-config.php
        lrwxrwxrwx 1 root root 28 Nov 13 22:59 config-Ghosting.php -> /etc/wordpress/wp-config.php
        lrwxrwxrwx 1 root root 28 Nov 13 22:58 config-localhost.php -> /etc/wordpress/wp-config.php
        lrwxrwxrwx 1 root root 28 Nov 13 23:00 config-pi.php -> /etc/wordpress/wp-config.php
        -rw-r–r– 1 root root 898 Sep 13 21:10 htaccess
        -rw-r–r– 1 root root 3160 Nov 13 22:55 wp-config.php

        Thanks

        • Hi George and others still having this problem about “Neither /etc/wordpress/config-.php nor /etc/wordpress/config-.php could be found…”

          Whatever WordPress says it can not find, just create it as a link pointing to wp-config.php file. WordPress is just trying to open the file using the link.

          So in Joanna’s case, WordPress is cannot find /etc/wordpress/config-.php. Give WordPress what is wants and create the link:
          $ sudo ln -s /etc/wordpress/wp-config.php /etc/wordpress/config-.php

          Then do this to make sure you created the link right and it resolves to the config file:
          $sudo cat /etc/wordpress/config-.php

          You should see the contents of the wp-config.php file. If you see it, so will WordPress and it should work.

          • I change the config-pi.php to config-ipadress.php and it started to work. I think I might try localhost.php later. I think that will work better.

            $ sudo mv /etc/wordpress/wp-config.php /etc/wordpress/config-192.168.1.10.php

          • Hi there. Thanks for the tutorial, *very* useful.
            I’m stuck at the same place, because it seems that the file is owned by root and I cannot get write permissions on it with my user-account or with sudo.
            Here’s the output of ls -l on /etc/wordpress/ :
            pi@pedagopi:/$ ls -l /etc/wordpress
            total 8
            -r—w—- 1 root root 3177 janv. 22 17:09 config-default.php
            -rw-r–r– 1 root root 898 sept. 13 23:10 htaccess

            I’ve been looking in the info on chmod commands to give me writing rights to /etc/wordpress/config-default.php, but I’m afraid it’s all double dutch to me. Am I right it’s only a question of writing permissions ? What’s the most easy / efficient way to change this ?
            Again a big THANK YOU for this tutorial and for the help it provides !

          • Hi Antoine

            Yes, the permissions on your config-default.php file mean that you must have root rights in order to edit it. I see from your prompt that you are logged in as “pi” user. By default, “pi” user is enabled for sudo. However if it is not working for you, get the root password and fix as follows.

            pi@pedagopi:/$ su –
            Password: [type root password here]
            root@pedagopi # vi /etc/wordpress/config-default.php
            [edit the file in vi and save it]

            And if you want to enable sudo for the “pi” account:
            root@pedagopi # echo “pi ALL=(ALL) ALL” >> /etc/sudoers

            should do it. Type ctrl-d to logout as root and return to “pi” user. NB. it is better to leave the ownership and permissions on the file are they are, for security reasons.

  8. Pingback: Raspberry server | Applicazioni interessanti sul Web - InternetPost

  9. Pingback: Raspberry server

  10. I have figured out how to edit wp-config.php however when I try to save and exit vi I always get this message. Cannot seem to resolve can anyone help???

    “/etc/wordpress/wp-config.php” E212: Can’t open file for writing
    Press ENTER or type command to continue

    • Hi Andrew I am not a Mac user but typing “vim” in a terminal should bring up the vim editor (like vi). So to edit the file type “vim /etc/wordpress/wp-config.php” or similar.

      The E212 error means you have no rights to write the file, so changes cannot be saved. Try using sudo, which will give your edit session root rights. Type “sudo” before whatever edit command you are using, eg “sudo vim /etc/wordpress/wp-config.php”

  11. Love this tutorial. Loooove it! I did my WP-on-RPi installation after comparing several tutorials, and this was my favorite.

    A word on configuring WordPress: Instead of copying /usr/share/wordpress/wp-config-sample.php into /etc/wordpress/ as wp-config.php, write your command as

    sudo cp /usr/share/wordpress/wp-config-sample.php /etc/wordpress/config-default.php

    Then use the following command to edit that config file:

    vi /etc/wordpress/config-default.php

    This will prevent the error “Neither /etc/wordpress/config-[host name or ip addr].php nor /etc/wordpress/config-[host name or ip addr].php could be found” from showing up in the first place. You won’t need to create any link to the file /etc/wordpress/wp-config.php. The WP help file /usr/share/doc/wordpress/README.Debian nicely explains this aspect of the configuration.

    • Hi Gene, thanks for your comments and the information about copying the config file to config-default.php. Article updated accordingly. That’s great.

  12. Quick Question…
    I’ve followed your instructions and got wordpress working..how do I install plugins?
    It asks for FTP credentials…
    Thanks

    • I figured it out.
      Apparent If you get the FTP screen it means that WordPress doesn’t have access write in the WordPress directory. To fix I ran the following via the terminal:

      chgrp -R www-data /usr/share/wordpress
      chmod -R 2750 /usr/share/wordpress

      chgrp -R www-data /var/www/myblog
      chmod -R 2750 /var/www/myblog

      cd /var/www
      sudo chown -R www-data:www-data myblog

      cd /usr/share/
      sudo chown -R www-data:www-data wordpress

      • Hi Martyn, thanks for coming back to add the information about FTP and permissions. It should help others with the same problem. I think what matters most is the permissions on the directory /usr/share/wordpress/wp-content (and its sub-direcotry “plugins”. So long as the web server (ie. the www-data user) can write into those folders, uploading plugins should work okay.

    • Hi MArcosab1991, unfortunately your domain name lifeonpi.sytes.net no longer resolves to an IP address, so I can’t view your site. sytes.net is one of the domains run by no-ip.com, and the free ones expire after a month I think. Maybe your record has expired. Perhaps you could renew it or re-post the URL with an IP address ?

  13. Pingback: Install WordPress Blog on Raspberry Pi | Mi Block de Notas

  14. Pingback: [Raspberry] Simplement ultra utile || WordPress - Le Texier

  15. Pingback: Sito per compito Informatica | Sito per compito Informatica

  16. Pingback: CentOS7 LAMP环境搭建WordPress博客 – Chien

  17. Pingback: INSTALAR DRUPAL EN RASPBERRY PI 1 | Con los pens en los usb 3.0

  18. Hi Jim,

    Firstly thanks for updating this guide – of all the ones on the net this is the furthest I have got on getting wordpress installed on my pi3 this however it is still not quite working. I have walked through all the instructions and managed to login to the site, I can see it on my local network and I can get into the dashboard but I cannot change the site (I have also followed Martyn’s permissions guide above). – note this is on a fresh installation of Rasbian stretch.

    Symptoms –
    1. I cannot upload media files using the drag and drop (but I can one at a time using the browser method). Using drag and drop I get a helpful “HTTP error”.

    2. I cannot browse any themes using the theme browser, I just get “An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration”. If I download a theme as a zip file I can upload it and preview but I cannot activate.

    3. If I go to edit / customise the site, I can change elements of the site but the save / publish button does not enable the site to save. No errors reported on screen but save does nothing (and I lose changes when I navigate away from the site).

    4. Plugins install ok BUT when I try to delete I get the message “Deletion failed: Connection lost or the server is busy. Please try again later”.

    /usr/share/wordpress/wp-content/* directories all have the same permissions / owner / group. There must be some fundemental permissions error somewhere but I really don’t know what if can be – any pointers?

    • Hi Geoff. You have installed WordPress following the guide, but there are a few problems. I must admit I have not tried drag-and-drop media files or deleting themes. Please send the outputs of the following commands:

      ls -l /usr/share/wordpress
      ls -l /usr/share/wordpress/wp-content
      ls -l /usr/share/wordpress/wp-content/themes

      Also, were there any error messages during the installation, or did everything go exactly as described in the process?

      Cheers,
      Jim

      • Hi Jim
        It actually was a browser issue! I had noscript running in firefox so added my site / IP as a trusted site and all works fine now!

        boy do I feel dumb! Feel free to keep this up as a measure of obviously dumbassery (or incase someone else runs into these kind of issues)..

        Thanks – Geoff

  19. Hi All, here is my situation, hope for some help.
    Following above instructions:
    Apache working, get the default page
    PHP working get the php info page
    Maria db working can log in directly with user i created
    made link in var/www/html for myblog to usr/share/wordpress
    copied config file to etc/wordpress and modified per instructions
    open browser to http://localhost/myblog and get 403 Forbidden error, you do not have permission to access myblog on this server.
    I’m new at this and linux, so im lost as to where the permissions are failing.
    Any help appreciated.

    • Hi Harold, I have tested the procedure again and it seems to work fine. I am not sure why you are seeing this 403 error. Were there any other error messages appearing at any other part of the process?

      Try re-starting Apache and see if that helps. Type the command:

      sudo service apache2 restart

      Then see if you can load the web page properly.

  20. Hey,

    I am having a “403 forbidden You don’t have permission to access /pear on this server.” and I have redone the process and cannot figure what is going on

    • Hi Peter. It means that something is incorrect with the installation. The most likely cause is file permissions or (possibly) Apache configuration. If you are using a fresh installation of Raspbian, this kind of thing should not occur. Cheers, Jim.

  21. Pingback: Cambridge Analytica – JamesBook

  22. Pingback: My new website saves lives and is the future of the internet – The Rogue Element

    • Hi Alex. I’m afraid I don’t know what is meant by “receive contact form entries”. Can you give more information ?

      Cheers,
      Jim.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.