Apache Web Server Raspberry Pi



If you're feeling brave, you might want your Raspberry Pi powered web server to host more than one website or subdomain. Providing you've made the necessary modifications to increase performance, and are running Raspbian from a USB flash drive, there's no reason why your Raspberry Pi couldn't host more than one site.

Before you begin, I'm going to presume that you've followed my earlier tutorials to install Apache2, PHP and MySQL on your Raspberry Pi, and you have already got your domain or subdomain DNS records pointing to your Raspberry Pi.

Step 1 – Create the sites available file for your domain or subdomain

Throughout this tutorial, I'll be adding the subdomain video.dingleberrypi.com so replace this with your domain or subdomain you want to add. First, we'll run our usual sudo bash command to login at root level:

After we've done this, we'll want to copy the default file:

Now, we'll want to edit this file to tell Apache where the document root is, as well as any other information we wish to provide. To do this, type:

In this tutorial we install Apache web server in Raspberry Pi to control the LED from a webpage that can be accessed from anywhere over the internet. This is a basic tutorial with minimum features and it can be further modified to use this method in IoT based home automation, remote control automation, robotics etc. Creating a LAMP server (web server – Linux Apache Mysql PHP) with the Raspberry Pi. This provides details of how to configure a Raspberry Pi as a webserver. This is similar to the guide to using Ubuntu as a LAMP webserver, but adds some of the things that need to be handled differently for the Raspberry Pi. Install Apache2 on Raspberry Pi. Apache2 is the most widely used web server software. Briefly, a web server is the software that handles requests to access a web page. Then, depending on the page you have requested, the server will generate the document to serve you (.html,.php, etc).

Once you've opened your file, we'll need to add a line. After the line ‘ServerAdmin [email protected]' (change this to your email address if you really want to), type the following line (edit as you see fit):

After this, we'll want to change the document root. Don't worry if the folder isn't there yet, we'll create it in the next step. Change the document root and directory to something similar to how I have b?resize=697%2C445&ssl=1)](/content/images/2013/08/nano.jpg?ssl=1)Make a note of the directory, we'll create it next. Now press CTRL + X to quit, and save when prompted.

Step 2 – Create the document root for your domain or subdomain

Next, we'll need to create and set the correct permissions to the document root. You can choose whatever path to use, but I'm creating mine inside a directory called vhosts inside the www folder.

If you've not already created the ‘vhosts' directory already, you'll need to create this first:

After this, create the site's directory:

If you've not already created the ‘vhosts' directory already, you'll need to create this first:

Almost there! Now we need to set the permissions so that the system can write, and everyone else can read:

Step 3 – Enable the subdomain or domain and restart Apache2

Next, we're going to use a built in extension to enable the submain or domain:

Now, it's time to restart apache:

Step 4 – Give it a try!

Apache Web Server Windows

Let's create a file in our site's directory to give it a go. Type the following command to create our index.php file:

Now type the following into?resize=695%2C448&ssl=1)](/content/images/2013/08/PHPinfo.jpg?ssl=1)

Give it a go, visit your subdomain and you should see the PHP info. Replace the index.php file with your subdomain or virtual host, and that's it. Just in case you wondered what video is on my video.dingleberrypi.com it's below!

Leave a comment below (or on the video if you really want to). Your feedback and thoughts always welcome!

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.

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

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

Apache Web Server Raspberry Pi

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.

Apache Web Server On Raspberry Pi

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.

Raspberry Pi Website Host

Server

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.

Install Apache Web Server Raspberry Pi

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.