LAMP & WordPress Installation

First please read through this entire document and all referenced documents first and this is substantial (hours).  This FP not only garners full credit but it also has an optional extra credit component for students that implement this in the Amazon EC2 Cloud.

Second, note this will be installed in your Ubuntu LTS implementation and while WordPress instructions are located in the submenu, you will submit a single file with screenshots of both the LAMP installation and configuration and the WordPress installation.

Third, as previously recommended, please take a snapshot of your Ubuntu Guest OS prior to installation where directed below.

Introduction

Well, while we are going to investigate today’s n-tier Web architecture (in our case we will simply explore and implement a 3-tier architecture) we are also going to have the opportunity to investigate a few other things.  

As background let’s recall that a VM image or instance or guest OS is simply a file that encapsulates an entire system (i.e. OS + applications + files).  What exactly is the system you are running on right now?  It is an OS running on your hardware accessing and controlling your processes and resources.  In our VM world, the VM simulates your hardware (actually it is a level of abstraction that provides a virtual hardware interface that your guest OS interfaces with and VB in-turn accesses your underlying host OS and hardware – recall VB networking with Bridged and NAT). Back on your host PC/Mac OS, you could capture the state of your system by packaging up all the files (programs and data) however this image would probably not work on someone else’s system due to (among other things) the specific nature of each system’s specific device drivers however a VM overcomes this.  A VM provides the identical architecture to your guest OSs whether you have a Mac, PC or Linux host OS running beneath the VM.  Do you see the beauty of this?  If you create an application you can create it for a specific OS, package it with the VM OS and distribute as an appliance.  In this model the VM  becomes responsible for providing a consistent platform and managing the new versions of Mac/PC/Linux  OS and the intricacies of each system.  On your tech support side (one of the high costs of system deployment) you see the same architecture across all your deployed users.  

There are many emerging Ubuntu appliances and that is the case with open source Web development frameworks like WordPress and Drupal.  As an example, both Turnkey and Bitnami have an Ubuntu Server Appliance complete with a preconfigured WordPress instance.  I had originally explored this option however Turnkey uses an Ubuntu Server installation and while it is not difficult downloading and configuring a GUI (Servers don’t necessarily have a GUI), it introduced another layer of complexity so I opted for a manual installation of everything in a GUI environment.   This approach probably has better teaching value as you will become very familiar with the individual elements however for your knowledge note there are  pre-existing VM images.

LAMP Stack and WordPress:

Before starting your implementation, please read about the LAMP stack here: http://en.wikipedia.org/wiki/LAMP_(software_bundle) .  You will read about the WordPress Web/Content Management system (CMS) shortly however in a nutshell, WordPress is a Web/content management system that runs on today’s 3-tier Web architecture typically implemented as:

1. Apache Web Server – from http://net.tutsplus.com/tutorials/other/an-introduction-to-apache/

The Apache HTTP server is the most often used Web server  and it is a software (or program) that runs in the background and provides services to other applications that connect to it, such as client web browsers.  A Web server’s job is basically to accept requests from clients and send responses to those requests. A web server gets a URL, translates it to a filename (for static requests), and sends that file back over the internet from the local disk, or it translates it to a program name (for dynamic requests), executes it, and then sends the output of that program back over the internet to the requesting party. If for any reason, the web server was not able to process and complete the request, it instead returns an error message. The word, web server, can refer to the machine (computer/hardware) itself, or the software that receives requests and sends out responses.

2. PHP business logic and,  

3. MySQL backend database.  

This is also referred to as an AMP stack and it is available for Linux (LAMP), Mac (MAMP) and Windows (WAMP or just AMP).  Now we could easily do the same thing in your Windows or Mac but again, running things in a VM provides consistency  and extra security as you will be firing up a Web server.  Firing up a Web server on your host machine opens your machine to Web attacks from the world whereas if you do this in a VM, the world can only compromise that single virtual disk file (i.e. your host system remains safe).  Lastly, you should note that developing and testing on a local machine is a better approach rather than developing on a live deployed system and WordPress has a publishing feature that will automatically update your live enterprise Web site from your local development site.

Repositories

First, if you haven’t explored repositories (apt-get) or even if you have, please read the following as this is an essential SysAdmin tool and understanding:

