Jump to content

Subdomain Creation


Recommended Posts

Guest MrLeN

I have created a members area on a website where members can create a personal web page for themselves. The page winds up being at:

 

mywebsite.com/user

 

So far so good (all working nicely)..

 

However, I want that user to be able to acces the page with a subdomain, because it looks a lot nicer. ie:

 

user.mywebsite.com

 

What is the easiest way I can go about this?

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/
Share on other sites

Guest MrLeN

I've been searching Google for:

 

virtual subdomains

create subdomain mod rewrite

htaccess subdomains

wildcard subdomains

craete subdomain for user folder

subdomain tutorial

virtual subdomain tutorial

(and about 5 dozen other variations)..

 

..and I've looked several pages deep under each search, and all I can find is either answers that don't really answer (ie: "yeah, just use virtual subdomains"), or answers that are similar but not really what I want (or are the oppositie of what I want).

 

Apparently, if you want a server to display the contents of:

 

website.com/user

 

under:

 

user.website.com

 

You have to find the wizard of oz or something.

 

As far as I can see, no one on the Internet knows how to do it.

 

Or, there's some secret society that have employed tens of thousands of people to erase the knowledge from the internet, in case Darth Vader find out or something.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245010
Share on other sites

Well, do you think animal cruelty will bring ppl to give you answers? What if i had screenshot your post and send it to the Moderator? What a noob. To get to where you want, you must first make a mistake. Try everything on google and the answers will come to you eventually. Are u using local hosting or shared hosting? If local hosting you need to edit your host file and point it to your ip if its a shared hosting, use the control panel by user host and add the subdomain

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245014
Share on other sites

Well, I assume you are aware that you can create subdomains using cpanel, right? You would just need to direct the subdomain "user.mywebsite.com" to the folder where this points to "mywebsite.com/user".

 

However, I assume you want a more automated solution than having to manually create these subdomains yourself. Well, it is "possible", but maybe not realistic. It would be possible to build your own PHP code to automatically configure subdomains on the HOSTs DNS with the appropriate connections, open ports, security, etc. But, I highly doubt your host would allow that. I think you have two options.

 

1) Contact your host. They maintain the subdomains and have the most intimate knowlege of what it would take to do what youwant.

 

2) Build a cURL script that will access your cPanel and create the subdomains for you. But, this does pose some risks to you and your host, so tread lightly.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245019
Share on other sites

Guest MrLeN

Well, I assume you are aware that you can create subdomains using cpanel, right? You would just need to direct the subdomain "user.mywebsite.com" to the folder where this points to "mywebsite.com/user".

 

That's not an option.

 

However, I assume you want a more automated solution than having to manually create these subdomains yourself. Well, it is "possible", but maybe not realistic. It would be possible to build your own PHP code to automatically configure subdomains on the HOSTs DNS with the appropriate connections, open ports, security, etc. But, I highly doubt your host would allow that. I think you have two options.

 

Yeah, doesn't sound like something the host would be interested in hearing about.

 

1) Contact your host. They maintain the subdomains and have the most intimate knowlege of what it would take to do what youwant.

 

I can already foresee their answer: "That is beyond the scope of our support".

 

2) Build a cURL script that will access your cPanel and create the subdomains for you. But, this does pose some risks to you and your host, so tread lightly.

 

I already built such a script, successfully. It works and everything is fantastic.

 

Problem (which is why suggestion 1 was "not an option"). cPanel creates the subdomain folder as owned by the "cPanel username" (ie: the ftp username). The Server PHP configuration is set up so that it can only write into folders owned by "nobody". So, once I've created the subdomain and try to have the PHP script write some files into it, I get a permision denied error, because PHP doesn't have access to do it.

 

So, I contacted the host and asked them to change the handler of PHP from CGI to SuPHP (so that php can write to the files). The problem with that is that the server requires folders to be chmodded to 750, which caused about 50 other website son the server with folders set to 755 to have a coronary (ie: Intenal Server Error's). Look, I can type all day long (and even as mUch as "ZulfadlyAshBurn" likes to suggest I don't try), I've tried EVERYTHING..

 

..also, this is not my first attempt to find a solution to this problem. I've been through this several times before (OVER THE LAST 12 MONTHS), but I had to give up each time, because each time I felt the urge to destroy everything around me -- with my FACE.

 

