Jump to content

Subdomain Creation


Guest MrLeN

Recommended Posts

A simple mod_rewrite rule in your .htaccess file should do what your after.

 

Something like:

 

RewriteCond %{HTTP_HOST} !domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) %2/$1 [L]

Link to comment
Share on other sites

Guest MrLeN

Well at the moment, I am trying to work out why my website is displaying a page that says:

 

Great Success !

Apache is working on your cPanel® and WHM™ Server

 

That will probably take me 3 days (to 3 weeks) to fix!

 

:(

Link to comment
Share on other sites

Guest MrLeN

ok, it was my browser cache. I cleared it. the site is working again now.

 

But this code:

 

RewriteCond %{HTTP_HOST} !domain.com$ [NC]

RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain.com [NC]

RewriteRule (.*) %2/$1 [L]

 

When I go to:

 

jack.mysite.com

 

..it just goes to:

 

www.mysite.com

 

 

 

 

Link to comment
Share on other sites

Guest MrLeN

I finally found one that works:

 

http://forums.hostgator.com/subdomain-subdomain-subdirectory-redirect-htaccess-t25446.html

 

RewriteEngine On

# Extract the subdomain part of domain.com

RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]

# Check that the subdomain part is not www and ftp and mail

RewriteCond %1 !^(www|ftp|mail)$ [NC]

# Redirect all requests to a php script passing as argument the subdomain

RewriteRule ^.*$ http://www.domain.com/show-user.php?user=%1 [R,L]

 

But I had to remove: show-user.php?user=

 

But the problem is, it's a redirect.

 

I didn't really want it to redirect.

 

I just want it to display the contents.

Link to comment
Share on other sites

Guest MrLeN

Ok, this is going to cost me money.

 

I have absolutely no alternative but to lease another server, ask the admin to change the php5 handler to SuPHP and not run any other website on the server, other than the script I am trying to build now, set all the public_html files to 750.

 

I already have a script where I can create subdomains through cpanel with php.

 

Scr*w this. I'm over it!

 

Off to order another VPS...

 

THE THINGS A BLOKE HAS TO DO!

 

Ok, thanks for your help everyone.

 

I do appreciate it (even though, with the mood I am in, it might not look like it).

Link to comment
Share on other sites

Guest MrLeN

Take out the R(edirect) flag and make the path absolute:

RewriteRule ^.*$ /absolute/path/to/show-user.php?user=%1 [L]

 

I changed it to that, but it has created a redirect loop.

Link to comment
Share on other sites

You understand what I mean by absolute path, right? Something like /var/www/domain.com/show-user.php?user=%1. If you set it to /show-user.php?user=%1, it will redirect to the php file from the same subdomain, causing a loop.

Link to comment
Share on other sites

But never mind, I have already ordered a new environment to work on this script, and also a new domain.

 

When in doubt, I'm sure a new server will solve all your problems.

 

I think you'd be better off if you learned a little bit about what people have been suggesting to you and why it's feasible.  What it boils down to is a provision in the HTTP1.1 protocol that requires the the HTTP header of a request to include the hostname. 

 

14.23 Host

 

The Host request-header field specifies the Internet host and port number of the resource being requested, as obtained from the original URI given by the user or referring resource (generally an HTTP URL,

 

as described in section 3.2.2). The Host field value MUST represent the naming authority of the origin server or gateway given by the original URL. This allows the origin server or gateway to differentiate between internally-ambiguous URLs, such as the root "/" URL of a server for multiple host names on a single IP address.

 

      Host = "Host" ":" host [ ":" port ] ; Section 3.2.2

 

A "host" without any trailing port information implies the default port for the service requested (e.g., "80" for an HTTP URL). For example, a request on the origin server for would properly include:

 

      GET /pub/WWW/ HTTP/1.1

      Host: www.w3.org

 

A client MUST include a Host header field in all HTTP/1.1 request messages . If the requested URI does not include an Internet host name for the service being requested, then the Host header field MUST be given with an empty value. An HTTP/1.1 proxy MUST ensure that any request message it forwards does contain an appropriate Host header field that identifies the service being requested by the proxy. All Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request) status code to any HTTP/1.1 request message which lacks a Host header field.

 

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

 

Apache vhosts depend on this, and the solutions that were suggested depend on it.  This very same variable is made available to PHP scripts via the $_SERVER variable you were provided. 

 