https://help.ubuntu.com/community/AddingRepositoriesHowto

Ok, let’s get started.  

First, please take your time and record your steps as this will be necessary for the DB discussion/documentation.  You do not need to repeat all steps provided here in the instructions just where things went right or wrong, what other resources you used, your thoughts on the process, etc. If you get an error message, check your work and try again. If this fails, please research online using keywords from your system, step, error message, etc. (e.g. Google “Ubuntu WordPress failed database”, etc.)  In contrast to a production system and for ease of use, I also recommend you use the same password across the various applications (includes your Ubuntu password).

Installation Preparation

First, make sure your system is up to date by running update manager or manually run $ sudo apt-get update and $ sudo apt-get upgrade in the Terminal.  Note you are not upgrading Ubuntu versions as we need a stable LTS version and to this extent you should always deploy LTS versions for production and cloud systems. 

Now that we have an updated stable system, take a snapshot of your Ubuntu instance naming it as you wish (e.g. PreLAMP-Date).  You may have to shut down your system and restart it but this is important as it will allow you to backtrack should anything untoward happen.  Also note, while not green, it may be beneficial to print out any referenced documents, tutorials or directions and mark up these documents as necessary as you proceed as this will improve the DB postings and support your technical communication and learning.

Ok, so the reading for this project is substantial which is one of the reasons for the prolonged nature of this project.  First, I recommend you read about WordPress here: www.wordpress.org.   Second, just to become more informed, please read the famous WordPress 5-minute install here:

http://codex.wordpress.org/Installing_WordPress.  

We will follow the WordPress installation instructions located here: https://help.ubuntu.com/community/WordPress however I will provide these directions augmented with my advice below so please follow my instructions.  

Additional Ubuntu WordPress installation resources may be found here and you can also search YouTube for multimedia presentations but again, please follow my instructions as students have broken their systems following YouTube installation instructions. Again, the more preparation you do the better but again, please follow my instructions.  If something goes wrong Google a solution as I cannot predict all complications for all platforms.

https://help.ubuntu.com/community/WordPress

http://tech.mobiletod.com/wordpress-installation-ubuntu-through-lamp-server/

LAMP Installation in Ubuntu instance

The LAMP installation instructions used to construct these instructions is located here: https://help.ubuntu.com/community/ApacheMySQLPHP  

Please see and reference the above page as necessary but things change. You will also see a packaged LAMP installation using tasksel and lamp-server but I have found this to be erratic so we will step through the old-fashioned was as this is a better learning experience. So to begin:

1. Open your VM

2. Start your Ubuntu instance 

3. Open a terminal (Again, I recommend you drag this from accessories to your desktop for easy access if you have not done so as we will use it a lot!).

Apache Installation

Enter the following in the terminal

$ sudo apt-get install apache2

We now need to test that our Apache Web Server is working so open Firefox in the VM and enter the following into the Web browser’s address bar:

http://localhost/

now try the loopback that we use to test our OS’s TCP/IP stack

127.0.0.1 

You should see – “It works!” in each case and you have just installed and started your first Web server!!!!!

Now you will use this address often so you can bookmark or pin the tab so that it remains easily accessible. I actually delete “Most Visited”, “Getting Started”, etc. and I also rename this http://localhost quasi-bookmark “Localhost” removing the http:// to save space on this level (right click – properties to perform this)

PHP Installation

In the terminal enter:

$ sudo  apt-get  install  php5  libapache2-mod-php5 #allow to continue (e.g. “y”) when prompted

$ sudo /etc/init.d/apache2 restart   #Restarts Apache so that it recognizes PHP install.  

#Note we had to use full path beginning at root as this is not in our PATH/path variable’s environment.  If this does not make sense to you, here is a good point to reread the assigned readings as you are missing requisite knowledge  (note I stated at the outset that everyone must continually review the material).

Now enter:

 $ sudo gedit /var/www/phptest.php #you should run this in the background

This will open gedit with root privileges.  Why is this necessary (perform ls –l on var/www directory at later date to see who owns the files and their permissions). Note gedit is also available from applications->accessories so you could also go this way saving the file phptest.php somewhere in the filesystem and later copy it /var/www directory but you would also have to change permissions (chmod) or change owner (chown). 