Basically I've been down that road (of creating subdomains through cPanel). I've spent weeks trying to get it to work. I can't.  Permission problems became a nightmare. So, even though, IDEALLY, I want "actual" subdomains.. I can't manipulate any of the files under those subdomaisn via PHP, so --- wipe your arm across the table and push everything I've tried, built and worked on for weeks and months into the trashcan.

 

My last option was to simply write a script that creates a folder under public_html (ie: public_html/user). That way there are no permission problems. PHP can write to and delete those folders. Everything works fine. I can move files (from a master account, that contains a copy of all the base files) into the folders, and I can symlink other files and it's all fantastic.

 

However:

 

mysite.com/user SUCKS!

 

I want:

 

user.mysite.com

 

I've tried adding *.mysite.com as a subdomin in cPanel, and then trying to find a way to create some sort of mod rewrite or htaccess file to make user.mywebsite.com display the contents of mysite.com/user but I am unable to find a way to do it.

 

Basically, I have tried everything that my brain is capable of conceiving. I've even taught so hard I think I started to phase into the 4th dimension. But I can't find an answer.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245021
Share on other sites

1) Contact your host. They maintain the subdomains and have the most intimate knowlege of what it would take to do what youwant.

 

I can already foresee their answer: "That is beyond the scope of our support".

 

have you asked them??? if your thinking you can get an answer by being bossy, then you can dream about it.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245034
Share on other sites

Guest MrLeN

1) Contact your host. They maintain the subdomains and have the most intimate knowlege of what it would take to do what youwant.

 

I can already foresee their answer: "That is beyond the scope of our support".

 

have you asked them??? if your thinking you can get an answer by being bossy, then you can dream about it.

 

ZulfadlyAshBurn, I know you work for Darth Vader. Don't try and deny it.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245037
Share on other sites

1) Contact your host. They maintain the subdomains and have the most intimate knowlege of what it would take to do what youwant.

 

HAHA. Funny. Don't be lame luh. You can close this thread cause no one is gonna help you anymore :)

 

I can already foresee their answer: "That is beyond the scope of our support".

 

have you asked them??? if your thinking you can get an answer by being bossy, then you can dream about it.

 

ZulfadlyAshBurn, I know you work for Darth Vader. Don't try and deny it.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245039
Share on other sites

I've tried adding *.mysite.com as a subdomin in cPanel, and then trying to find a way to create some sort of mod rewrite or htaccess file to make user.mywebsite.com display the contents of mysite.com/user but I am unable to find a way to do it.

 

This is your solution. Create a wildcard subdomain. http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain What you have done using cPanel is probably enough. Make sure you add to your DNS records. All subdomain aliases will now resolve to your domain.

 

You must write some code that maps the subdomain to the user. This is kinda like what wordpress does on its multisite installation, maybe download the code and fathom it out.

 

For a kick of you will want to be using the following to determine what data to display:

 

<?php echo $_SERVER['HTTP_HOST']; ?>

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245041
Share on other sites

Guest MrLeN
Make sure you add to your DNS records. All subdomain aliases will now resolve to your domain.

 

I don't understand this.

 

You must write some code that maps the subdomain to the user.

 

I don't understand this.

 

For a kick of you will want to be using the following to determine what data to display:

 

<?php echo $_SERVER['HTTP_HOST']; ?>

 

I don't understand why you gave me the code to echo a domain name. What do you suggest I do with it?

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245047
Share on other sites

Make sure you add to your DNS records. All subdomain aliases will now resolve to your domain.

 

I don't understand this.

 

You must write some code that maps the subdomain to the user.

 

I don't understand this.

 

For a kick of you will want to be using the following to determine what data to display:

 

<?php echo $_SERVER['HTTP_HOST']; ?>

 

I don't understand why you gave me the code to echo a domain name. What do you suggest I do with it?

 

Seriously, if you are not a developer and do not understand why you would need to use the super-variable I gave you to do exactly what you ask for in your original post I would personally give up now.

However, I want that user to be able to acces the page with a subdomain, because it looks a lot nicer. ie:

 

Get a developer to do this for you if it is out of your scope.

 

