Seamlessly direct multiple domains to a single set of PHP files? - php

I need to direct multiple domains to a single set of (PHP) files. So I point a domain at my server, which then goes to a single index.php file. This index.php file then detects the domain accessing it and returns the appropriate content. I do not want to add domains or set-up sites manually though as this is for a content management service. So it should be a case of a user signing up and it immediately works without me having to manually do anything. The file set must also exist only once, so updates can easily be applied to everyone.
I am currently on shared hosting, but I believe I may need to move to a VPS (running Apache) to achieve this.
How do I go about doing this?
Thanks

Unless I'm missing something about what you're trying to do, a simple CNAME DNS record may work. Just CNAME the new domain to your existing 'main' domain.
However, if you need to know what domain was requested using shared hosting this very well may not work. The catch is you would also have to setup the hosting account to accept requests from the new domain. This seems to be what you're trying to avoid.
If this is the case, you'll need a static IP, and Apache setup to accept wildcard domains and pass them to your application (index.php in this case). You may not need a VPS for this, just a relatively configurable shared hosting account.
Update: To get this working on shared hosting, check out the Apache VirtualHost directive. That's what Apache uses to setup a (wait for it) 'virtual' web server (document root, logs, etc) allowing a single server to host multiple sites. Also checkout Named Based Virtual Hosting, you'll need an account that doesn't do virtual hosting that way.

"So it should be a case of a user signing up and it immediately works without me having to manually do anything"... So you want magic. Anyways domains point to a directory so that is easy just point all domains to the same directory. PHP can examine the full URL so you can use that to select the content.
If you are using something like Joomla you might be able to customize the starting extension. For example all joomla content is stored in tables named jos_XXX.
It should theoretically be modifyable to the base table is domain_com_XXX
Maybe, but you really need to find a good programmer for this, I don't know of any systems that will do this out of the box. Maybe someone else might know of one.

Related

Domaining with PHP

I have a site say abc.com and a user account is accessed at abc.com/user. Now I want to add functionality that user can link his site say user.com to abc.com/user. Can u please give me an overview that how this process can be done dynamically via php?
Set up DNS to point the host name at the server
Set up the server configuration so the site is the default virtual host (so if an unrecognised domain name is used to request it, the right site will be loaded)
Use $_SERVER['HTTP_HOST'] instead of the path.
If I understood correctly - you want that a person who is entering user.com will see the content from abc.com/user.
I would recommend checking out launchrock.com they do exactly this, and it involves adding a CNAME dns record as I remember, another way to do this is to create a Proxy flag rule in httpd (mod_proxy must be enabled for this), so that you won't have to restart the server, you can always the .htaccess in your www dir.
doing so dynamically will be easy if you go the proxy route, as you just need to append a new proxypass every time a new site is deployed, or create a parameterized rule, like a regular htaccess, as far as automating DNS records creation, I'm sure that's possible and maybe DNS provider such as godaddy or AWS have api for those kinds of things, but more research is required.

webpage hosted on a server which is pointed by separated domain name, how to hide original server path?

Am sure there's answer on Google but I don't know how to formulate my question:
A php website is hosted on server like this: http://sub.realserver.com/website/index.php
Now I want to link the real domain name to it: http://therealwebsite.com
Problem is, when user visits:http://therealwebsite.com, he will see http://sub.realserver.com/website/index.php as he browse through other pages.
Question is how do I hide this realserver path and replace it with the domain name?
Thanks
edit: the website is hosted on a different server as the real domain name
I presume the domain name and the web site are pointing to the same server.
Although you could use URL rewriting (works with almost all popular web servers), the better solution is to set up your web server to provide that web site for the root of that domain name. How to do that completely depends on what server software you are using.
In apache, you need to create a so-called Virtual Host, configure it to respond to your domain name and set its DocumentRoot directive to the directory where your site is located.
See http://httpd.apache.org/docs/2.0/vhosts/examples.html for an example.
EDIT: I just read your comment. I'm afraid your options are rather limited. The easiest solution, but also the most dirty one, is to create one page with an IFRAME on it, that loads the site from the real server. You could also host a PHP proxy and on the server that hosts your domain name, and let it proxy the site on your
http://sourceforge.net/projects/php-proxy/
(I never used this, nor am I affiliated with this project, but it seems to claim to do what you want.)
I highly recommend though that you update your DNS records on your domain name so that it points to your server that hosts your site, and that you add a virtual host there.
you can do this with asp, there is a good resource on it here -
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Setting up custom domain of users' inputted domain