Now enter the following in the open gedit phptest.php and save the file (make sure it is saved correctly in var/www by navigating to this directory where var is two levels above your home directory).  If it is not saved correctly you may have to use “Save as” and navigate in the “File System”.   BTW – if you look in the /var/www directory you will see index.htm that displayed the “It Works” in your browser.  

<html>

<head>

<title> Your Name PHP Test Script </title>

</head>

<body>

<?php

print_r (phpinfo());

?>

</body>

</html>

Open your browser and enter http://localhost/phptest.php in the address bar and you will see the PHP environment settings in a page with your name as the tab heading.  Of course this was a nice demonstration of HTML opening and closing tags and the phpinfo method call.

Assignment Screenshot 1:

To document installation, take a screenshot of this php generated page with the title and copy your pdf document titled: LastnameFirstnameLampInstallation and preface the screenshot with Assignment Screenshot #1.  Now if you wish you can use your Ubuntu Linux Writer which is located in the left panel.  You can find your Ubuntu screenshot app by searching in your Dash search box.  BTW – it is not a bad idea to print the PHP info page out for later reference.

Continuing on:

You will need to close your gedit window to return focus to your Terminal if you didn’t run it in the background and hopefully you remembered how to run programs in the background.  

MySQL Installation

In the terminal enter

$ sudo apt-get install mysql-server # accept with “y” when prompted

Set your password when prompted noting that you are user root and using the [tab] key to move to “Ok” if necessary.  For our test “classroom” purposes I recommend you use consistent passwords but in a real production system you should make this a strong…. very strong password as this is your database and should it be compromised…. bad… very bad things can happen (e.g. I could take over your site and capture/present whatever I wanted to).

Optional and we will not do this… you should not do this…  but for completeness, if this were a production environment, in order for other computers on your network to view the server you have created, you must edit the /etc/mysql/my.cnf file to correctly bind the IP address (e.g. “Bind Address”).  Again you would use sudo gedit for this and change the 127.0.0.1 to your IP address.  This would result in a static IP.  

$ mysql -u root

and then 

mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘yourpassword’);al

phpMyAdmin Installation

Now working with MySQL from the command line is a pain so let’s install phpMyAdmin to manage and edit the database (Recall DBMS and all the management that takes place).  There are more robust automated installations available but again we need to learn this from the ground up so we will do almost everything discretely and manually.

Enter the following:

$ sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin # accept ‘y’  

Choose apache2 Webserver using the spacebar to add an X in apache2 (not lightpd) and tab to ‘Ok’ and ‘Enter’

Allow the installation app to configure a MySQL DB (e.g. ‘yes’), provide a password, [tab] to ‘Ok’, verify password again and reset apache as done previously.  

$ sudo /etc/init.d/apache2 restart   

if you were sysadmin you may want to add the etc/init.d path for ease of use but you may of course use the arrow keys to bring up recent CLI commands

phpMyAdmin Installation Verification

Now open a browser and enter the following in the address bar – http://localhost/phpmyadmin

Enter root as username and your previously entered password to verify that everything is up and running – please do not change anything.  Btw – It is not a bad idea to drag this tab up into your quick access menu and rename it phpMyAdmin in properties for quick access

Note to anyone who encountered problems with setting up the MySQL password, please refer to this page for instructions: MysqlPasswordReset – https://help.ubuntu.com/community/MysqlPasswordReset