I am not trying to be mean but if you do not know how DNS works & what a subdomain actually is then you don't have much hope. To me this is an easy project for a developer.

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245050
Share on other sites

Guest MrLeN

Make sure you add to your DNS records. All subdomain aliases will now resolve to your domain.

 

I don't understand this.

 

You must write some code that maps the subdomain to the user.

 

I don't understand this.

 

For a kick of you will want to be using the following to determine what data to display:

 

<?php echo $_SERVER['HTTP_HOST']; ?>

 

I don't understand why you gave me the code to echo a domain name. What do you suggest I do with it?

 

Seriously, if you are not a developer and do not understand why you would need to use the super-variable I gave you to do exactly what you ask for in your original post I would personally give up now.

However, I want that user to be able to acces the page with a subdomain, because it looks a lot nicer. ie:

 

Get a developer to do this for you if it is out of your scope.

 

I am not trying to be mean but if you do not know how DNS works & what a subdomain actually is then you don't have much hope. To me this is an easy project for a developer.

 

I read your response several times.

 

I backspaced my response to your response  several times.

 

Then I read your response several times, again.

 

I looked at the wall, without blinking for at least 2 minutes.

 

I have come to the conclusion that you work for Darth Vader too.

 

Is there anyone that knows how to do what I want to do?

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245053
Share on other sites

Guest MrLeN

re: http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain

 

I assume you have a general understanding of the Apache configuration file and especially of how to setup virtual hosts. So to get quickly to the point, here is what you have to add to your exisiting httpd.conf configuration file.

 

Can anyone tell me where I might find the httpd.conf file?

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245058
Share on other sites

OK, we won't get very far on this as you are expecting a simple one line answer when really there isn't one. It would take a developer to write some code that will understand what data to display for each subdomain that is part of your website. You are not going to get anyone to write this for you or get a cut-and-paste solution!

 

This topic is discussed in detail here http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php

 

If you are still struggling after reading then I would use a simple solution such as a rewrite rule.

http://oneapachetipaday.blogspot.com/2007/03/redirect-subdomain-to-subfolder.html

 

And if you are still struggling, seriously get someone else to do it!

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245059
Share on other sites

re: http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain

 

I assume you have a general understanding of the Apache configuration file and especially of how to setup virtual hosts. So to get quickly to the point, here is what you have to add to your exisiting httpd.conf configuration file.

 

Can anyone tell me where I might find the httpd.conf file?

 

Linux? /etc/httpd/

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245060
Share on other sites

Guest MrLeN

I found this in the httpd.conf

 

<VirtualHost 123.135.133.60:80>

    ServerName host.mywebsite.com

    DocumentRoot /usr/local/apache/htdocs

    ServerAdmin root@host.mywebsite.com

    <IfModule mod_suphp.c>

        suPHP_UserGroup nobody nobody

    </IfModule>

</VirtualHost>

 

So (as far as I can understand, seeing as I am stupid and all, and because this is beyond my scope and I should get a developer)..

 

..I changed it to:

 

<VirtualHost 123.135.133.60:80>

    ServerName host.mywebsite.com

    ServerAlias *.mywebsite.com

    DocumentRoot /usr/local/apache/htdocs

    ServerAdmin root@host.mywebsite.com

    <IfModule mod_suphp.c>

        suPHP_UserGroup nobody nobody

    </IfModule>

</VirtualHost>

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245064
Share on other sites

Now:

 

jack.mywebsite.com

 

Displays the content of:

 

mywebsite.com

 

Not:

 

mywebsite.com/jack

 

*but it was already doing that when I added *.mywebsite.com in subdomains via cPanel.

 

So now I see no change.

 

I had already said that you had probably got this far by adding the wildcard * in cPanel! Now you need code in your website to display the correct data based on the subdomain or you can use a simple mod-rewrite rule

 

http://oneapachetipaday.blogspot.com/2007/03/redirect-subdomain-to-subfolder.html

 

Or you can map subdomains to subfolders using the following:

 

http://blog.merhar.si/post/757871034/mapping-subdomains-to-subdirectories-with-apache

Link to comment
https://forums.phpfreaks.com/topic/242407-subdomain-creation/#findComment-1245074
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.