Install WordPress Blog on Raspberry Pi

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

My Raspberry Pi was purchased from New It in the UK and runs Debian 7 (“Wheezy”).

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

PHP should install automatically at the same time. If not, install it by typing:

pi@raspberrypi ~ $ sudo apt-get install php5

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.

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

Note: You will be prompted to enter a password for the MySQL ‘root’ database user. Choose a suitable password and make a note of it.

Be patient while the database installation completes. It can take half an hour.

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

root@raspberrypi:~$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 42
Server version: 5.5.28-1 (Debian)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> quit
Bye

It works!

Increase MySQL Security

Now secure the MySQL installation. Run the script /usr/bin/mysql_secure_installation. It will ask for the password chosen earlier. Answer “yes” to all of the questions, except the first one about changing the root password. I have removed much extraneous output from the example:

pi@raspberrypi ~ $ sudo /usr/bin/mysql_secure_installation
Enter current password for root (enter for none):
Change the root password? [Y/n] n
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 MySQL!

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.

root@raspberrypi:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 44
Server version: 5.5.28-1 (Debian)

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> create user wpfred;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for wpfred = password("raindrop");
Query OK, 0 rows affected (0.00 sec)

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

mysql> exit
Bye

That does it for the database.

Install WordPress

Proceed as follows.

pi@raspberrypi ~ $ sudo apt-get install wordpress

WordPress will install, along with many associated packages.

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/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 ~ $ 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, if your Pi’s IP address is 192.168.1.90, 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 leaving the user name as “admin”. Enter a secure password and keep a note of it. Enter an email address where indicated.

Next, click the “Install WordPress” button.

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

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

A Note on Speed

In order to make your blog posts load with acceptable speed, I would recommend using the wp-super-cache plugin for WordPress.  That would be true whatever hardware you were using, but it is especially important with the Pi, which has limited CPU power to process the MySQL database.  With wp-super-cache, your blog will be plenty fast, with pages loading in just a couple of seconds.

A Note on Security

If you plan on making the blog internet-facing, I would recommend removing the “admin” user and replacing it with am administrative account with a less guessable name. And with a properly secure password that cannot be easily guessed.  There are many guides on the internet offering more WordPress security tips.

32 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

Leave a Reply

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