Install Your Webserver Stack

Install the Mission Critical Packages

If you are not currently logged into your master server, do so with the ssh command.

ssh root@your.master.public.ip.address
  • Reminder: Insert the IP address corresponding to your server.

We can install everything your webserver needs with one simple command in the terminal:

sudo apt-get install apache2 libapache2-mod-php5 php5 php5-mysql mysql-client gcc -y

With the server busy let's take a moment to look over what was installed:

  • Apache2: This is the web server. While other web servers exist, Apache will work just fine for our purposes and is the most commonly used web server on the Net. After all it's the A in LAMP
  • PHP 5: This will install the current version of PHP 5.x. PHP is one of the most common languages for websites on the Net and is responsible for everything under the hood of WordPress. WordPress is coded in PHP so your server must know the language.
  • MySQL client: This will handle connections from the server to the Cloud Database.
  • GCC: This is the GNU C Compiler. This open source library allows the server to interact with and compile C-based programs. While technically not required yet, this will be used later to make and install the Lsync utility. Also it is always a good idea to have gcc installed in the event you need to install something from source.

Once these packages are finished installing, your Cloud Server, paired with your Cloud Database, should have everything required to work as a fully functioning web server.

Start Apache

In the Linux world, programs are known as services. They are started by special scripts known as init scripts kept in the /etc directory. Let's boot up the Apache web server by starting its process with the corresponding init script.

sudo /etc/init.d/apache2 start -y
  • You may notice Apache gives you a message stating it "Could not reliably determine the server's fully qualified domain name (FQDN)". This is because we did not set a FQDN within the Apache config file. Don't worry, this will not cause any issues and the web server will still function properly.

Once started, Apache will be added to the upstart service. The upstart service handles the processes started when a server boots up. This means if your server needs to be rebooted, Apache will start automatically. In other Linux distributions, this is not the case and services need to be configured to start upon boot through the use of run levels. This is another reason why we chose Ubuntu to perform this walkthrough.

Test Apache

You can test Apache right from your web browser. Open a new window and enter the IP address of your server in the address bar.

If Apache is up and running without issue you will see the default Apache index.html page. As the page notes, "It works!", you are now serving web content out of your default web directory(/var/www).

Connect to your Cloud Databases

Let's connect to our Cloud Databases instance to ensure it can communicate with your server. To connect, we'll use the command line MySQL client we installed earlier. Use the hostname of your Cloud Databases instance and the associated username. You will be prompted to enter your password once a connection is made.

sudo mysql -u username -h hostname -p

A successful connection and password input results in the presentation of a MySQL shell. This looks very similar to what we have been looking at except now we have MySQL> as our prompt. Our test connection so type exit to get back to your Cloud Server.

Extend PHP

Your webserver is now fully operational. But we can maximize our WordPress functionality by installing a few extra PHP modules. In a terminal, enter the following:

sudo apt-get install php5-imagick php5-mcrypt php5-gd php5-memcache php5-curl

Here's what we just installed:

  • image libraries for server-side image manipulation (used in gallery and portfolio plugins)
  • crypto libraries (handles encryption algorithms)
  • GD libraries ( allows access to information stored in JPEG and TIFF formats )
  • Memcache libraries ( enables information caching )

Add Postfix for Email

WordPress occasionally needs to send you email. To enable this funtionality, we install Postfix, a mail server.

sudo apt-get install postfix mailutils -y

You will need to supply a few parameters to complete the installation. When prompted for "type of setup" select "Internet Site".

Next you are asked for the servername. Insert the FQDN (fully qualified domain name) of your site. Though it may be redundant, an example of a FQDN would be www.example.com.

The Postfix installation can be tested via the mail command. To test simply run the command below inserting your email address in place of the example.com address.

mail user@example.com

Press enter when asked to include a CC address. Give your email message a subject and press enter. Type in some text for your message and press enter again. Pressing CTRL+D will end the mail transaction. The server queues your message and sends it to the email address supplied. You should see the email momentarily.

Now that we've confirmed Postfix works, our server is ready for WordPress. See "Additional Information" below if you'd like to learn more about Postfix.

Mod_rewrite for Permalinks

Permalinks let you use a custom URL page structure. To configure permalinks we need to enable the Apache rewrite module with the following command.

sudo a2enmod rewrite

The rewrite module is now enabled for Apache. Our last step in turning over our Cloud Server in a web server is to allow access to the web directory. To do this, we must modify the configuration file in Apache's sites-enabled directory.

Before editing a configuration file it is always a good idea to create a backup in case something unexpected happens while editing. Run the command below to make a copy of the config file.

sudo cp /etc/apache2/sites-enabled/000-default /etc/apache2/sites-enabled/000-default.backup

Great, now you are ready to edit the file itself. Since we only need to change the option on line 11 from "AllowOverride None" to "AllowOverride All", let's use a quick shell script to target only that line and change "None" to "All".

sudo sed -i '11s/None/All/' /etc/apache2/sites-enabled/000-default

In order for Apache to interpret the change you just made, it requires a service restart.

sudo service apache2 restart