The immediate problem you had was easily understood, as by default, apache willl serve up its default, when it isn't able to identify a vhost.  With that said, configuring and developing a solution like this on a production server with other sites, is a bad idea if you aren't ready to experience downtime.  People don't develop new code on their production servers for the same reason, but then that's common sense.

 

 

Link to comment
Share on other sites

Guest MrLeN

When in doubt, I'm sure a new server will solve all your problems.

 

But I am not in doubt. I know that a server with SuPHP will solve all my problems. I had already written a script that creates real subdomains through cPanel, but once those subdomains were created, PHP didn't have the permisions to do anything with them (making them unusable); not even to write a file into the public_html folder! So, I have ordered an environment where PHP has such permissions, which renders this whole subdomain problem (which was plan B, anyway), unnecessary to bother with.

Link to comment
Share on other sites

I was agreeing with you that you needed another server.

 

I'm not sure what you mean by "real" subdomain.  All a subdomain is, is a name/IP association in DNS.  CPanel is simply a set of scripts that do things in a particular way.  What it does in terms of making a new website user, is that it creates a user/group, makes a directory under the primary CPanel user home, updates the local DNS server zone file (which won't work for example, if you aren't running DNS on your VPS, which happens to be a bad idea, but that's a whole other topic I'm not going to get into)  and adds a vhost file for apache.  Solving your permissions issues certainly does not require suPHP, although it was never quite clear what exactly the problem was.

 

But I am not in doubt. I know that a server with SuPHP will solve all my problems.

 

With all due respect, your confidence in your own understanding of what is going to make everything work seems overstated, based on the evidence in this thread.  You didn't seem entirely clear on how DNS works and perhaps still don't, you didn't understand vhosts, rewrite rules or standard webserver CGI variables.  It seems like you read a few things, and start running off in a direction without really understanding what you're talking about.  It's like you alternate between coming off as a know-it-all one minute and a complete noob the next. 

 

The CPanel user and scripts make the user/group and directories.  If you have a permissions problem inherent in that, suPHP isn't going to do squat.  suPHP plain and simple is a mechanism for running php scripts as a particular user.  I can make a file or directory as a super user inside your directory and there is nothing you can do about it, if I deny you permissions to that file or directory. 

 

Because suPHP is something used by shared hosts, I assume that is that's how you seized onto it, but it is not a magical subdomain-website-making panacea.  It is not by any means the only solution to that concern either --- fastcgi with suexec has been around much longer, and is used by most ISP's who offer shared hosting.  In fact, suphp has some things about it that hamper its performance, and make it impossible to use certain types of php acceleration addons. 

 

Well in summary, since you are again off and running in a particular direction, I hope at least some of the things that were brought up in this thread will help you learn a bit more about the underlying technology related to what you're trying to accomplish.  I guess when it comes right down to it, the way you handled yourself in this thread was at times very rude and dismissive and I take umbrage to that on behalf of the people who donate their time and expertise.  I gave you the benefit of the doubt, because I believe you were attempting to be funny, but you certainly rubbed some really experienced people the wrong way, and that tends to limit future response.  For example, complaining about how upset you are, when people who get paid good money for doing professional system admninistration and web development spent significant time giving you great advice and explanations, really comes off as bratty.

 

Either way, good luck with your project.

Link to comment
Share on other sites

Guest MrLeN

I'm not sure what you mean by "real" subdomain.  All a subdomain is, is a name/IP association in DNS. 

 

Well, all the rewrite stuff I was doing with htaccess was just redirecting people from user.mysite.com to mysite.com/user. So I don't class that as a real subdomain.

 

CPanel is simply a set of scripts that do things in a particular way.  What it does in terms of making a new website user, is that it creates a user/group, makes a directory under the primary CPanel user home, updates the local DNS server zone file (which won't work for example, if you aren't running DNS on your VPS, which happens to be a bad idea, but that's a whole other topic I'm not going to get into)  and adds a vhost file for apache.  Solving your permissions issues certainly does not require suPHP, although it was never quite clear what exactly the problem was.

 