This may be a server question, but I'm asking how to do this system in PHP before you vote to close as off-topic.
I'm setting up a custom cloning site system, where paid users can have their own software but on a custom subdomain build, e.g. user1.domain.com. I want to allow them to have their own paid domain pointing to my server replacing their built subdomain. However, I don't know how to do this kind of process in raw PHP.
For example, on an administration page, they can input their paid domain and I want the domain to be added to BIND DNS/nginx on my server, but I need to know what I need take from there (except URL validation) such as checking if the domain is pointing my server when they enter the nameservers of my server from their domain manager (GoDaddy, 123-reg, etc) and so on and making sure the domain is properly active and can be taken well when accessing the new domain that replaces the built domain (nginx can do this?)
What steps should I take into making this kind of system? Is there any server support I need to take into such as cron jobs or such.
My server is running Ubuntu 11.10 with nginx 1.0.6.
EDIT: I already have a wildcard A record in BIND.
Just point *.domain.com to your server. Assuming you are running Apache, you just define your VirtualDocumentRoot in httpd.conf and you're off and running. Nothing to do in PHP or anything else.
Check out the documentation here: http://httpd.apache.org/docs/2.0/vhosts/mass.html
UPDATED
Didn't catch you were using nginx, sorry about that - looks very similar to Apache:
root /PATH/TO/WEBROOT/$host;
in your server { config. http://wiki.nginx.org/VirtualHostExample
Edit your configuration file (nginx.conf) and change the server section beneath http as shown in the VirtualHostExample at the link above, replacing the server name and paths with your server's info.

How can I detect entry to a website by domain?

If I have multiple domain entry points and want to use the same hosting, can I detect by way of PHP or JavaScript what domain that person came though to the hosting website?
ie: I have 3 domains:
www.jackfrost.com
www.holycow.com
www.ohmy.com
Hosting is under www.jackfrost.com.
So if somebody comes in through www.ohmy.com, can I detect that, so I only display content for that entry and different content for a different entry?
(purpose is to keep costs down since the websites are hosted by godaddy)
The best way you can do is to have a look at $_SERVER['HTTP_HOST'] in your PHP script and dispatch your content based on that.
In JavaScript, you can check window.location.hostname for the domain name used.
However, a better way would be to have three different virtual hosts in your webserver configuration - one for each domain you have. This way, even without PHP or any other scripting language, you can have different content for different domains. When using Apache as webserver, you can have a look at the documentation with examples: http://httpd.apache.org/docs/2.2/vhosts/examples.html.
If you do not want or can use name based virtual hosting, you can use only one virtual host, and use mod_rewrite of Apache to internally rewrite requests to other directories based on HTTP_HOST.
If you are using Apache you should set up name-based virtual hosts.
Apache V1
http://httpd.apache.org/docs/1.3/vhosts/name-based.html
Apache V2
http://httpd.apache.org/docs/2.0/vhosts/

looking to create a hosted solution

I am in the early stages of thinking through a product I am looking to develop, the product is a hosted e-commerce solution. What kind of things do I need to think about when allowing users to register there own domain names? Hows does that even work? I know I can do subdomains, but no idea how a users own domain would work on the hosted solution?
Any ideas?
You can run multiple domains on a single host using virtual hosts, as supported by HTTP 1.1. See the Apache docs for setting up virtual hosts for Apache httpd for example (you may use some other web server).
You probably don't want to get involved with the actual domain registration: users should register the domain with an established domain registrar and configure the A record to point to your server.
All a user would then do is specify their domain name and you'd update Apache's httpd.conf (or equivalent config file) appropriately.
You might want to look into the easy way out - A resellers account. I had one before, it was easy to use and setup. The only problem I had was there are extra fees if you want people to register domains though your website. It's worth the money if your going to make it back.
I used JustHost.com, there pricing is fair but there e-mail system and cPanel are out-dated. E-mail is fine if you use POP3 or IMAP.
Good Luck,
CwTechies

Categories