WordPress is one of the most, if not the most, popular way of hosting a website today. You can setup a website using WordPress.com, but you can also host WordPress on your own Raspberry Pi. This tutorial will show you how to do exactly that.

Documentation remote-access web-server Setting up a web server on a Raspberry Pi You can use a web server on a Raspberry Pi to host a full website (locally on your network or globally on the internet), or just use it to display some information you wish to share to other machines on your network. Set up Apache Web Server on a Raspberry Pi STEP-01: Install the OS. Hook up the keyboard and mouse to the Pi and connect it to an HDMI monitor. Copy NOOBS to a. STEP-02: Check the network address. Make a note of the ‘inet addr’ value for eth0. This will be the IP address of your. STEP-03: Update.

What you will need

If you have not setup your Raspberry Pi with an operating system this tutorial will show you how that is done.

Tutorial

To get WordPress up and running on your Raspberry Pi you will need a few other components up and running first. These include a database, a web server and a programming language.

  • PHP (Programming language)
  • MariaDB (Database)
  • Apache Web Server (Web Server)
  • WordPress

Apache Web Server

Server

The most common web server which is used together with WordPress is the Apache Web Server. To install Apache on your Raspberry Pi, simply type the command.

In order to check that the web server has been setup correctly you can visit the site “raspberrypi.local” in your browser. It should look something like this.

PHP

WordPress uses the programming language PHP which is according to their website a general-purpose scripting language that is especially suited to web development. To install PHP on the raspberry Pi type the following command on its command line. It will install the programming language PHP on the Raspberry Pi and make it ready to be used for WordPress.

To check that PHP works as expected we need to do some more things than just visit a website hosted on the Raspberry Pi.

Start by removing “index.html” placed in the folder “/var/www/html”

Next step is to create a file called “index.php” in the same folder with the following content.

You also need to restart the Apache Web Server to verify that the PHP is working correctly.

When you now visit the same page as before you should see info about PHP instead of the Apache Web Server information.

MariaDB

The last component that WordPress needs in order to work properly is the database. In this case it is a database which is called MariaDB and is a fork of the more famous database Mysql.

The packages needed to install are the following.

When the database has been installed the Apache Web Server needs to be restarted once more to know about the changes.

Install WordPress

Now when all the components needed by WordPress it is finally time to actually install WordPress onto the Raspberry Pi. We start by downloading the latest version of WordPress in the folder “/var/www/html” and removing the “index.php”

The downloaded file is a .tar.gz file and needs to be extracted in order to be used. (–strip-components=1 means that you will extract all the content in the folder “wordpress” directly to “/var/www/html”). Another good thing is to do some cleanup before we forget.

Another thing that is easy to forget is to set ownership of all the newly created WordPress folders to the Apache Web user. You do that by executing the following command in the “/var/www/html” folder.

Configure MariaDB for WordPress

Before the MariaDB can be used one needs to configure the database properly. You start this configuration by typing the following command and follow the instructions. Below you can see the answers I used to get the MariaDB up and running. Y for Yes and n for No.

The last step for the MariaDB installation is to create the proper database and table structure for the WordPress Database. You do this by first open the MariaDB command prompt.

When you have entered the prompt you need to first create a database called “wordpress”, grant the proper access rights and as a last thing flush the last access rights. Make sure you replace “PASSWORD” with something else.
You exit the prompt by clicking Ctrl + D.

When all the commands has been executed it should look something like this.

WordPress Installation

Reloading the “rasberrypi.local” site should now show something like this.

Success!

Follow the instructions on the WordPress site and you should not be too far off before you have your very own WordPress site! When WordPress needs the Username it is “root” and the password is the password you were forced to enter in the “MariaDB configuration” stage.

Summary

In this tutorial we have successfully setup a WordPress site which is hosted on your Raspberry Pi. The next step is to configure the site to be just the way you want it to be, with plugins and themes. You can check out the community around WordPress here.

If web sites is not enough for you, maybe you should checkout how to create your very own speaker with a Raspberry Pi? You find the tutorial here.

In my previous blog I installed Apache 2 on a raspberry Pi. To display more than simple HTML pages, you need to install and configure additional software such as a database server and scripting language PHP. For more convenience and security you can still arrange things like SSL. You do that as follows.You can install Apache web server yourself as described here.

Install a database server

Most sites do not consist of passive HTML pages, but retrieve their ever-changing content from a database. To store the content and other data in a database, you must install MySQL (or MariaDB) as database server.

During installation, a password is requested for the database user. After you have typed that in for confirmation again, the database server is ready for use. Wit the following command you can check if that is indeed the case.

Remember the database password well, because you will need it later, for example to create backups or new tables.

Install PHP

To install the language PHP you have to add some extra modules. This is why this command is a bit longer than the commands that you have typed so far.

and

Raspberry

To test if PHP is properly installed, you must first have a PHP page that you can run. To create such a page, you need an editor for editing text files. For beginners, nano is the easiest.

Then you can make a test page. At Apache, the files on the web server are in the directory by default.

In that directory you create a test page with the extension php.

