If you are not currently logged into your master server, do so with the ssh command.
ssh root@your.master.public.ip.address
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:
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.
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
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.
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).
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.
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:
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.
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