In this part of the series, I want to explain, how to install Apache2 and PHP5 on your Ubuntu Server (which we installed previously).
So, let’s get started by logging into the server and gaining ‘root’ :
sudo -su –
Now, as ‘root’ we can enter the following commands to update the list of available packages (1:) and to install Apache2 (2:):
1: $> apt-get update
2: $> apt-get install apache2-mpm-prefork
Here, we use the
apache2-mpm-prefork version because we need a solution which deals each request completely isolated. For more information read the Apache2 docs.
Before we start messing with it, you might as well check that Apache is working. Point a browser at http://yourdomain or http://yourIPaddress and verify that you see the installed default Apache site. If you don’t, check your DNS and firewall. Fix whatever the problem is before you go on.
I decided to enhance the security a little bit and got some tips by reading the Security Tips on the Apache site. There are two possible ways.
- You can add these to the main config file.
- But, I opted to keep my own config changes separate by putting them in a file in the /etc/apache2/conf.d/ directory
So, because I chose the second way, I created under
/etc/apache2/conf.d/ a file named
local_configs.conf and put the following in it:
# Tighten access to the file system.
# Forbid default access to file system locations
Deny from all
# prevent use of .htaccess files in all directories
# apart from those specifically enabled.
# Limit available info about this server.
The file creation can be done by using
vim as follows:
$> vim /etc/apache2/conf.d/local_configs.conf
And, using the shortcut “
i” to insert some text in the newly created file. To quit and save the file press the
ESC-key to enter command-mode and then pressing
SHIFT and the ‘Z’-key twice) to save and quit.
If you want to discard some changes, you can press the
ESC-key to enter command-mode and then
:q! to quit without writing anything to the file.
Now, we have to force Apache2 to load the new config-file by entering in the command line:
$> /etc/init.d/apache2 force-reload
With our Apache2 web server running, we can install PHP5 with the following command:
$> apt-get install libapache2-mod-php5
There is a good sample php-config-file:
/usr/share/doc/php5-common/examples/php.ini-recommended, we’ll use. It contains the “warmly recommended”
php.ini settings for production servers. This file is very well commented and worth the time to read.
So we first save a copy of the original php.ini file and copy the recommended file in place of the original file:
$> mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.original
$> cp /usr/share/doc/php5-common/examples/php.ini-recommended /etc/php5/apache2/php.ini
By editing the php.ini and changing the
expose_php from “on” to “off”, we hide info about our php config by telling PHP to hide itself.
expose_php = off
So, that’s all by now….
Nice, isn’t it?
But, we haven’t reached the end… Let’s go one step further by: Installing MySQL and phpMyAdmin