Then type the following line.

Save the file (Ctrl + O) and close the editor (Ctrl + X). Then go to http://Servername/test.php with the browser. If all goes well, you will now see the system information of PHP. Because you probably do not want everyone to be able to view all the information about your web server, you remove that page after testing with the command.

Multiple websites

Raspberry Pi Php Server

Usually you want to host multiple websites on a single web server. They all come in their own directory and work with their own database, so that they do not get in each other’s way. In this case you make with the command.

a directory for the test.com website, followed by the command.

goes to that directory and there with

Apache Web Server On Raspberry Pi

the file index. html creates a default opening when someone visits a website.

In that index file you put the following content with nano:

Add A Website

You have created a separate directory for the new website, but Apache does not yet know what to do with it. In the directory

are the configuration files for the websites hosted by your Apache server. The configuration file for the new test.com domain must be created in that directory.

Apache

In the configuration file you set the following rules. At

enter your email address.

Then that configuration has to be added and loaded. With

(Apache 2 enable site) you add the site to the web server and with it

command recharges Apache the configuration. After this the site should be available.

If you go to http: //Servername/test.com with the browser, you should see the index page. If you have registered the domain name test.com and refer to the IP address of your web server, you should get the same result if you go to http://test.com.

Install SSL

The internet traffic between your web server and the browser of your visitors are not yet encrypted. Everyone who has access to that network traffic can therefore read everything and see what is being sent. Of course, you do not want that on pages with login details or payment information. That is why we need to encrypt this traffic. Nowadays this can be done in several ways: a difficult one, a reasonably easy one and a very easy one. Of course we take the easiest – and free – method and do it with Let’s Encrypt. You can let Let’s Encrypt arrange the certificates needed for encryption and also have all the settings necessary to secure internet traffic.

Thereby the file

in the directory

created in which port 443 is configured for secure SSL traffic. The normal data traffic via HTTP uses port 80, but the HTTPS protocol works with port 443. Fortunately, both HTTP and HTTPS are already enabled by the firewall, so that the secure data traffic is not stopped.

For optimal security, of course, you want all traffic that enters your web server via HTTP to be redirected to HTTPS. That is also what Let’s Encrypt sets for you in the configuration file

from your website. If you then go to https: // www. ssllabs.com/ssltest/analyze. html? d = test.com & latest, you can test if your site is indeed secure. If you go to http://test.com with your browser, you will see that you are automatically redirected to https://test.com. And more importantly: next to the url you will see a green lock to confirm the secure status of the web traffic.

Extend automatically

A Let’s Encrypt certificate has a maximum validity of 90 days, after which you normally have to renew the certificate manually. That is still possible for one website, but if you manage multiple sites, you do not want to run the risk of accidentally forgetting to extend one, which means your site will suddenly no longer be reachable safely. Fortunately, there is a possibility to automatically renew the certificate.

For this we create a system task, called Linux cronjob or crontab. With Cron (from the English word chronograph, a sort of stopwatch) you can perform tasks at a preset time. At the bottom of the list of existing tasks you add a new task to renew the certificates. In this case, that happens every morning at 7 a.m. If a certificate does not have to be renewed yet, nothing else happens.

Install the database manager

Now that the traffic from and to your web server is encrypted, you can continue with the database server. You have already installed it, but there is no management interface yet. Usually phpMyAdmin is used for this. Install this software with the following commands:

At the first screen, select apache2 by pressing the space bar and in the question to dbconfig- common you say yes. Then you have to enter a password to login to phpMyAdmin. The modules mcrypt and mbstring need to be explicitly allowed because phpMyAdmin needs them and they are not automatically installed. Then you have to restart Apache:

Then you can go to https: // test in the browser. com / phpmyadmin and you will be asked to log in. Use the password you just entered. You use root as the username.

How To Install Apache Web Server On Raspberry Pi

By logging in at phpMyAdmin as root, you will manage the database as a kind of super-user. Just like with the management of the web server, this is absolutely undesirable in practice, especially not because that interface is often the target of attackers. If malicious people manage to hack the interface, they have total access to all your databases. This is prevented by better shielding phpMyAdmin. Open the php-MyAdmin configuration file with

And add the line with

Raspberry Pi Apache2

to overrule the default settings later:

Restart the Apache server for the new settings:

Then you will ensure that only explicitly specified users can login to php-MyAdmin. There you create a .htaccess file in the phpMyAdmin directory for

containing the following content:

Save the file and create the file named .htpasswd with the permissible users:

for the first user and for every subsequent user the second command again, but without

. If you then go to https://test.com/ phpmyadmin, you will first have to log in as one of those users to access the interface.

Web server ready

Then the basic configuration of your web server is ready and your website is ready for use. If you want to work with a content management system (CMS), you can use phpMyAdmin to create a database for the relevant CMS package (for example WordPress, Jooma or Drupal) and specify its data when installing that package. Basically you now have a secure web server with all the basic functions – but also the possibility to extend that functionality where, how and when you want it.

DO YOU HAVE ANY QUESTIONS? LEAVE A COMMENT DOWN HERE.