Problems setting up a new whitelabel service via CNAME - php

I have a SAAS and am trying to allow other people to use my SAAS in their own domain. So, supposing my site is app.example.com (hosted with Apache and with PHP as the backend language), I want to allow someone to offer my website from, for example, app.anotherwebsite.com.
I already created a CNAME on app.anotherwebsite.com:
app.anotherwebsite.com CNAME app.example.com.
But if I access app.anotherwebsite.com, it loads the default cPanel page on app.anotherwebsite.com/cgi-sys/defaultwebpage.cgi.
I already tried many solutions offered on the web with no luck. Does anyone have any clue how to solve this? Do I have to do something on the example.com server to fix this?
Thanks a lot!

When you create a CNAME and try to make a HTTP request to it, the computer does the follow:
1) Try to discover the IP related to your hostname (in this case, app.anotherwebsite.com), and the CNAME it's an alias to another hostname, that need to point to an IP address;
2) When the computer has the IP address of the hostname, it connect to port 80 (in case of HTTP) or port 443 (in case of HTTPS) and request the page app.anotherwebsite.com;
3) Your HTTP server at the IP address will search it configuration for a virtual host that match app.anotherwebsite.com. If there's no virtual host configured that match the requested hostname, it will serve the default virtual host. At Apache, if there's no explicit declared default virtual host, the first virtual host configured will be elected as default.
In your case, your CPANEL is your default virtual host, and that's why it's displaying it.
So, to make your SASS work at this scenario, you can change your default virtual host to your application or you can add a virtual host with wildcard, like app.*. It'll receive the requested hostname (at PHP, you can access it as $_SERVER["SERVER_NAME"]).
Below is an example code:
<?php
echo "Hello!<br />\n";
echo "<br />\n";
echo "I'm seeing you're requesting the hostname " . $_SERVER["SERVER_NAME"] . "!\n";
?>
Your code can handle this information and serve your client based on that variable.
EDIT:
You can add a virtual server at Apache using this code:
<VirtualHost *:80>
ServerName app.example.com
ServerAlias app.*
DocumentRoot /var/www/SASS
<Directory /var/www/SASS>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/SASS-error.log
CustomLog ${APACHE_LOG_DIR}/SASS-access.log combined
</VirtualHost>
This Apache virtual host add a new server named app.example.com, and will also match app.* requests.
The server will point to /var/www/SASS as root directory, looking for index.html or index.php (if there's PHP enabled at Apache) file.
The permissions to /var/www/SASS granted with tag <Directory> disallow the automatic creation of index files of directories without index file and allow use of .htaccess.
Also, was created a separated error_log and access_log to log requests matching this entry.
To check your Apache configuration and look for all your virtual hosts, use the following command:
apachectl -t -D DUMP_VHOSTS
This will produce an output like:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server cpanel.example.com (/etc/httpd/conf/httpd.conf:994)
port 80 namevhost cpanel.example.com (/etc/httpd/conf/httpd.conf:994)
port 80 namevhost app.example.com (/etc/httpd/conf/httpd.conf:1044)
wild alias app.*
Syntax OK

Related

FileNotFound exception Wamp server [duplicate]

So I set up a few virtual hosts with unique urls and they work just fine on the desktop. However, when I connect a mobile device on the network, it can't seem to access anything properly but the default localhost virtualhost and that's only when it's the only virtualhost I have up.
My setup and coding is pretty much this except with a different site title
wamp server 3.0 virtual host on another device
and while that solution redirects me to my unique url, it has a lack of images on a default wordpress website.
Has anyone managed to get mobile devices fully accessing links other than on localhost?
Since I posted the answer you referenced, I have decided upon a simpler solution.
What the actual problem is
Because we cannot fiddle with the configuration of a phone like we can with a PC, the phone can never find the domain name we create in our Virtual Host definition on the Server machine, because it does not exist in any DNS Server for it to locate the IP Address in, and a DNS Server is the only place a phone can look, unless it is jail broke.
If you wanted to access one of your Virtual Hosts domains from another PC you could just add a line like this into the HOSTS file on the other PC like this.
192.168.0.10 example.local
But you cannot do that on a phone/tablet.
What Apache expects to be able to asssociate a request to a Vhost
When we create an Apache Virtual Host, we are actually telling Apache to look at the domain name on the incoming connection and match that domain name to a ServerName that exists in one of our multiple Virtual Hosts definitions.
But if we use for example example.local as our virtually hosted domain when we attempt to connect to that from our phone, the phone does a DNS Lookup and does not find that domain and therefore cannot get its ip address.
The simplest way to get round this is:
Assuming we do not have access to adding record to a DNS Server we have to come up with a different solution.
The simplest of these is to use the IP Address of the PC running the WAMPServer(Apache) server and a specific port number. So thats a different port number for each of our sites we want to use from a phone.
So how do we do this
Add the new listening port to httpd.conf like so after the 2 existing Listen statements
WAMPServer 3: Do this using the menus, not by doing a manual edit on httpd.conf
right click wampmanager-> Tools -> Add listen port for Apache
#Listen 12.34.56.78:80
Listen 0.0.0.0:80
Listen [::0]:80
Listen 0.0.0.0:8000
Listen [::0]:8000
Suggested httpd-vhosts.conf file
#
# Virtual Hosts
#
# Always keep localhost, and always first in the list
# this way a ramdom look at your IP address from an external IP
# maybe a hack, will get told access denied
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp/www
<Directory "c:/wamp/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# The normal Vhost definition for one of our sites
<VirtualHost *:80>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
# Access example.dev from phone for testing
<VirtualHost *:8000>
ServerName example.local
DocumentRoot "c:/websrc/example/www"
<Directory "d:/websrc/example/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
# assuming yoursubnet is 192.168.0.?
# allow any ip on your WIFI access
Require ip 192.168.0
</Directory>
</VirtualHost>
Restart Apache from wampmanager after completing these edits.
Now you test this from the WAMPServer PC by using the ServerName i.e example.dev and from the phone using the ip of the PC running WAMPServer with the port number i.e. 192.168.0.10:8000
Apache will find the correct code to serve from both requests.
If you want more than one Virtual Host to be accessible from your phone you just duplicate this idea and change the port number for each new site, lets say you would use 8001,8002,8003 etc. For as many sites as you want to access.
You may also have to amend your firewall to allow access on http on port 8000, or whatever port you pick to use

Cakephp 3 and Subdomain

Cakephp 3 and Subdomain
I have an application cakephp 3 inside the root of my server and need to create a subdomain that this also goes in the same root with the cake.
example:
bin
config
src
...
shop (Sub domain)
How have the cake in my root it does not allow access subdomio.
What can I do to get around this problem?
Because the file convention of cakephp is sometimes hard to get the result you want to.
Correct me if I'm wrong. Your situation looks like this?
www.maindomain.com, which run by 'src'.
But you want the sub.maindomain.com use other files outside the cakephp file structure
I think it's too much effort to work outside the file convention. I think this is more '.htaccess' and 'virtual hosts' issue.
I've found a link that maybe can you help you "CakePHP subdomains with htaccess"
UPDATE:
Also keep in mind the folder-permission issue when you try to fix this.
I think the best approach is to have a VirtualHost configured, I am assuming you use Apache, so that the shop folder isn't part of the root of the server. Here you can see how to do it:
Move shop folder to outside Apache root so it's not part of the main website. If it's in /var/www/html/shop move it to /var/www/
Add a VirtualHost to Apache httpd.conf file or add it as shop.conf into /etc/apache2/sites-available/ assuming your server is an Ubuntu 14.04, you must know where to save the file according to your distro.
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName shop.local
ServerAlias shop.local
ServerAdmin alejandro#ulfix.com
DocumentRoot /var/www/shop/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Optional: Edit /etc/hosts file so that you can reach the new subdomain if it is in a VM o you can't resolve it from your computer:
192.168.100.14 shop.local # Change IP to your Server's IP
Enable site in Apache (In Ubuntu you'll need to run: sudo a2ensite shop.local) and restart Apache Server.
See CakePHP 2.x virtual host file for Apache2 for reference.

Virtual not working in other system wamp

Virtual host not working in the NETWORK
I just followed this site tutorial,
Virtual host steps
The tutorial was excellent but when I try this alias URL in another system, its not working. I have checked in my other system, I am able to see my application, after I did these changes I am not able to see my application on the other system.
I have even changed Allow from 127.0.0 to all but that is not working.
My C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
This what I added
<VirtualHost *:80>
ServerAdmin webmaster#developertalk
DocumentRoot "C:/wamp/www/developertalk"
ServerName developertalk
ServerAlias www.developertalk
ErrorLog "logs/developertalk-error.log"
CustomLog "logs/developertalk-access.log" common
<directory "C:/wamp/www/developertalk">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
When hitting URL in another system, getting following error:
Server not found
In my local host i am having 3 web application.
Due to above changes my local host other sites not working.
How to make it work other sites.
You need to use local DNS to say every PC in Your network, that You have on Your PC host 'myApp', also You can add to every client's hosts file something like myapp 192.168.1.2 where 192.168.1.2 Your static IP in network
For every computer you want to have access to http://developertalk, you need to edit the Hosts file in each one.
Located at (xp/win7): C:\Windows\System32\drivers\etc\
You need to add only 1 line on every computer.
(your static internal ip) www.developertalk
example:
192.168.1.71 www.developertalk
you can check your internal ip address on your windows by opening cmd and typing ipconfig.
Look for the IPv4 address under the Ethernet adapter Local Area Connection column.
If you don't request or assign a static internal IP to your computer, others will not be able to connect to http://developertalk which was forwarded to your old internal IP.
Egor Sazanovich has actually answered your question and provided you with extra information, so accept his instead of this one, if this helped at all.

Go to a different port from different domains

I have 2 "hypothetical" domains. myname.me, and myproduct.co.nz. I have four servers forded to the ports 44, 45, 80 and 90 of my public ip address.
The domains both have their A record set to my ip, so myname.me:44 and myproduct.co.nz:44 bring up the same page.
What I want, is for visitors to myname.me to see the page on the server operating on port 90, but not for them to see ":90" in the address bar.
I also want visitors to a.myproduct.co.nz to see the page on the server operating on port 44, and visitors to b.myproduct.co.nz to see the page on the server operating on port 45, both without seeing the :44 or :45 (e.g. I want the pages all serverd on 80).
The servers are all apache2 with php.
I guess that it would be something related to http://httpd.apache.org/docs/2.2/vhosts/name-based.html, but I am not sure how it would work with 2 servers.
I'd really appreciate any help.
~JJ56
Setup name-virtual-hosts on your "port-80 machine". Then use ProxyPass (from mod_proxy) within each virtual host definition, to pass requests from your "port-80 machine" to the other machines behind your firewall.
It might look something like the following:
(NOTE: The main server (your "port 80 server") has to be able to reach the other servers on your internal network -- I've used numeric addresses (192.168.1.5, and 192.168.1.6)).
<VirtualHost *:80>
DocumentRoot /var/www/myname.me/public_html
ServerName myname.me
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.1.6/
ProxyPassReverse / http://192.168.1.6/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/myproduct.co.nz/public_html
ServerName myproduct.co.nz
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://192.168.1.5/
ProxyPassReverse / http://192.168.1.5/
</VirtualHost>
Setup the virtual hosts without the proxy-related stuff first. Make sure you can successfully resolve a test page in each of the two vhosts. then (and only then) add in the proxy stuff, and start working the kinks out of that.
While I want to answer your question, I have to ask why you would want to configure the server in this way. What it seems you're really trying to do is configure multiple domain (or Name Based Virtual Hosts) on this shared IP address.
If that's the case, then in Apache it's very easy to set up. Each domain will need to be defined in the httpd.conf or vhosts.conf (or inside of the catch-all include directory depending on your installation; see your documentation). A very basic set up would look like the following:
<VirtualHost *:80>
DocumentRoot /var/www/mywordpressblog.co.uk/public_html
ServerName www.mywordpressblog.co.uk
</VirtualHost>
Best of luck.
You run one server on port 80 and use name-based vhosts, and you don't play any games with any other public ports. If you need different domains to hit different physical servers, you set up mod_proxy to proxy the requests to those servers, or you set up squid or varnish on port 80 to do the same thing. PHP doesn't come into it at all.

Create subdomain upon user registration

I have a website where I want users that sign up to get their own subdomain. This subdomain is virtual, and every subdomain uses the same web server files.
I use PHP and Apache, and I know about Virtual Hosts, but I'm wondering where I need to put the vhosts code. First, I don't have access to httpd.conf. Second, I want this to be done automatically upon registration.
I've read about virtual hosts, but didn't find anything that answers my questions. Is there anyone who can explain me how all this works together, or know where I can find my answers?
Can you tell apache to read an extra .conf file? (traditionally you store your vhosts in httpd-vhosts.conf)
if so, add something like the following and restart your webserver
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /abs/path/to/webroot
ServerName domainname.com
ServerAlias *.domainname.com
<Directory /abs/path/to/webroot>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
then in php, you can see which subdomain the user is requesting by inspecting:
$_SERVER['HTTP_HOST']
ie. if the user requests http://user1.domainname.com/index.php
$_SERVER['HTTP_HOST'] will have user1.domainname.com
you can then explode('.', $_SERVER['HTTP_HOST']) to inspect each segment.. etc.
You will need 3 thing for this:
1.
Set your DNS for *.yourDomain.com
2.
Add the ServerAlias directive to the apache configuration for this domain:
ServerName www.yourDomain.com
ServerAlias *.yourDomain.com yourDomain.com
Also make sure that you apache server has UseCanonicalName set to on (this is the default)
3.
Grep the subdomain name with PHP:
$nameChunks = explode('.', $_SERVER['HTTP_HOST']);
$subDomainName = $nameChunks[count($nameChunks) - 3];
(inspired by Janek's comment)
IF your Apache instance is configured for * aliasing, then there is no need to create a virtual named host - You can fake it with PHP by evaluating $_SERVER['HTTP_HOST'].
To determine if your Apache instance will handle it, edit your local /etc/hosts file (or windows equivalent - %SystemRoot%\system32\drivers\etc\hosts) so that the desired virtual name is pointing to your server.
For instance
# An example HOSTS file.
192.168.1.4 testserver testserver.com subdomain.testserver.com secondname.com
This assume that 192.168.1.4 is the IP of your server. Everything after that are alias's that the server can be called.
Then, as Janek suggested create a page that will echo $_SERVER['HTTP_HOST'] to see if it capturing the name correctly. If so, then all that is required is a DNS change and Apache can remain unchanged.
Otherwise without access to Apache.conf (this kind of implies that you don't have access to a lot of things) this will be difficult to pull off. The programming won't be - but the implementation will be.
Here's why:
Apache by default will serve up virtual hosts. But you do need access to the server's conf directory (often located in /etc/httpd/conf.d/) so you can create the virtual host "include" file (IF the Apache configuration is setup to include it - most recent installs should be).
You will need to be able to cycle Apache (restart). Without this the Virtual Host changes won't take affect.
You will need to be able to change the DNS. You can always change your local /etc/hosts file - but in order for visitors to get to your site, you'll need to be able to push through a DNS change. (Which may instantaneous - or it may take 24 hours to propagate).
The scripting certainly can be done (see Cpanel and WHM)
You will first of all need to setup the DNS server to resolve any subdomains to your main IP address, i.e. *.domain.com will have to resolve to your server's IP address. Then the web server needs to handle all incoming requests regardless of subdomain as well, invoking some PHP script. The PHP script can then simply figure out what domain was requested from the $_SERVER['HTTP_HOST'] header and act accordingly.
You're not actually "creating subdomains upon user registration".

Categories