I have already created a script that creates subdomains. However, when cPanel creates the public_html/user folder it is owned by the ftp username. So, if I try to run a script, to create folders unto public_html/user, I get permission denied errors, because PHP is running as CGI and not SuPHP. It doesn't have the permission. I have since leased a WHM/cpanel reseller account and specified that I need it on a server that already has SuPHP. Now, my script is fine and everything is running just the way I wanted. I am creating subdomains, then creating installer scripts into those subdomains, and then I am creating a free web page service, all automatically. Everything is just about complete and I am not far from finally being able to launch the site.  I just have to complete the email validation functionality. But that part is easy. I wont have a problem with that.

 

With all due respect, your confidence in your own understanding of what is going to make everything work seems overstated,

 

I know exactly what I wanted to do, and I am very confident about what it is I wanted to do and how i want to go about doing it. Creating mod rewrites was not something I wanted to do, but I entertained the idea for long enough to come to the realization that I was positive it wasn't what I wanted to do. Once it's not something I need, I have absolutely no will to learn anything more about it. I've already got enough on my plate with all the stuff I do need to learn.

 

based on the evidence in this thread.  You didn't seem entirely clear on how DNS works and perhaps still don't, you didn't understand vhosts, rewrite rules or standard webserver CGI variables.

 

True. I don't understand those things properly. But I understood enough to know that it's not where I wanted to head with what I am doing.

 

It seems like you read a few things, and start running off in a direction without really understanding what you're talking about.  It's like you alternate between coming off as a know-it-all one minute and a complete noob the next. 

 

I read a few things, tried a few things, bashed my head into the table ten times, and went and leased a server that will do what I needed in the first place. My solution wound up costing me $46 for a .cc domain and now I have a $25 a month commitment to pay for the reseller plan I ordered. But that's still cheaper than a new table (or brain surgery).

 

The CPanel user and scripts make the user/group and directories.  If you have a permissions problem inherent in that, suPHP isn't going to do squat.

 

I need SuPHP or my script wont run. I've proven that by leasing an environment that has SuPHP, and now everything works fine.

 

  suPHP plain and simple is a mechanism for running php scripts as a particular user.  I can make a file or directory as a super user inside your directory and there is nothing you can do about it, if I deny you permissions to that file or directory. 

 

I know what SuPHP does. That is why I went and leased an environment that has it enabled.

 

Because suPHP is something used by shared hosts, I assume that is that's how you seized onto it, but it is not a magical subdomain-website-making panacea.

 

Now that I have suPHP I don't have a subdomain problem. I simply use the subdomains created by cPanel (which I ask cPanel to make, using a script that took me weeks to make). However, now I can have PHP write to those files. without SuPHP, that's not posible.

 

It is not by any means the only solution to that concern either --- fastcgi with suexec has been around much longer, and is used by most ISP's who offer shared hosting.  In fact, suphp has some things about it that hamper its performance, and make it impossible to use certain types of php acceleration addons. 

 

Yeah, the host told me I can no longer use htaccess. That kinda sucks. But i can still use php.ini - Keep in mind that the service I am creating is a flat file/form based free web page service, where people can create websites with forms. I don't need a whole lot of functionality on the server.

 

Well in summary, since you are again off and running in a particular direction, I hope at least some of the things that were brought up in this thread will help you learn a bit more about the underlying technology related to what you're trying to accomplish.

 

Yeah, I learned that I need SuPHP, and that trying to create dynamic subdomains (and associated accounts) for a free web hosting service is a nightmare -- and that it's much better to have cPanel create subdomains.

 

I guess when it comes right down to it, the way you handled yourself in this thread was at times very rude and dismissive

 

I started off joking and posting in a light manner. Then I was called stupid and bossy. I continued posting in a light manner (ie: insisting that people work for Darth Vader, which was obviously a joke), in an attempt to demonstrate that there's no need to call me names, or suggest that I find someone else to work on my script (which insists I am stupid). I came here to ask for help, not to be told I am stupid, or to receive suggestions that I should get someone else to do it, because I can't handle it. If you want to get upset with someone, get upset with people who call others derogatory names, or badger them with veiled insults.

 

and I take umbrage to that on behalf of the people who donate their time and expertise.  I gave you the benefit of the doubt, because I believe you were attempting to be funny, but you certainly rubbed some really experienced people the wrong way, and that tends to limit future response.

 

The problem is, that sometimes people spend more time trying to tell people what they "really" want, instead of listening to the actual problem. I am sure that the advice in this thread is very useful to someone (who needs to learn about DNS). But it turned out not to be useful to me. I did give it my best shot though, and entertained the idea more than long enough.

 

