Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

The same way 'localhost' in the url points to /var/www/
I would like to put http://courses/somehting/somthing/moresomthings/.... and it would always point to /var/www/courses.php

This is to work on my local machine only. How should I approach this?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You have the right idea, but you'll need to put your "courses.php" in a folder, most likely. So your structure would be more like /var/www/courses/index.php (index.php is generally the default file a web server looks for, this allows you to do something like "http://courses" without dealing with rewrite engines).

You then need to set up an Apache virtual host to match up your new folder with a domain name. You can find this in /etc/httpd/sites-available or /etc/apache2/sites-available, depending on your setup. In your virtual host file, you'll have something like:

<VirtualHost>
  ServerName courses
  DocumentRoot /var/www/courses
</VirtualHost>

See Apache's documentation for more stuff you can do. You'll need to edit this file with elevated privileges, so in a terminal, you'll have to run gksu gedit /path/to/virtual/hosts/file.

Once you add that, make sure your virtual hosts file is symlinked to sites-enabled (if not, run sudo ln -s [/etc/httpd/sites-available/realfile] [/etc/httpd/sites-enabled/nameofrealfile] replace the stuff in brackets with the appropriate paths and file name (the symlink name is conventionally the name of the real file). Then, restart Apache, so that it picks up the new virtual host information.

If you're running PHP files, then you'll need to make sure you have PHP5 installed (sudo apt-get install php5) and make sure the Apache module is activated sudo a2enmod php5.

Finally, you need to associate you local web server with the domain name you've chosen earlier. For that, you'll need to edit your HOSTS file, which is located in /etc/hosts. Like your vitual host file, the HOSTS file requires elevated privileges, so open it with gksu gedit /etc/hosts. Then, below the other entries in it, add a line with 127.0.0.1 yourdomain (where "yourdomain" is the domain name you've chosen), then save and close the file.

Once that's done, you should be able to see the contents of your /var/www/courses folder. Ideally, you'll have an index file, and it will pick it up. If you have an index.php file, and it's not reading it, you may have to tell Apache to look for .php extensions for index files.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.