[Download the Complete Tutorial as a single PDF]
This article is a continuation from this post. Previously, we have provisioned our RasPi 2 and installed BIND on it. We also transferred DNS zones from our Windows DNS system to the RasPi.
In this post, we will see how to install and configure Apache web server and install the PHP scripting language.
Installation
The installation itself is very simple. Login from PuTTY and do:
# apt-get install apache2 apache2-utils php5 php5-gd php5-mysql
Note that you need php5-gd if you are going to be using any WordPress plugins that generate PDFs automatically. I do (as you can see) on this blog and hence I need it. Without this plug in (it is NOT installed by default), the PDF plugins will fail. Answer “y” to the prompt to install the packages and sit back.
Configuring Apache
Once installed, we need to configure Apache. Now, the “apache” we installed is called “apache2” (like “bind9” for the BIND we installed earlier). Many files and folders will be named “apache2”, make note of this to go along. I am going to do this the easy way — from WinSCP.
From WinSCP, on the right-side, navigate to the “/etc/apache2” folder. Find “apache2.conf” there and double-click it.
- CTRL+F to find “
DefaultType
”, you will land in a line that starts “# DefaultType
”, scroll down further to below the large explanation of what this is all about. We will set it to “application/octet-stream
” because it is a nice thing to do. No data should be sent to a client without a content type value. Hit enter to add a new line and type (no “#
” at the start): -
DefaultType "application/octet-stream"
- Scroll a little bit below (just after the
HostnameLookups
, leave that Off as it is) and find an entry that starts “ErrorLog
” with a path after it. We need an error log to tell us what went wrong if something breaks. Remove the “#
” in front and edit the path to point to “/var/log/apache2/error.log”: -
ErrorLog /var/log/apache2/error.log
- Just below that for “
LogLevel
”, edit as below. Anything more will unnecessarily flood the logs and we are not going to look in everyday anyway. -
LogLevel error
- If you really want to see for yourself if RasPi is serving up the files, anywhere on a blank line, but before the “
Include
” lines towards the end of the file, add this (you can set any value instead of X-Server-Name
and “RasPi-Kumbaya
”): -
Header add X-Server-Name "RasPi-Kumbaya"
Hit the floppy icon on top to save the file.
Next, we need to enable some mods (modules) of Apache to enable some of this stuff and others required by WordPress. To do so, we again resort to the command prompt. Apache provides the macro “a2enmod
” (Apache2 Enable Module) to do this:
# a2enmod alias autoindex cache cgi env expires headers mime negotiation
php5 reqtimeout rewrite setenvif status
Some of them may already be enabled, others will get enabled. The tool will tell you to restart Apache, don’t do that yet.
We are not done yet. We are not reloading or restarting Apache just yet, because we still need to transfer in the WordPress files. We will do that in two posts from now. After that, we will create the virtual hosts in Apache and restart it. Next up, we install MySQL.