Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks.

Similar presentations


Presentation on theme: "Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks."— Presentation transcript:

1 Lab 8 Overview Apache Web Server

2 SCRIPTS Linux Tricks

3 Scripts Small programs to help the maintaining and configuring of an operating system Executed by the shell  Syntax dependent on shell Typical use:  Create a bunch of new users  Configure a service De facto extension: .sh

4 Change terminal color #!/bin/bash # script to turn the screen blue setterm -background blue echo It is a blue day Line 1: specifies which shell should be used to interpret the commands in the script. Line 2: is a comment (has no effect when the script is executed). Line 3: sets the background colour. Line 4: displays a message. Assuming the file is executable: To execute if the PWD has this file: Assume a file named changecolor:./changecolor If in another directory use the fully qualified name: /home/mydir/utils/changecolor

5 Simple Menu Script #!/bin/bash OPTIONS="Hello Quit" select opt in $OPTIONS; do if [ "$opt" = "Quit" ]; then echo done exit elif [ "$opt" = "Hello" ]; then echo Hello World else clear echo bad option fi done These can be as complex as needed with conditional and loop controls (among many other things)

6 Running Scripts Basics Make sure the first line is a directive of which shell to use (if needed)  Starts with a shebang: #!  For Debian it is the bash shell /bin/bash Make sure it is executable  rwxr-xr–- User can run, edit and view Group can run and view World can view  chmod 754 script.sh If the shell is in a directory defined in the PATH  echo $PATH Will show the directories  type: filename If it is not in PATH but it is in the PWD  type:./filename If not in PATH and not in the PWD  type full filename starting with the root: /home/ajkombol/Desktop/script.sh

7 Script one: netconfig.sh #!/bin/bash NETCONFIGFILE=/etc/network/interfaces RESOLVECONF=/etc/resolv.conf ifdown $1 vi $NETCONFIGFILE #vi $RESOLVECONF ifup $1 echo 'nameserver 172.16.1.254' >> $RESOLVECONF echo 'nameserver 172.16.1.250' >> $RESOLVECONF myprompt#./netconfig.sh eth0 Desired action: stop the NIC open the interfaces file to edit restart the NIC add two nameservers to the resolve.conf file The script: To execute the script:

8 Quick script intro Parameters passed to a script are denoted by $1, $2, $3, …  $1 is the first parameter, $2 is the second, etc.  $# is the number of parameters passed Variables are case sensitive  Environment variables Used by the system in general Are UPPER case by convention

9 Quick script intro (cont.) Conditionals are done by an if…elif…else…fi structure  if and elif are followed by a command that evaluates to true or false  elif and else are optional elif can be repeated Only one else may be used, if needed  if is closed with the fi statement  To stop in the middle of a script use exit n n = 0 is a normal exit If n is not specified it is assumed 0 n = 1 is an error exit Actually any non 0 value is an error  If a value needs to be checked the test command is used Numbers use conditionals e.g. –gt, -lt, and –eq  greater than, less than, equal EX: test 1 –gt 2 Strings use operators e.g. = or !=  equal and not equal EX: test $1 = "opt1"  There are other comparisons that can be done, check the internet

10 Script two: go #!/bin/bash IFILE=/etc/network/interfaces ifdown eth0 if test $1 = "static" ; then cp $IFILE.static $IFILE echo "Static interfaces loaded!" elif test $1 = "dhcp" ; then cp $IFILE.dhcp $IFILE echo "DHCP interfaces loaded!" else echo "Parameter must be static or dhcp" fi ifup eth0 Desired action: stop the NIC, check which option copy the proper template to interfaces, restart the NIC Note: eth0 is assumed to be the NIC name To execute the script: myprompt#./go static … myprompt#./go dhcp

11 Today's labs scripts summary Changing network configuration  Script one – editing the interfaces file stop NIC edit interfaces add some additional routing information start NIC  Script two – alternating interfaces templates Make two interfaces templates stop NIC Copy the desired template start NIC You may wish to keep these scripts  Use netconfig.sh to edit the interfaces file After making appropriate changes  Use go or go2 to switch between DHCP addresses Static addresses

12 Reminder ALWAYS make a backup copy of a configuration file BEFORE editing it  Will allow the file to be restored If you mess it up If something else messes it up  Examples: cp interfaces interfaces.backup cp apache2.conf apache2.conf.orig Make a copy of a line to be changed in a file and comment it out before changing the original  Example: # This is the original line This is the changed line

13 APACHE Main Lab

14 Apache Web Server Main Goals  Install Apache  Configure basic system  Configure restrictions Side goals  Installing packages on a Debian System  Reinforce VM environment  Reinforce use of vi editor

15 Apache Web Server Overview Install Apache on your Debian VM  apt-get Backup: Synaptic Package Manager No credit for Synaptic install Check if installation worked Create new directories  “Install” the web application Configure Apache to “find” the new “application” Copy Web page files into proper directories  Hint: assume the Web application is being moved from a different Web server to this machine Configure Apache for restrictions  Allow directory access  Deny directory access Browse the application from another machine

16 Misc. Notes Debian required for the Apache Server CentOS recommended for the browsing client  Can be any OS with a browser Use ifconfig to identify your IP address Web files (.htm and pics) available on hades.lab  Use browser to locate /apachelab e.g. lab302-web.hades.lab/classes/apachelab  (172.16.1.250)  In /public directory  Also available ON website on thumbdrive You will need to figure out on your own where the images go to be properly displayed  All web pages except home have an image  A subdirectory is involved!

17 IMPORTANT!!!! This Debian VM must be working and saved! Will be used as the basis for the DNS Lab!

18 Apache Overview “Open source” web server Default browser “root” directory  NOT the same as the host’s root directory!  Location: /var/www /var/www/htdocs  Depends on distribution To access the web server:  Use the IP address or host name  Port 80 Bonus:  At end of lab add port to browse on port 8080 Document results

19 Last minute notes: Check the links to  test1.html  test2.html  They should go to the ITIS2110 directory Watch the IP addresses of your VM  DHCP OK this lab Need to look up address for browsing  If address was assigned Be sure does not conflict with another machine Can use machine ID as subnet or host id Can use your subnet (see listing on post)

20 Apache Lab Lab 20 pts


Download ppt "Lab 8 Overview Apache Web Server. SCRIPTS Linux Tricks."

Similar presentations


Ads by Google