Franske ITC-2480 Lab 5: Difference between revisions
Jump to navigation
Jump to search
BenFranske (talk | contribs) |
BenFranske (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
=Introduction= | =Introduction= | ||
In this lab you will learn about static network configuration of Debian Linux systems, how to install PHP and MySQL on your server, experiment with websites and databases, and some of the standard log files on your system. | |||
=Lab Procedure= | =Lab Procedure= | ||
==Prerequisites== | ==Prerequisites== | ||
# Open an SSH console to your Linux system using the PuTTY software, login with your standard user account | # Open an SSH console to your Linux system using the PuTTY software, login with your standard user account | ||
# Make a note of the static IP address information for your particular system in the table below, it is based on the system name identification letter in vmWare. All systems will use a gateway address of 172.17.50.1 and a subnet mask of 255.255.255.0 | |||
{| {{table}} | |||
| align="center" style="background:#f0f0f0;"|'''System ID''' | |||
| align="center" style="background:#f0f0f0;"|'''Static IP''' | |||
|- | |||
| A||172.17.50.11 | |||
|- | |||
| B||172.17.50.12 | |||
|- | |||
| C||172.17.50.13 | |||
|- | |||
| D||172.17.50.14 | |||
|- | |||
| E||172.17.50.15 | |||
|- | |||
| F||172.17.50.16 | |||
|- | |||
| G||172.17.50.17 | |||
|- | |||
| H||172.17.50.18 | |||
|- | |||
| I||172.17.50.19 | |||
|- | |||
| J||172.17.50.20 | |||
|- | |||
| K||172.17.50.21 | |||
|- | |||
| L||172.17.50.22 | |||
|- | |||
| M||172.17.50.23 | |||
|- | |||
| N||172.17.50.24 | |||
|- | |||
| O||172.17.50.25 | |||
|- | |||
| P||172.17.50.26 | |||
|- | |||
| Q||172.17.50.27 | |||
|- | |||
| R||172.17.50.28 | |||
|- | |||
| S||172.17.50.29 | |||
|- | |||
| T||172.17.50.30 | |||
|- | |||
| U||172.17.50.31 | |||
|- | |||
| V||172.17.50.32 | |||
|- | |||
| W||172.17.50.33 | |||
|- | |||
| X||172.17.50.34 | |||
|- | |||
| Y||172.17.50.35 | |||
|- | |||
| Z||172.17.50.36 | |||
|} | |||
==Set a static IP== | ==Set a static IP== | ||
# Using your text editor of choice, open up the file /etc/network/interfaces | # Using your text editor of choice, open up the file /etc/network/interfaces | ||
Line 17: | Line 75: | ||
gateway xxx.xxx.xxx.xxx</pre> | gateway xxx.xxx.xxx.xxx</pre> | ||
# Now save the file, and exit your file editor. | # Now save the file, and exit your file editor. | ||
# Now we are going to apply the static IP change | # Now we are going to apply the static IP change. Try using ifconfig to view your active configuration now and you should see that your old address is still active. | ||
#* '''NOTE: You should only do network configuration changes when you have physical access to a machine. This way, if you mess up your configuration you will be able to fix it from a local console.''' | #* '''NOTE: You should only do network configuration changes when you have physical access to a machine. This way, if you mess up your configuration you will be able to fix it from a local console.''' | ||
# Using the ifdown and ifup command, we are going to restart the network interface | # Using the ifdown and ifup command, we are going to restart the network interface, this step is required to apply the change. | ||
# In a terminal, run ifdown eth0 && ifup eth0. Notice the two && symbols. This tells the linux shell that it should run the second command right after the first. If we do not define this, then we would be left with a machine that has its networking turned off. | # In a terminal, run ifdown eth0 && ifup eth0. Notice the two && symbols. This tells the linux shell that it should run the second command right after the first. If we do not define this, then we would be left with a machine that has its networking turned off. | ||
# At this point, your machine should now be using a static address. | # At this point, your machine should now be using a static address. You will lose your SSH connection because the IP your SSH session is connected to is no longer in use by your machine. | ||
# Reconnect through SSH to your new IP address and verify it is now applied using the ifconfig command. | |||
==Install PHP & MySQL== | ==Install PHP & MySQL== | ||
Line 35: | Line 94: | ||
phpinfo(); | phpinfo(); | ||
?></pre></li> | ?></pre></li> | ||
<li>Now save the file, and on your local machine go to xxx.xxx.xxx.xxx/phptest.php in a web browser where xxx.xxx.xxx.xxx is your VM's static IP. You should now be on a page that shows your PHP Version, and system information.</li> | <li>Now save the file, and on your local machine go to xxx.xxx.xxx.xxx/phptest.php in a web browser where xxx.xxx.xxx.xxx is your VM's static IP. You should now be on a page that shows your PHP Version, and system information. Use the "View Source" option in your browser to see what the HTML source code is for the page you're viewing is. Is it the same or different than the .php file you created? Why? How is this different than a standard .html file? | ||
* Note: PHP files are really tiny scripts that the webserver must execute in order to render them into HTML for the browser, therefore you may need to make adjustments so that the www-data user (which is the user the Apache webserver runs as on Debian Linux) has execute permission for the .php files you create.</li> | |||
</ol> | </ol> | ||
== | ==Experiment with Websites PHP== | ||
# In a previous lab we learned about editing the /var/www/index.html file to change the default web page displayed by your server. In a future lab you will install some PHP/MySQL based software which powers many Internet sites with forums, blogs, etc. Before we can do that we need to learn a little more about PHP and about databases. Like most software on Linux the Apache webserver configuration files are stored in the /etc directory. Specifically, you can find several of them which work together and are called from each other in /etc/apache2/ take a look in the /etc/apache2/sites-enabled/ directory. See how symlinks are used to point to configuration files which actually reside in the /etc/apache2/sites-available/ directory? This allows us to turn off and on various sites by creating or removing a symlink rather than by deleting the actual configuration file, a handy thing if we just want to temporarily disable a site. | |||
# As you might have guessed the default site for your system is configured by the file linked to at /etc/apache2/sites-enabled/000-default If you open this file in your favorite text editor you will see a series of what Apache calls "directives" which explain how the webserver should function, what port it should listen on, where the website files will reside (/var/www), etc. Going into all of the different Apache directives is outside of the scope of this course but you will find a lot of documentation about them on the Internet. | |||
# In addition to configuring Apache directly through it's configuration files you can also configure it through an interface like Webmin which we installed in a previous lab. Bring up the Webmin configuration page for Apache and take a look at the settings for the default site. Note how the things you saw directly in the configuration file match up with what you see in Webmin. One of the things you may be interested in seeing is how the webserver knows to display the index.html file from a deirctory if it exists and no specific file is requested in the URL. Take a look on the "Directory Indexing" page and see if you can find this information. You'll notice that there is a list of files, not just index.html which the server will display. | |||
# In another section of this lab you created a basic phptest.php file and saw how the server executed the PHP code and turned it into an HTML page your browser could display. Because PHP offers an easy way to write web applications it powers much of the Internet. To prepare us for setting up some PHP applications in a future lab it will be helpful to know a little about how PHP scripts work. Read through the [http://www.w3schools.com/php/default.asp W3 Schools PHP Basics Tutorial] (PHP Intro through PHP Superglobals) and try creating some PHP scripts on your own Linux server like the examples given in the tutorial pages to see if you can get them to run, try modifying them a little bit and see what the results are. There are many great Internet resources devoted to understanding how to do things with PHP so take some time to see how this language can be easily integrated in websites. You should definitely be familiar with editing PHP files to change variables, echo statements, etc. work which are all skills you'll need when installing PHP based website software. | |||
# Try writing some simple PHP scripts on your own using variables and echo statements and make them available through your webserver. Edit your index.html file (or create a new index.php file which will be loaded instead if it exists) so there is a menu for you to find and run the various scripts you have created. | |||
==Experiment with Databases== | |||
==View Logfiles== | ==View Logfiles== |
Revision as of 06:21, 12 February 2014
Introduction
In this lab you will learn about static network configuration of Debian Linux systems, how to install PHP and MySQL on your server, experiment with websites and databases, and some of the standard log files on your system.
Lab Procedure
Prerequisites
- Open an SSH console to your Linux system using the PuTTY software, login with your standard user account
- Make a note of the static IP address information for your particular system in the table below, it is based on the system name identification letter in vmWare. All systems will use a gateway address of 172.17.50.1 and a subnet mask of 255.255.255.0
System ID | Static IP |
A | 172.17.50.11 |
B | 172.17.50.12 |
C | 172.17.50.13 |
D | 172.17.50.14 |
E | 172.17.50.15 |
F | 172.17.50.16 |
G | 172.17.50.17 |
H | 172.17.50.18 |
I | 172.17.50.19 |
J | 172.17.50.20 |
K | 172.17.50.21 |
L | 172.17.50.22 |
M | 172.17.50.23 |
N | 172.17.50.24 |
O | 172.17.50.25 |
P | 172.17.50.26 |
Q | 172.17.50.27 |
R | 172.17.50.28 |
S | 172.17.50.29 |
T | 172.17.50.30 |
U | 172.17.50.31 |
V | 172.17.50.32 |
W | 172.17.50.33 |
X | 172.17.50.34 |
Y | 172.17.50.35 |
Z | 172.17.50.36 |
Set a static IP
- Using your text editor of choice, open up the file /etc/network/interfaces
- Notice how it is currently set to dhcp for the eth0 interface.
- To set a static IP, you will need to change iface eth0 inet dhcp to iface eth0 inet static.
- Now, under the iface line you just edited, you will need to enter the address, netmask, and gateway for the static network.
- Reminder: it is common practice to indent (tab) static network configuration information in the interfaces file.
- Your configuration should be similar to this:
auto eth0 iface eth0 inet static address xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gateway xxx.xxx.xxx.xxx
- Now save the file, and exit your file editor.
- Now we are going to apply the static IP change. Try using ifconfig to view your active configuration now and you should see that your old address is still active.
- NOTE: You should only do network configuration changes when you have physical access to a machine. This way, if you mess up your configuration you will be able to fix it from a local console.
- Using the ifdown and ifup command, we are going to restart the network interface, this step is required to apply the change.
- In a terminal, run ifdown eth0 && ifup eth0. Notice the two && symbols. This tells the linux shell that it should run the second command right after the first. If we do not define this, then we would be left with a machine that has its networking turned off.
- At this point, your machine should now be using a static address. You will lose your SSH connection because the IP your SSH session is connected to is no longer in use by your machine.
- Reconnect through SSH to your new IP address and verify it is now applied using the ifconfig command.
Install PHP & MySQL
- Using aptitude, install the php and mysql packages using aptitude install php5 mysql-server
- Note: Remember to do an aptitude update before installing packages to make sure you get the latest versions
- After the dependencies are found, go ahead and accept them to continue the install.
- During the mysql-server install, you will see a blue window (similar to the debian install screen) that will ask you to create a mysql root password. This password is what will be used to access the root account in mysql. Just like in linux, the mysql root account has full control of all databases hosted on the system. It does not need to be the same as your system root password but just like your system root password it is important that you keep it secure and don't forget what it is.
- After the install is complete, cd to /var/www
- At this point we will test to verify that php is working properly with Apache. Create a new file named phptest.php, and then open it in a text editor.
- Enter the following into the file:
<?php phpinfo(); ?>
- Now save the file, and on your local machine go to xxx.xxx.xxx.xxx/phptest.php in a web browser where xxx.xxx.xxx.xxx is your VM's static IP. You should now be on a page that shows your PHP Version, and system information. Use the "View Source" option in your browser to see what the HTML source code is for the page you're viewing is. Is it the same or different than the .php file you created? Why? How is this different than a standard .html file?
- Note: PHP files are really tiny scripts that the webserver must execute in order to render them into HTML for the browser, therefore you may need to make adjustments so that the www-data user (which is the user the Apache webserver runs as on Debian Linux) has execute permission for the .php files you create.
Experiment with Websites PHP
- In a previous lab we learned about editing the /var/www/index.html file to change the default web page displayed by your server. In a future lab you will install some PHP/MySQL based software which powers many Internet sites with forums, blogs, etc. Before we can do that we need to learn a little more about PHP and about databases. Like most software on Linux the Apache webserver configuration files are stored in the /etc directory. Specifically, you can find several of them which work together and are called from each other in /etc/apache2/ take a look in the /etc/apache2/sites-enabled/ directory. See how symlinks are used to point to configuration files which actually reside in the /etc/apache2/sites-available/ directory? This allows us to turn off and on various sites by creating or removing a symlink rather than by deleting the actual configuration file, a handy thing if we just want to temporarily disable a site.
- As you might have guessed the default site for your system is configured by the file linked to at /etc/apache2/sites-enabled/000-default If you open this file in your favorite text editor you will see a series of what Apache calls "directives" which explain how the webserver should function, what port it should listen on, where the website files will reside (/var/www), etc. Going into all of the different Apache directives is outside of the scope of this course but you will find a lot of documentation about them on the Internet.
- In addition to configuring Apache directly through it's configuration files you can also configure it through an interface like Webmin which we installed in a previous lab. Bring up the Webmin configuration page for Apache and take a look at the settings for the default site. Note how the things you saw directly in the configuration file match up with what you see in Webmin. One of the things you may be interested in seeing is how the webserver knows to display the index.html file from a deirctory if it exists and no specific file is requested in the URL. Take a look on the "Directory Indexing" page and see if you can find this information. You'll notice that there is a list of files, not just index.html which the server will display.
- In another section of this lab you created a basic phptest.php file and saw how the server executed the PHP code and turned it into an HTML page your browser could display. Because PHP offers an easy way to write web applications it powers much of the Internet. To prepare us for setting up some PHP applications in a future lab it will be helpful to know a little about how PHP scripts work. Read through the W3 Schools PHP Basics Tutorial (PHP Intro through PHP Superglobals) and try creating some PHP scripts on your own Linux server like the examples given in the tutorial pages to see if you can get them to run, try modifying them a little bit and see what the results are. There are many great Internet resources devoted to understanding how to do things with PHP so take some time to see how this language can be easily integrated in websites. You should definitely be familiar with editing PHP files to change variables, echo statements, etc. work which are all skills you'll need when installing PHP based website software.
- Try writing some simple PHP scripts on your own using variables and echo statements and make them available through your webserver. Edit your index.html file (or create a new index.php file which will be loaded instead if it exists) so there is a menu for you to find and run the various scripts you have created.