Also, should phpmyadmin not open (i.e. if you get a 404 error upon visiting http://localhost/phpmyadmin: You will need to configure apache2.conf to work with Phpmyadmin)  you will have to perform the following:

sudo gedit /etc/apache2/apache2.conf

Include the following line at the bottom of the file, 

include /etc/phpmyadmin/apache.conf

Save the file and quit gedit.

Now we must restart or stop and start Apache using one of the following:

 $ sudo /etc/init.d/apache2 restart

Or

$ sudo /etc/init.d/apache2 stop

$ sudo /etc/init.d/apache2 start

So should anything go drastically wrong, you can simply go back to the previous VM snapshot or even delete/remove the Ubuntu instance from the VM when it is powered down and start over.  If this should happen to you, welcome to the club as this has happened or will happen to every Sys Admin professional at some point (It actually happened to me when using the simplified tasksel/lamp-server installation which is why I don’t recommend that option).

Importantly, if you are here, congrats you have now installed both Apache and PHP! 

Assignment Screenshot 2:

Please take a screenshot of phpMyAdmin and paste it into your assignment.

Setting up MySQL for WordPress:

First we need to set up our database where WordPress will store and access all information (This is the core DBMS of our 3-tier architecture and the DBMS provides the necessary functionality for significant business analytics allowing us to continually tailor user experience ex: Amazon.com, eBay, CNN, New York Times and many other WordPress sites).    From the famous 5-minue install of WordPress I have copied the phpMyAdmin instructions below.  Now again I recommend you pre-read this section and move very slowly and double check and write down everything as you go.  

Using phpMyAdmin Note: These instructions are written for phpMyAdmin 2.6.0; the phpMyAdmin user interface can vary slightly between versions. 

Creating WordPress database using phpMyAdmin

1. Choose ‘Databases’ from the menu and then create a new database, choose a name (‘wordpress’ is good), enter it in the Create new database field, and click Create. 

2. Choose/click the newly created wordpress database in the database list and then click Privileges (Try the More menu if you don’t see it but note from this point on you should be exploring the menu system to find the functionality I reference).  If wordpress user does not already exist in the list of users, create one: 

3. Click Add a new User. 

4. Chose a username (‘wordpress’ is good) and enter it in the User name field. (Be sure Use text field: is selected from the dropdown.) 

5. Make sure Host is set to local which will populate the associated field with localhost.

6. Choose a password and again while we normally select a difficult-to-guess unique password (ideally containing a combination of upper- and lower-case letters, numbers, and symbols) I recommend a consistent password for this exercise and enter it in the Password field. (Be sure Use text field: is selected from the dropdown.) Re-enter the password in the Re-type field. 

7. Write down the username and password you chose. 

8. Select “Grant all privileges on database “wordpress”” and check all global privileges (we wouldn’t actually do this in a production system but it may prevent some problems and this is just a local inaccessible implementation).  

9. Double check your entries and then click Go at the bottom of the screen. As a learning experience, have a look at the SQL phpMyAdmin generated.

10. Everything should be copasetic but just so you know, click the “wordpress” database in the left hand database list.  Note the red “Drop” command in “More” “Operations”.  This can be used to drop the newly created “wordpress” database and its users should you need to start over.  Note you may have to do this at some point but this illustrates that you can make mistakes, backtrack and begin anew.

Alternative privilege granting method: Return to the Privileges screen and click the Check or Edit privileges icon on the user you’ve just created for WordPress (it was all the way to the right for me). In the Database-specific privileges section, select the database you’ve just created for WordPress (e.g. wordpress) under the Add privileges to the following database dropdown. The page will refresh with privileges for that database. Click Check All to select all privileges, and click Go. 

Assignment Screenshot 3:

Please take a screenshot of phpMyAdmin and paste it into your assignment.

Zowie!!!

If you are here, congratulations as you have now installed the LAMP stack in preparation for WordPress!  Now if you were not careful you could have arrived here with mistakes in your implementation and these will become apparent when you install WordPress next.  If this happens you will have to retrace your steps and maybe even reinstall but this too is a learning experience.

Most importantly, I hope you understand you are now running a Web Server and I hope you realize that you can do anything with the proper research and preparation. Note the research and preparation can be substantial taking even months or years but you should realize you can take your computing to any level you desire.

Take a break as necessary and you are ready for the WordPress installation next (found in the sub-menu structure).  It is also a good idea to take a snapshot of your system at this juncture.  

Note we will continue inserting screenshots into your FP assignment PDF so please do not submit it yet.

Help and Alternate Installations

There are many alternate installation tutorials on the Web and YouTube.  This is a very nice alternate installation.  If you experience problems with the installation above that cannot be resolved I recommend you try the following link’s instructions with a few modifications.

1. Do yourself a favor and use gedit instead of nano as the author recommends.

2. Please create a phptest.php file per above rather than the author’s info.php

3. Edit the wp-config file per the above instructions but of course substituting the correct db, username, password, etc.

http://www.wpexplorer.com/locally-install-wordpress-on-ubuntu/


?

Leave a Reply