• No results found

Putting It All Together

In document 01_PHP_Rev1_4_IG (Page 53-57)

ACTION (You Do) COMPUTER RESPONSE / Comments

SHOW DATABASES;

3. Under the Complete Source Code heading,

2.6 Putting It All Together

Now that all the components of the LAMP architecture are set up, it is time to test each of the components and verify that everything is working correctly.

Restarting Apache

Apache was shutdown during the installation of MySQL and PHP and should be started back up to provide the web services necessary to test the PHP installation. To start the Apache server again, choose the apache2/bin directory. This directory contains the files associated with executing the components of the Apache server. The Apache server can be started by executing apachectl start from this directory.

Testing PHP

With the Apache server back up an running, it is time to test the installation of PHP on the server. This is accomplished by creating a test PHP file in the /usr/local/apache2/htdocs directory. This file (which is usually called test.php) will contain a PHP command (<?php phpinfo(); ?>) that will display all the configuration information associated with the local PHP installation.

Automatic Starts of Apache and MySQL

Up to this point, Apache and MySQL were manually being started and would need to continue to be manually started every time the operating system was restarted. This is not the most effective approach for many reasons, least of them being they are easy to forget at start up time when needing to be started manually.

Linux (along with practically every other operating system) has the capability to start applications when the operating system is loaded (during planned or unexpected restarts). In Linux, this is accomplished by placing a copy of the start up executable files into the /etc/init.d directory. In addition, some additional steps such as making the new files executable and executing a Linux tool (update-rc.d) to ensure that all the proper links on the operating system are made to ensure each component is started when the operating system starts up.

Updating the Exectuable Paths

We now have apache and all the associated executables in our /usr/local/apache2/bin directory. Our life would be easier if we could type apachectl instead of the full path over and over again. In addition, the same is true for running the mysql client. In order to do that we edit an environment variable called path.

A number of files are read when we log in. One of them is /etc/profile but that requires that we login to activate. /etc/bash.bashrc is a good place, each new console that is launched reads /etc/bash.bashrc and thus adding the following lines to our /etc/bash.bashrc file will prevent us from needing to provide the full path everytime we want to execute a command from these directories:

PATH=${PATH}:/usr/local/apache2/bin:/usr/local/mysql/bin

Once that file is updated and saved, any new terminal windows (consoles) that start-up will have those in the path allowing mysql and/or apachectl to called without the paths preceding them.

35

Lab 2-D

In this exercise you will complete the final steps of setting up the LAMP architecture along with testing the setup. In addition, you will configure the operating system to start up MySQL and Apache automatically when it starts up.

ACTION (You Do) COMPUTER RESPONSE / Comments

1. In the /etc/ directory, edit the following file:

vi bash.bashrc

There are a couple of files that modify your PATH.

They all work but some are read all the time for everyone, some are read for each user.

/etc/bash.bashrc only works for bash but it is automatic when a console is launched, no global logout required (unlike the profile files).

2. Locate the end of the file and add the following and then save and close the file:

PATH=${PATH}:/usr/local/apache/bin:

/usr/local/mysql/bin

The path for the apache server and the MySQL server binary directories is added to the path preventing us from needing to precede each command with the full path.

3. To be able to use the "path-less" approach to executing apache and mysql commands, shut down the current terminal window and open a new one.

This will give you access to using the "path-less"

approach.

4. Execute the following command (from any directory due to our PATH having the binary directory of Apache):

apachectl start

This will restart the Apache server.

5. In the document root directory of Apache, located at /usr/local/apache2/htdocs, create a new file called test.php containing the following line of code:

<?php phpinfo(); ?>

Close and save the file.

This file will display all the configuration options of PHP when called from the http://localhost directory in the web browser.

6. In your web browser, call up the following URL:

http://localhost/test.php

This will display multiple configuration options showing that PHP, Apache and MySQL are working.

7. In the operating system terminal window, copy the mysql.server file to the /etc/init.d directory to ensure that MySQL will start when the operating system starts:

cp /usr/local/mysql/

support-files/mysql.server /etc/init.d/mysql

This step will copy the MySQL startup file to the /etc/init.d which is a directory containing initialization and termination scripts for changing init states.

ACTION (You Do) COMPUTER RESPONSE / Comments

8. Add the ability for the new file in the /etc/init.d directory to be executed:

chmod +x /etc/init.d/mysql

This will give the new file created,

/etc/init.d/mysql to be executable thus allowing it to execute when the operating system starts up.

9. To complete the process of MySQL being started when the operating system is started, execute the following command:

chkconfig –-add mysql

update-rc.d is a utility (on Debian operating systems) that creates all the appropriate links to ensure that a file is executed on start up.

10. For Apache, the process of ensuring that the web server starts up on the operating system start up is similar to MySQL. The first step is to make a copy of the apachectl executable in the /etc/init.d directory:

chkconfig –-add httpd

This step will copy the Apache startup file to the /etc/init.d which is the same directory where the MySQL startup script was placed.

11. Add the ability for the new file in the /etc/init.d directory to be executed:

chmod +x /etc/init.d/httpd

This will make the new file created (

/etc/init.d/httpd) to be executable thus allowing it to execute when the operation system starts up.

12. To complete the process of MySQL being started when the operating system is started, execute the following command:

update-rc.d httpd defaults

update-rc.d will create all the appropriate links to ensure that httpd is executed on start up.

13. At this point, you can shut down your operating system and restart it to check to see if the LAMP architecture starts up as expected.

Once you have restarted your operating system, complete step 3 to test if everything is working.

2.7 Chapter Summary

In this chapter, you have learned to:

• Explain the LAMP architecture The acronym LAMP stands for a group of independent open-source software and tools that when used together allow for the execution, development and deployment of dynamic websites and servers. The tools used reflect the acronym name: Linux, Apache, MySQL and PHP.

• Verify that the Apache Server is installed and running

Being one of the components of the LAMP architecture, it is important to ensure that the Apache Server is installed and running on the Linux distribution being used.

• Verify that MySQL is installed and running MySQL AB is responsible for maintaining and supporting the MySQL Relation Database Server.

Its website is http://www.mysql.com which provides the details associated with the product lines that it offers and further information to install, configure and run the MySQL Server on a wide range of operating systems.

• Verify that PHP is installed and running The sole implementation of PHP is produced by

"The PHP Group" and released under the PHP License.

36

C HAPTER 3

In document 01_PHP_Rev1_4_IG (Page 53-57)