topamax once a day

WordPress on Raspberry Pi

This tutorial will demonstrate how to install and host WordPress on Raspberry Pi. This process assumes you have Debian for Raspberry Pi installed on an SD card. If not, see RPi Easy SD card setup.

Install Apache

WordPress runs on the Apache2 web server. To setup Apache, follow the instructions in my previous post, Raspberry Pi and Apache.

Install MySQL and PHP

Begin by installing the required dependencies. From a terminal:

sudo apt-get install mysql-server-5.5 php5 php5-mysql php5-gd

Next run the MySQL init script:

sudo mysql_install_db

Download and Extract WordPress

Download the latest wordpress source files

wget http://wordpress.org/latest.tar.gz

Extract the downloaded archive:

tar -xvzf latest.tar.gz

Create a directory in /var/www for the WordPress install:

sudo mkdir /var/www/wordpress

Copy over the extacted files:

sudo cp -r ~/wordpress/* /var/www/wordpress

Configure Apache

Next, make a backup of the apache config file, then open it in a text editor:

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
sudo vim.tiny /etc/apache2/apache2.conf

Add this line to the end of the file:

AddType application/x-httpd-php .html

And restart Apache

sudo /etc/init.d/apache2 restart

Configure MySQL

The next step is to configure MySQL for use with WordPress. WordPress needs a database and user, and permissions set correctly for access. Start the mysql config:

mysql -u root -p

Enter the root MySQL password, then arrive at the mysql prompt

mysql>

Create a database for WordPress, create a user for the database, and set password set the permissions:

CREATE DATABASE wordpress;
CREATE USER wordpressuser;
SET PASSWORD FOR wordpressuser= PASSWORD(“1234”);
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser IDENTIFIED BY ‘1234’;
FLUSH TABLES;

Then quit the MySQL client:

exit

Now create a new wordpress configuration based on the sample:

sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

And open it up for edit in an editor:

sudo vim.tiny /var/www/wordpress/wp-config.php

Change this:

/** 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 this (substituting password_here with your own from above):

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘wordpressuser’);

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

Finalizing the install

The hard part is over! Now open up a browser and head to the site and finalize the install. To do this, navigate from a browser on another machine on your local network, only substitute the local address of the Raspberry Pi. To find the address of the Raspberry Pi, open a terminal and run:

ifconfig

Then navigate to that address with a trailing /wordpress from a browser on the same local network:

http://192.168.1.100/wordpress

 

  • Nice writeup! I’ve gone through this process recently myself. How does the server hold up to more than minimal traffic? I’ve been thinking about setting up an image with WordPress, nginx, and Sqlite as a low-memory alternative.

    • I haven’t tried with nginx or sqlite myself, but I suspect it will be an improvement over the full fledged apache/mysql install!

  • Pingback: Zerbitzari banatu txertatuak | txertatuak()

  • James

    Thanks for the explanation. Followed your guide and got WordPress working, although it does seem to ‘lock-up’ easily, needing a restart of the RasPi. How stable do you think it is?

    • Hi James,
      I was experiencing the lock-up issue as well. I’m looking into some options with the memory split, or caching to improve the stability!

  • Brad

    Thank you. I can confirm that it works on my Pi with a Sandisk Class 10 Ultra SD (16GB). Serves pages fine. Install only possible remotely. Having issues with ‘lockup’ when using backend to edit content.

    • Hi Brad, thanks for the feedback. My experience with backend editing also sometimes seems to ‘lockup’. I’m going to try with nginx and see if it fares better than apache.

  • when I tried to copy extracted files(sudo cp -r ~/wordpress/* /var/www/wordpress) it keeps giving me error….or asking me to go to –help…for cp command…what am I doing wrong? Need help please.

    • Hi Rafael, the most likely cause is the wordpress archive is not in the assumed location. The command assumes you have downloaded and extracted the archive to the home directory of the pi user, if you have extracted it somewhere else, you will need to adjust accordingly. Try the cp command with fully qualified paths (update to match your location):

      sudo cp -r /home/pi/wordpress/* /var/www/wordpress
  • you know what….that did it beautifully….thanks a million…

  • I find that the mysql user creation section above doesn’t work – after doing it attempting to log in as wordpressuser gives and access denied.

    Instead of the three lines (CREATE USER, SET PASSWORD and GRANT ALL), I found the following single line worked:

    GRANT ALL on wordpress.* TO [email protected] IDENTIFIED BY ‘password’;

    • Laurent Mahé

      Thanks Jon

      I had the “error establishing a database connection” error message.

      Your suggestion solved my problem beautifully 🙂

      • Russel

        I had same problem using 2012-10-28-wheezy-raspbian.zip image
        I had also done a
        sudo apt-get update
        sudo apt-get upgrade
        this was 7 November 2012

        your use of @localhost in the user ID fixed the problem

        mysql -u root -p
        GRANT ALL on wordpress.* TO [email protected] IDENTIFIED BY ‘password’;
        flush tables;
        exit

        then connected to web page and all worked!

        ===
        Michael, great tutorial/recipe thank you!

        • This too was my most troublesome section. I found manually typing the commands instead of cut/paste helped here.

          CREATE DATABASE chimps;

          mysql> use chimps

          mysql> create user newuser

          mysql> set password for newuser=password(“xxxxx”);

          mysql> grant all privileges on chimps.* to newuser;

          mysql> flush tables;

          Otherwise great writeup. I usually use XAMPP but it doesn’t work on ARM processors I read.

    • I too had the “error establishing a database connection” error. The above provided by Jon solves it. Cheers mate.

    • Paul Barrett

      This also work for me

  • Hey this is great! I’m a big Raspberry Pi fan myself. WordPress would be a fun project to put on the Raspi, and it also helps those of use who are just looking to install something like MySQL and PHP.

  • Pingback: Wordpress for Raspberry Pi using Nginx and MySQL | CNXSoft – Embedded Software Development()

  • Pingback: Raspberry Pi ลง WordPress, Nginx, FastCGI, MySQL | Raspberry Pi Thailand()

  • Pingback: WordPress on Raspberry Pi « Logbook()

  • Cool but for me, I can’t install MySQL and PHP. It say:
    “Some packages could not be installed. This may mean that you have an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or ben moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies
    mysql-server-5.1 : Depends: mysql-client-5.1 (>= 5.1.62-1) but it is not going to be installed
    Depends: libmysqlclient16 (>= 5.1.50-1) but it is not going to be installed
    PreDepends: mysql-common (>= 5.1.62-1) but it is not going to be installed
    php5-mysql : Depends: libmysqlclient18 (>= 5.5.24+dfsg-1) but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.”

    I have the last RaspBian image with the last firmware. I made some apt-get update and upgrade but it didn’t change anything.

    • Looks like the newest version of Raspbian has updated the mysql-server-package. Instead of:
      sudo apt-get install mysql-server-5.1 php5 php5-mysql php5-gd
      Use this instead:
      sudo apt-get install mysql-server-5.5 php5 php5-mysql php5-gd
      Thanks for pointing this out… I have updated the article as well!

      • Steve

        Just use mysql-server without the version number and it will get the latest one.

  • RickNL

    Hi Michael,

    i have a problem, when I follow your tutorial everything went well except when I try to open the website (the apache page works fine). I get a HTTP-500 error. Can you help me with this?

    • You need to go into your site from your localhost and edit the site URL under settings -> general. Once you update that you will be able to see all your content externally.

  • Lunatic4ever

    No lockups and using apache with php-apc and apc backend plugin! Works very well!!

  • Pingback: Random Links of the week | Raspberry PI Community Projects()

  • Jim

    I have an interesting problem. If I connect to the server from the localhost I get a correctly formatted webpage. If I connect to it from anyone inside or outside of my network I don’t get graphics. and If I try to login via the login page it gets redirected to 127.0.0.1/wp-login.php which fails. any ideas?

    • Dmitriy

      hostname lookup problem

      • Rob

        i have this problem too, would you mind giving a little more advice towards a soloution?

        • Rob

          i have now fixed this problem, open wordpress admin panel navigate to settings and change the site url and other url from your local ip 192.168.x.x/wordpress to your full ip/wordpress (to find this google search whats my ip) if like me for some reason you can not change the two urls, start a session on the pi terminal, sudo nano var/www/wordpress/wp-config.php

          locate the two ip addresses in their and change as appropriate, save and close.

          job done. enjoy 🙂

  • Pingback: Finally, Putting the Raspberry Pi [RPi] to some use! | The Second Try()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | TechCrunch()

  • Pingback: NerdSites.com – Getting Started With The Raspberry Pi Is Not As Easy As Pie()

  • Pingback: Houston Outsource: Get Tech News Now! Getting Started With The Raspberry Pi Is Not As Easy As Pie | Houston Outsource: Get Tech News Now!()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | Easy Nulled Script()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | Crowdfunding News()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | Krantenkoppen Tech()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | DailyBusinessNews.comDailyBusinessNews.com()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | Hosting In()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie « Mr Gee()

  • Pingback: GIASTAR – Storie di ordinaria tecnologia » Blog Archive » Getting Started With The Raspberry Pi Is Not As Easy As Pie()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | blog seo tips and tricks()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | download free music to mp3download free music to mp3()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie : Blog()

  • Pingback: Getting Started With The Raspberry Pi Is Not As Easy As Pie | Tech Is Geeky()

  • Good write up!
    I had several things that needed to be worked out.
    I could not add or delete to the “FTP” in wordpress, it was a permissions issue.
    sudo chown -R www-data:www-data*

    To log into the FTP I had to use.
    Domain:wordpress
    FTPuser:’SQLuser’@localhost
    FTPpass:’SQLuser’ password’

    Also I developed the site on one RasPi and put it up on another. WordPress really did not like this as it was using the internal IP as it location. When I moved it over I lost the site until I installed phpMyAdmin so I could edit the database and get it back. The settings for the site URL had to be right or it was really slow or not accessible at all. I was using dyndns.

    WordPress Address :your.dyndns.tv/wordpress
    Site Address :your.dyndns.tv

    I hope this helps others get their RasPii up on wordpress!

  • Yacine

    Hi,
    I’m getting an error : “Error establishing a database connection”
    Any suggestion ?

    • ben

      Yeah i get this problem as well and i really want to sort it!

  • ben

    Yeah i get the same problem and i really want to sort it!

  • Great blog, thanks for sharing it with us. Now following you, you maybe also interest in looking at my WordPress blog also.

  • Kevin

    🙁 followed to a T but get the same “Error establishing a database connection”

    • Stefan

      GRANT ALL PRIVILEGES ON wordpress.* TO “user”@”localhost”IDENTIFIED BY “password”;
      solved the “Error establishing a database connection” for me!

  • Pingback: Install WordPress on Cubieboard(with APM) | Dev.()

  • Pingback: Wordpress on the Raspberry Pi | PYoung.net()

  • It got a little confusing with the code sections of the posts in italics — I missed some spaces in the syntax and I’m a Linux n00b. Had the database connection problem too, so I just jumped in PHPMyAdmin (I’d previously installed) and set the user and permissions in the GUI. MUCH easier. Thanks for the post! My pi is serving up WP!

    • hey, I’m really new to this and I’m getting the database connection problem. Any tutorials for the solution you used anywhere? thanks

  • Christopher

    Hello, I got a problem when I’m traying to setup a wordpress on my raspberry pi.
    I get this message:

    mysql> SET PASSWORD FOR wordpressuser2= PASSWORD(“1234″);
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘“1234″)’ at line 1

    • Yoon

      Hi There. I have had exact same problem occurred me. You simply use single quote (‘) rather than using double (“) will fix a problem.
      GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘1234’;

  • Jack

    If i want to open: “http://ipoftheraspberrypi/wordpress” it sais an error: “Error establishing a database connection”

    pls help

    • Dick

      Have just installed and get the same error message when I enter http://local IP address/wordpress 60sec after entering the command

  • Benny Widing

    Same here, Error establishing a database connection”.
    Should i use internal IP-adress on “localhost”
    or raspberrypi..or just leave it as it is?

  • Gordon

    Great tutorial, thank you!! My first attempt, I was getting the “database connection error”. I had to improve my Linux text editing skills (I used Nano) to learn how to ‘save’ my changes (CTRL and O) in the wp-config.php file. Once WP knew what to look for and the password, I was in business.

    Thanks again. I would have NEVER figured all this out on my own.

  • Pingback: Bringing up the webserver on a Raspberry Pi | Greenhouse News()

  • Pingback: The Boghallpi | Boghallpi.com/dads()

  • Pi in the sky

    Reading the thread and the issues by those trying got me going so far but I’m having the FTP issue. The database issue was difficult , it was easier opening it in leaf pad and saving a copy – vim.tiny is hard for amateurs and almost impossible if you ssh in from a terminal on an iPhone ! Could anyone clear up the FTP issue for ” Failed to connect to FTP server WordPress:21 ” ? I think that maybe my last hurdle for this WordPress on a pi tia

    • Pi in the sky

      Aha ! My problem was the ownership of /var/www/—-incorrect — something like
      “sudo chown www-data.www-data /var/www/my install place

  • Pingback: Na endlich!! | blög()

  • Pingback: blög – Verbinden der Datenbank mit Wordpress()

  • Pingback: Install WordPress on Raspberry Pi | JohnyLuky()

  • Pingback: T-E-M-T – I didn’t name it…. | George's Portfolio()

  • Gene Shiau

    Thank you! This was an easy-to-follow instruction, especially because I didn’t want to have to install phpmyadmin (which other tutorials often use). After the installation I ran into an error when browsing to my Raspberry Pi:

    “Neither /etc/wordpress/config-192.168.1.101.php nor /etc/wordpress/config-168.1.101.php could be found.”

    I imagine that I wasn’t the only person experiencing this issue. To address this, I would suggest a change to the “create a new wordpress configuration based on the sample” procedure (after quitting the MySQL client):

    sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/config-default.php

    Then use the following command to to edit this config file:

    sudo vim.tiny /var/www/wordpress/config-default.php

    • I after I did everything, I went to my other computer and used the local ip with /wordpress attached at the end only to get a big white page with “Error establishing a database connection”.

      Help please 🙂

  • Pingback: Install WordPress Blog on Raspberry Pi | Mi Block de Notas()

  • How can I use this with my domain (not on example.com/wordpress but just on example.com? How do I set up the DNS and which port do I need to fordward?

    • Tcow

      just install wordpress in the root DIR of your webserver, so instead of var/www/html/wordpress, you would simply install it in var/www/html then forward port 80 for your raspberry pi and set up DNS with your domain to point to your global IP address,

  • Pingback: Host your own wordpress site! | Garys blog()

  • Pingback: WordPress for Raspberry Pi using Nginx and MySQL | vienergie()

  • Pingback: Trying to install a theme with WordPress (FTP Failing) | Zimmerly Answers()

  • I tried to add this command to the AddType application/x-httpd-php .html to the apache config file, then opened it in a text editor: I can save the file because could not open file. I stopped the apache to no avail. Please advise.

    • I found out how to the add “AddType application/x-httpd-php .html” to the apache config file, You have to edit the config file as root
      sudo nano apache2.conf.

  • Pingback: Powered by Wordpress, running on raspberries - I am Davin()

  • Appfixers.nl

    MariaDB ERROR 1045 (28000): Access denied for user ‘user’@’localhost’

    I also needed to add:
    GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘mypassword’;

    not only
    GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’%’ IDENTIFIED BY ‘mypassword’;