320 likes | 421 Vues
Learn essential Unix commands for navigating directories, changing ownership, modifying access rules, copying, moving, removing files, and downloading from web resources. Understand Apache Webserver configuration and modules. Explore using .htaccess files and mod_rewrite for URL rewriting.
E N D
Getting Around • pwd • Print Working Directory • Tells you where you are on the remote computer
Getting Around • LS • Lists directory contents L flag for ‘long list’
Getting Around owner size date name directory everyone owner group W = writable R = readable X = executable
Getting Around • cd Go to the root of the server From there, go to the folder called ‘afs’ Now you’re in /afs
Operations • Chown • Changes ownership of a file or folder chown [user] [file] chown gillw3 /var/logs chown –R gillw3 /var/logs Changes ownership of the folder ‘logs’ Changes ownership of the folder ‘logs’ and everything in it
Operations • chmod • Modifies access rules for a file chmod [usertype] = [rights] [file] [usertype] can be one of u, g, or o (current owner, anyone in the owners group, anyone) [rights] can be r, w or x (read, write, execute)
Operations • chmod chmod u=rwx somefile.txt
Operations • cp • Copies a file cp [source] [destination] cp somefile.txt somefile_copy.txt
Operations • mv • Moves a file mv [source] [destination] mv somefile.txt newname.txt (renames) mv somefile.txt /var/www/somefile.txt (moves)
Operations • rm • Removes a file rm [file] rm somefile.txt
Operations • wget • Gets a file (or more) from a web resource wget [url] wget http://www.rpi.edu/index.html (gets file, saves it to current directory as index.html) wget –O rpihome.html http://www.rpi.edu/index.html (gets file, saves it to current directory as rpihome.html)
.sh files • Put shell commands in a file • Call the file, all the commands run The following should be the top line of the file: #!/bin/sh
Operations • cron • allows users to set timers for operations to be exicuted • crontab • A file that specifies what should be done when
Operations • Crontab • Crontab –e (edits file) [min] [hour] [day of month] [month] [day of week] [command] [0-59, *] [0-23, *] [1-31, *] [1-12, *] [0-6, *] [command] 0,5,10,15,20,25,30,35,40,45,50,55 * * * * update-rss-feeds.sh 0 3 * * * managelogs.sh
Apache Webserver = httpd • Hypertext transfer protocol daemon • Daemons are applications that run all the time listening for a request. When a request is made they do something. • Developed in 1995 • Serves 50% of websites
HTTPD is Modular • mod_php is added to allow php to be processed…. • Modules may be added when the application is complied • Modules may be dynamically added after the application is complied • apxs is a tool for managing dynamic modules • http://httpd.apache.org/docs/2.2/programs/apxs.html
Modules • mod_auth_cas • http://www.ja-sig.org/wiki/display/CASC/mod_auth_cas • mod_auth_ldap • http://httpd.apache.org/docs/2.0/mod/mod_auth_ldap.html • mod_proxy_fcgi • http://mproxyfcgi.sourceforge.net/
Configuring in httpd.conf • Httpd.conf is read when httpd starts • Restart httpd every time you edit httpd.conf • At all times, refer to the apache documenation • http://httpd.apache.org/docs/2.2/
httpd.conf • <directory> • Rules for a folder on the server • <location> • Rules for a url • <virtualhost> • Directive that creates additional hosts on your httpd instance. • <IfModule> • Tests of a module is loaded before you attempt to configure the module
<directory> Allows server side includes in the specified folder Instructs httpd to follow shortcuts in the filesystem, to ignore .htaccess files, do not serve any content
<location> Requires AFS login to any URL that has an /AFS in the path
<virtualhost> Creates a virtual host, alert.rpi.edu
<IfModule> Only runs the re-write rules if mod_rewrite is loaded
.htaccess • Contains instructions, like those found in httpd.conf • File is parsed every time the server requests a resource in that folder, or a downstream folder
In Class Work • Using mod_rewrite to • Proxy • Make neato urls • Create a httpd servable directory named ‘rewrite’
In Class Work Allowing .htaccess files in httpd.conf • Add the following to httpd.conf <Directory /path/to/www/rewrite> AllowOverride All </Directory> • Restart httpd
In Class Work • Create a file named .htaccess in ‘rewrite’ • Add: <IfModule mod_rewrite.c> RewriteEngine on RewriteBase /rewrite/ RewriteRule ^(.*)$ http://www.cnn.com/ [P] </IfModule>
In Class Work • Go to http://localhost/rewrite • Rename .htaccess to example1.txt • Create another file named .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteRule /(.*) index.php?input=$1 </IfModule>
In Class Work • Create index.php • echo $_GET[‘input’]; • Use ‘explode’ on $_GET[‘input’] to break the input into value key pairs