Jump to content
xisto Community
iGuest

Apache, Subdomains, Indexes And Mail

Recommended Posts

Hi, on my other computer (not connected to the internet) I have an Apache server, just to test out PHP pages and stuff, I'd like to know how to do some stuff in it, like:
Have subdomains, e.g. abc.localhost, do you modify something in the httpd.conf file? How do you edit DNS records?
Indexes, set it up so that LOCALHOST will take you to LOCALHOST/index.php. At the moment, it's set up so that it'll take you to localhost/index.html, but if there's no index.html file, it'll take you to a list of files.
Mail, e.g. abc@localhost, how do you set up mail? You probably need some other kind of server, I don't know, but I really need this for testing contact forms, and other things with the mail() function.

Thanks, I have looked in the Apache documentation, but it's a bit complicated, and it's hard to find the thing you're looking for.

Share this post


Link to post
Share on other sites

As you know, apache wont work all that brilliantly on my computer.I just get a command prompt with like 100 errors.

Share this post


Link to post
Share on other sites

Hey Habble,

I think I have a solution for at least one of your problems!

I just wanted to say first that yes, Apache is a powerful application, and naturally that makes it somewhat complicates, and gives it a bit of a learning curve. You will see that once you start "getting the hang" of it, the documentation will seem so much simpler to you, so don't give up! Running your own web-server is a great experience that helps with web-page programming and creation.

 

So, now for some direct answers! If you want to change the list of index files, that Apache will open when a directory is requested, you just need to find the "DirectoryIndex" directive in the "http.conf" file. Mine looks like this:

DirectoryIndex index.html index.html.var index.php main.php
As you can probably see, you only need to add another filename to the space-delimited list!

 

Now for subdomains. The way Apache (and the HTTP protocol) works is that a server may have only 1 IP, but when a web browser requests the subdomain of the server, while still going to the same server, it passes a "Host: subdomain.example.com" in the HTTP request, and thus the server knows it needs to server the subdomain. So basically you can (if you're using Windows) go to "c:\windows\system32\drivers\etc\" (you may have a different Windows directory from me), and edit the Hosts file. For each subdomain you want, add a line to the file that looks something like this:

127.0.0.1	   subdomain.localhost
Now each time you visit "subdomain.localhost" in your browser, you will be redirected to 127.0.0.1 by Windows. That IP is an IP that tells the computer to access itself. Because the Apache server is running on your computer, 127.0.0.1 will redirect you to your web-site. When you visit the subdomain, Apache will get the information from the browser that tells it that we're looking at a subdomain. To configure Apache to recognize and respond correctly to multiple subdomain, you need to you "virtual hosts." I've never done this before, so I can't help you from my memory, but two articles that might really help you are this one and this one.

I hope you manage to get it working, and if not, just write back!

 

As for configuring an email? This one requires a totally different server than Apache. You can find some very nice result by googling "email server" or "smtp server." I'll try to look for some things that might be of help to you, but I've never run an email server, so I might not be of much help. Sorry! <_<

 

I hope I've managed to assist you in some way!

Share this post


Link to post
Share on other sites

The easiest way to get Apache, mail, FTP, MySQL, PHP etc running on your machine is to use something like XAMMP - it runs on windows, linux, osx and solaris.
I use it myself and must say it is so easy to configure, just follow the onscreen prompts and you are all set.
Here is what the basic package contains - Apache HTTPD 2.2.4, MySQL 5.0.41, PHP 5.2.2, PHPMyAdmin 2.10.1, Mercury Mail Transport System v4.01a, FileZilla FTP Server 0.9.23 and also has the zend optimiser installed.Also I think its got SSL as well but I have never used it.
One other great thing about Xammp is the way you can install it all "ON" or "OFF" what I mean by that is that you dont have to install it and activate the services at startup of the mahine.There is a Xammp control panel application that you start then click on the servers you want to start, for instance I tend to only start Apache and MySql and turn off Mail and FTP.
I do this so that I dont have all these services running all day long on my pc and also giving a hacker more open ports to have a look at <_<
All in all Xammp is a perfect way to test out any site locally before hosting it here, I do this and it takes much less bandwidth off my astahsot account, I get a site 100% working an no bugs before transferring it to Gamma.

Share this post


Link to post
Share on other sites

Thanks seec77 and Mark420, I'll try out those things later today when I go onto my other computer, and I'll have a look at XAMPP.I've seen Virtual Hosts in the Apache Docs before, but I didn't really understand what they were. I'll have a look round for some Mail programs. Thanks!

Share this post


Link to post
Share on other sites

Hey Habble,

I think I have a solution for at least one of your problems!

I just wanted to say first that yes, Apache is a powerful application, and naturally that makes it somewhat complicates, and gives it a bit of a learning curve. You will see that once you start "getting the hang" of it, the documentation will seem so much simpler to you, so don't give up! Running your own web-server is a great experience that helps with web-page programming and creation.

 

So, now for some direct answers! If you want to change the list of index files, that Apache will open when a directory is requested, you just need to find the "DirectoryIndex" directive in the "http.conf" file. Mine looks like this:

DirectoryIndex index.html index.html.var index.php main.php
As you can probably see, you only need to add another filename to the space-delimited list!

 

Now for subdomains. The way Apache (and the HTTP protocol) works is that a server may have only 1 IP, but when a web browser requests the subdomain of the server, while still going to the same server, it passes a "Host: subdomain.example.com" in the HTTP request, and thus the server knows it needs to server the subdomain. So basically you can (if you're using Windows) go to "c:\windows\system32\drivers\etc\" (you may have a different Windows directory from me), and edit the Hosts file. For each subdomain you want, add a line to the file that looks something like this:

127.0.0.1	   subdomain.localhost
Now each time you visit "subdomain.localhost" in your browser, you will be redirected to 127.0.0.1 by Windows. That IP is an IP that tells the computer to access itself. Because the Apache server is running on your computer, 127.0.0.1 will redirect you to your web-site. When you visit the subdomain, Apache will get the information from the browser that tells it that we're looking at a subdomain. To configure Apache to recognize and respond correctly to multiple subdomain, you need to you "virtual hosts." I've never done this before, so I can't help you from my memory, but two articles that might really help you are this one and this one.

I hope you manage to get it working, and if not, just write back!

 

As for configuring an email? This one requires a totally different server than Apache. You can find some very nice result by googling "email server" or "smtp server." I'll try to look for some things that might be of help to you, but I've never run an email server, so I might not be of much help. Sorry! <_<

 

I hope I've managed to assist you in some way!

I tried what you said, and I changed the hosts file, and then I added a VirtualHost. The hosts I added were test.localhost and http://forums.xisto.com/no_longer_exists/

This worked fine, and when I went to these addresses, it took me to localhost. But when I tried using virtualhosts, it wouldn't work. It completely ignored them. I did restart apache once I changed them, but they still took me to the localhost index. Do you know what the problem is?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.