For example, complaining about how upset you are, when people who get paid good money for doing professional system admninistration and web development spent significant time giving you great advice and explanations, really comes off as bratty.

 

I was quite obviously joking. If you can't see that, what more can I say?

 

Either way, good luck with your project.

 

Thanks, it's almost up and running (thanks to SuPHP).

 

If you really want to analyze why some people in this thread became antagonistic (and why my responses started to lose appreciation). I can tell you why: When people ignore humor and start insulting others. It turns a thread sour, and then it can easily turn into a problem. That's human nature. I handled myself about as well as the tone of this thread deserved. I didn't call anyone any names. I kept being humorous, even though people were being insulting. What more do you want from me?

 

See, there are some people in this thread who wanted their suggestions to work. However, when it became apparent that I was going to do things a different way, people took exception to it (including you). However, keep in mind that this whole thread was my "Plan B" (from the beginning). It turned out too complicated, so I just went back to my plan A (but on a different server). I apologize, humbly, to everyone who didn't see their suggestion(s) realized. I meant no offence, and I have not redirected the development of my web project to insult you. You have my word.

 

I appreciate everyone's help, who tried to provide a solution (and didn't become insulting or antagonistic). As for those who did, I take nothing back. Next time, don't be so mean.

Link to comment
Share on other sites

I think you still don't quite get what I am trying to tell you here.  You are just plain wrong about any number of things.  Your scheme works BECAUSE of vhosts and HTTP1.1 Host headers.  It does not work because of su_php.  You have some scripts that could have utilized a technique to get around the permissions issues you were having and never brought su_php into it.  Also, su_php isn't as good of a solution as fastcgi with suexec.  Keep in mind that you never provided even 1 snippet of code or script for anyone to look at. They were simply trying to guess based on limited information what you have, and it's exactly because we have a lot of gurus in this forum that you got any response at all. 

 

Here's the thing: you set yourself on a path and got things done in a certain way via your directions for people you paid.  You did not pay the people in this thread, so they gave you unfiltered advice.  They tried to work with and around the information you provided.  Oftentimes there are multiple ways to skin a cat, but they do tend to have tradeoffs and strengths and weaknesses.  Your approach has some strengths and some weaknesses.  It could be made to work either way.  What bothers me is not that you wanted to do things the way you felt most comfortable -- that is entirely understandable.  What isn't acceptable at all, is your preconceived notion that the people who replied to you have some agenda that involves sending you off on a wild goose chase.  One guy got frustrated and called you stupid.  Another guy, who happens to be an expert sysadmin simply questioned whether or not you were out of your element, when you claimed not to understand what was fairly basic advice.

 

I can tell you, as someone who worked for a company that had 700+ servers in 40+ data centers around the world, and automated provisioning of services with various DNS related tricks, that you did not receive one oddball or crazy suggestion in this thread.  I'm a little disappointed I haven't been able to get through to you that you were very much responsible for the way things went in this thread, but that sort of feedback is not the easiest to receive.  I do think you have to really consider your attitude and openness to hearing advice that doesn't match your preconceived notions, because you even have gone so far as to include me in this, which just goes to show how far off track you are.  I gave you no advice -- just tried to educate you a bit about the fundamentals involved with how Apache supports multiple websites, and even as of the last reply, you are confidently reiterating that su_php was all you ever needed.  I was trying to point you in the right direction so that you might better understand what you are ALREADY DOING by using cpanel to automate the creation of users/directories AND a vhost.  There is a directive in the httpd.conf file that tells apache to load the seperate vhost files cpanel creates fwiw. 

 

One last note:  in order for this to work, apache has to be restarted anytime you add a new subdomain/user, so that process will result in small blips in service (weakness column).  Also, if there is ANYTHING wrong with that script that creates an invalid vhost file for any reason, all the websites will be down until that is debugged and corrected (weakness).  The more you know about the infrastructure you're creating, the better for you as the owner, afaik.  Cheers ;)

 

 

Link to comment
Share on other sites

Guest MrLeN

Ok, I will take all that on board.

 

Forgive me, I'm sick.

 

I probably need medication.

 

Now, I am off to complete my (now functional) web service.

 

Anyone interested to see it? :)

Link to comment
Share on other sites

Guest MrLeN

Ok I will. I am actually very excited to see what people think of it :)

 

I want to make sure it's all working properly first.

 

I am still working on the registration and validation system.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.