Linux Lab 05 - Creating a LAMP Server
In this lab you will turn your Linux computer into a LAMP server. A LAMP server is made up of four things. An operating system (Linux), a web server (Apache), a database engine (MySQL), and a server side scripting language (PHP).
We've already installed the L in LAMP in lab 1 when we installed Linux. Now we need to install the A in LAMP. Apache will turn our server into a web server. It will share out data to our clients using web technologies. Type in sudo apt-get install apache2 to install Apache.
After Apache is installed test it out. Open Firefox inside the virtual machine and type the URL http://localhost. Notice the root location of the website, we're going to need that later. /var/www/html. You'll also see the configuration layout listed. Apache Your computer is now a web server. At this point you could use it to host static websites.
Now we're going to skip to the P in LAMP. PHP is a server side scripting language that's used to make your websites more dynamic. The PHP code runs on the server and generates the page on the fly and sends it to your browser. Type in sudo apt-get install php5 libapache2-mod-php5 to install PHP. If that doesn't work type in type in sudo apt-get install php libapache2-mod-php
After PHP is installed we want to test it. We'll create a test php file to verify the server side code is running. Type in sudo nano /var/www/html/phptest.php to create the test file and open it in nano, the terminal based text editor.
Add the following text to the file <?php phpinfo(); ?> When done save the file and exit the text editor. CTRL+O, CTRL+X.
Now that we have a test file in the root of the web server let's test it out. Open Firefox inside the virtual machine and type the URL http://localhost/phptest.php If everything is setup properly you should see information about your system, PHP and Apache installation.
We have one more thing left to install before our server is a LAMP server. We need a database that the server side script will connect to in order to retrieve the data needed to build the pages. MySQL is the M in our LAMP server. Type in sudo apt-get install mysql-server to install MySQL.
During the installation it will ask you to set the password for the root user of MySQL. Use P@ssw0rd for the password.
Once the installs done we want to test it. We will create and delete a database using the terminal to make sure it's working. Open the MySQL console by typing mysql -u root -p Enter the password, P@ssword, and type in create database testdb; to create the database. If all looks good delete it by typing drop database testdb; When you're done in the MySQL console type in quit to exit and return to the shell.
Testing our LAMP Server
Our LAMP server is setup. Now we want to install a program that will verify everything's working, and provide a nice interface to MySQL. We're going to install a program called phpMyAdmin. Type in sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
During the installation you will be asked what program you're using for a web server. Select apache2.
You will then be asked if you want to create a database that will be used by phpMyAdmin. Select Yes.
The installer will need the MySQL root password to create the database, type it in now. P@ssw0rd
Now you will need to create a password to log into phpMyAdmin once the install is done. Type in P@ssw0rd
Once the installs done open Firefox inside the virtual machine and go to the URL http://localhost/phpmyadmin If everything works right you should see a logon screen. Log on using root for the username and P@ssw0rd for the password.
It works, you've successfully created a LAMP server.