WordPress is a PHP and MySQL based open source blogging platform and content management system. It is a popular blogging system and includes features like threaded comments, galleries, revision histories, trash, custom post types, thousands of themes, widgets and plug-ins. This article describes the setting up of a web server for WordPress on Raspberry Pi.
Apache web server installation
Apache, a web server application notable for playing a key role in the initial growth of the World Wide Web, is used to serve web pages. Follow the procedure given below to install it on Raspberry Pi.
1. Install apache2 package by executing the following command (also see Fig. 1):
$ sudo apt-get install apache2 –y
2. After this installation, Apache sever will be running. Thereafter you can start or stop it by running the following commands (also see Figs 2 and 3):
$ sudo service apache2 start
$ sudo service apache2 stop
3. Apache server by default creates a test HTML file in web folder. This can be served when http://localhost/ is browsed on the Raspberry Pi or http://192.168.2.104 (IP address of the Raspberry Pi in our case, but can be different in your case) from any other computer on the network.
Browse the default web page and you will see the message shown in Fig. 4 appear on the screen.
4. Change the default web page as per your requirement. The default web page is an HTML file on the file system and is located at /var/www/index.html. Execute the following command on terminal to navigate and have a look on the file:
$ cd /var/www
$ ls -al
You will see the following:
drwxr-xr-x 2 root root 4096 Mar 2
drwxr-xr-x 12 root root 4096 Mar 2
-rw-r–r– 1 root root 177 Mar 2
This shows that there is one file called index.html in /var/www/. The ‘.’ (dot) at the end of line 2 refers to the directory itself/var/www/ and the ‘..’ at the end of line 3 refers to the parent directory /var/.
Meaning of each column in the previous file is:
1. File or directory permissions
2. Number of files in the directory (1 in case of a file)
3. User who owns directory or file
4. Group which owns the directory or file
5. File size
6. Date and time of last modification
In order to edit the directory and file, you should log in as root user. Edit the index.html file using either of the following commands.
$ sudo chown pi: index.html
$ sudo nano index.html
Try editing/changing this file and refreshing the browser to see the web page changes.
Next step is to install PHP and MYSQL, which are used to create your own site and publish your own content dynamically, without knowing how to program those pages.
Install PHP by executing the following command (also see Fig. 5):
$ sudo apt-get install php5 libap
ache-mod-php5 php5-intl php5-mcrypt
To check whether PHP has been installed properly, move index.html file to index.php using following command (also see Fig. 6):
$ sudo mv index.html index.php
Now edit the file:
$ sudo nano index.php
Put following text in index.php after opening the nano editor:
Save and then refresh the browser. You should see ‘hello world’ on your browser. This is served by the PHP and is not dynamic. So let us try something dynamic like displaying date and time by giving following command:
Or you can show the PHP info by giving following command:
Installing MYSQL database management system
Execute the following command to install MSQL (also see Fig. 7):
$ sudo apt-get install mysql-
server mysql-client php5-mysql
Enter the password of your choice for the top-level MSQL user, who will be managing MSQL but is not root user of the Raspberry Pi operating system. Stop and start the apache2 server.
Download WordPress by running wget command on the terminal. You can find the latest version at wordpress.org/latest.tar.gz and wordpress.org/latest.zip
Download the WordPress to /var/www/ location. You will have to empty the folder first. Now change the ownership of this folder to the Pi user using following command:
$ cd /var/www
$ chown pi:
$ rm *
$ wget http://wordpress.org/
Or you can download it directly from the link mentioned below:
Extract the tarball using following command:
$ tar xzf wordpress-3.9.1.tar.gz
Move the contents of folder to the current directory.
$ sudo mv wordpress/*
Remove the folder (which is now empty) and tarball to tidy up.
$ sudo rm -rf wordpress-3.9.1.tar.gz
To see the content of the WordPress project, run the ls or tree-L1 command. You will see the project as given below. It is the source of a default WordPress installation.
The files for editing to customise installation is in the ‘wp-content’ folder.
Setting up WordPress database
To set up WordPress site, you will require a database such as MYSQL.
Run the mysql command in the terminal and provide the login credentials (username is ‘root’ and password is ‘password’) as given below:
$ mysql -uroot –ppassword