WordPress multisite setup as subdomain - wildcard DNS record setup - wordpress

I am new to WP multisite environment. I want to setup multisite in my local Ubuntu 14.04 environment. I already have localhost for my main site configured as carbazarlocal.com and its running OK. When I go to Tools > Network Setup I can see two options - Sub-domain and Sub-directory. I want to setup my multisites as sub-domains like dealer1.carbazarlocal.com, dealer2.carbazarlocal.com etc.
On this page WordPress says "You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality". How to do this and where?
In /etc/hosts I have the following entry:
127.0.0.1 carbazarlocal.com
In /etc/apache2/apache2.conf I have the following:
<Directory /var/www/html/carbazar>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In /etc/apache2/sites-available/carbazarlocal.com.conf I have this:
<VirtualHost *:80>
ServerAdmin admin#carbazarlocal.com
ServerName carbazarlocal.com
ServerAlias *.carbazarlocal.com
DocumentRoot /var/www/html/carbazar
</VirtualHost>
And in /var/www/html/carbazar/wp-config I have this:
define('WP_ALLOW_MULTISITE', true);
What else I need to do and where to complete the following step:
"You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality"?

If you use Apache server then ...
In the httpd.conf file, or in the include file containing the VirtualHost section for your web account, add a line like this (if it is not already present):
ServerAlias *.example.com
Also create a wildcard DNS record like:
*.example.com A 192.0.43.10
REF https://codex.wordpress.org/Configuring_Wildcard_Subdomains

Related

Multiple WordPress Multisite under one EC2 instance (AWS)

We are trying to to configure the DNS routing for our multisites under one EC2 instance.
Specifically we are setting up DEV, TEST, and UAT environments of a WordPress Multisite. We only just have 2 sites on this network; the main site and one network site.
Now I have successfully migrated a copy (using Duplicator Pro) of our production site (on a different EC2 instance) to our DEV and the WordPress Multisite works. We have set the wildcard entries on our route53 for this (will provide a screenshot later).
But when I migrated the same copy to TEST and UAT, the main site works but the network site is not working and only redirects to our DEV site.
Can you suggest the correct way of setting up the DNS and wildcards for this setup? Or it's not possible and should be on separate EC2 instances for each environment?
Check your setting in wp_options table for different environment. Whethere its set to dev URL or not.
select * from wp_options where option_name like 'siteurl';
OR
inside wp-config.php
define('WP_SITEURL','http://localhost/xyz');
it should be different for different environment. If possible give your URL sample.
You can use single EC2 for multiple wordpress instance. You have to set server configuration file to accept domain request under 80 or 443 port.
/etc/apache2/site-available/000-default.conf
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/html/project_name/public/
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html/project_name/public/
</VirtualHost>
<VirtualHost *:80>
ServerName www.abc.com
DocumentRoot /var/www/html/project_name1/public/
</VirtualHost>
<VirtualHost *:80>
ServerName abc.com
DocumentRoot /var/www/html/project_name1/public/
</VirtualHost>

ERR_NAME_NOT_RESOLVED on third level domain localhost for WPMU

I'm setting up WP Network on my localhost. I'm on windows, using Uniform Server, and I've setup a vhost like this:
<VirtualHost *:${AP_PORT}>
ServerAdmin webmaster#themes.wp
DocumentRoot ${US_ROOTF}/vhosts/themeswp
ServerName themes.wp
ServerAlias www.themes.wp *.themes.wp
ErrorLog logs/themes.wp-error.log
CustomLog logs/themes.wp-access.log common
<Directory "${HOME}\vhosts\themeswp">
Options Indexes Includes
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
plus I've added this on the windows Host:
127.0.0.1 themes.wp
If I go to
themes.wp
everything loads fine. If I try a third level domain, like
dummy.themes.wp
I get
ERR_NAME_NOT_RESOLVED
Wordpress Network tells me this:
Warning! Wildcard DNS may not be configured correctly!
The installer attempted to contact a random hostname (9f3c9c.themes.wp) on your domain.
This resulted in an error message: cURL error 6: Could not resolve host: 9f3c9c.themes.wp
Right, themes.wp and dummy.themes.wp different domains
Fast way: add dummy.themes.wp to you hosts file
127.0.0.1 dummy.themes.wp
Or install any simple dns server because hosts not support wildcard domains

How to prevent WordPress setup in 'blog' subdomain, redirecting to 'www' when trying to finish Installation

I have a main site http://www.example.com that's written in another language (Ruby/Rails). I want a wordpress blog installed in http://blog.example.com. I have control over the server and DNS.
I have created the necessary CNAME record for the 'blog' subdomain. But after setting up apache and restarting it, when I visit http://blog.example.com, for the final installation steps, I'm redirected to http://www.example.com/wp-admin/install.php.
Also now when I try to visit the main site http://www.example.com, I'm being redirected to the above wordpress install page.
How can I make it work like this: the blog should only reside in blog.example.com path, and the main site should be accessible via http://www.example.com.
Removing the www subdomain is not an option as it's been like that for awhile for the main site. It might be ok, if somehow a redirect can be setup from www to non-www url, though I'm not aware how to set it up.
Please suggest.
Here's the main site's apache conf:
<VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin webmaster#localhost
ServerName http://www.example.com
ServerAlias example.com
DocumentRoot /home/apps/example/current/public
<Directory /home/apps/example/current/public>
AllowOverride all
Options -MultiViews
</Directory>
#RewriteEngine On
#Redirect / http://example.com/
</VirtualHost>
Here's the apache conf for the wordpress under 'blog' subdomain:
<VirtualHost *:80>
ServerName blog.example.com
ServerAlias blog.example.com
ServerAdmin webmaster#localhost
DocumentRoot /home/apps/example_blog/wordpress_blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/apps/example_blog/wordpress_blog>
AllowOverride All
</Directory>
</VirtualHost>
WordPress has domain references in the database and the code which will throw your permalinks off and cause bad redirects. These renegade URLs should appear as 404's on your root domain (example.com). If not I'd double check the root domain with the sub domain removed from the vhosts.
I don't see any issues with your current vhost configuration. I would also try testing the domains in isolation if you suspect its vhost related. I suspect its a WordPress site url issue.
Assuming the database records are incorrect.
Log into phpMyAdmin or other database manager.
Select your WP database.
Go into the wp_options table (wp_ prefix may be different).
Look for the record's with option name = "siteurl" & "home".
Edit these records to reflect your new domain name.
Here's the WordPress documentation on how to switch a sites urls schema.
Document
Your problem is likely deep in various DB references throughout your WP project. I've run into this problem deploying WP before. You'll need to edit the DB directly to fix the issues.
Export your WordPress DB with phpMyAdmin or SequelPro (something that gets you a clean .sql file)
Use a text editor like Sublime or Atom, search for "www.example.com" and replace all with "blog.example.com" then save.
Upload DB to prod location and you should see these errors go away.
This should not happen if your virtual host is configured correctly
but still as your tables are not created so you can only do one try with this step :
you can add in your wp-config.php file the following parameter
define('wp_site_domain', 'blog.example.com');
This will force the wordpress to follow blog.example.com

Pointing domain name to server ip running XAMPP and wordpress

I installed XAMPP on my windows server and also installed Wordpress XAMPP module. I also bought a domain to point it to my server ip. Thing is , I want that when people enter mydomain.com , mydomain.com shows in the address bar and that it keeps showing while browsing.
First I tried to point the domain to my ip , and when I go to mydomain.com it shows mydomain.com/xampp
Then I tried to changing:DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
in httpd file in C:\xampp\apache\conf
to
DocumentRoot "C:\xampp\apps\wordpress\htdocs"
<Directory "C:\xampp\apps\wordpress\htdocs">
But this time when I enter mydomain.com it redirects to myipaddress.com/wordpress
All I want is:
1)When someone enters mydomain.com , he will see my wordpress home page.
2)Whenever a user is browsing mydomain.com , he will always see mydomain instead of myipaddress.
Any help would be appreciated.
Regards!
Type this at the bottom of your httpd file:
Alias /wordpress "C:/xampp/htdocs/wordpress/"
<Directory "C:/xampp/htdocs/wordpress/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Please take note that the directory that I stated above is a sample of a default directory. I am having a hard time trying to figure out your directory but the above example should make sense. After typing the codes on your httpd file, go to the directory of xamp/apache/conf/extra/ and openup the httpd-vhosts file. Type this at the bottom of the httpd-vhosts file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.yourdomain.com
ServerAlias yourdomain.com
ServerAdmin email#yourdomain.com
DocumentRoot "C:\xampp\htdocs\wordpress"
</VirtualHost>
Double check your host file if you already entered this line:
127.0.0.1 yourdomain.com
Restart your Apache webserver. Hope this helps!

Same WordPress Website but Different Sub Domain for Mobile Version

Let say I have WP website on mydomain.com, I'm using WP plugin WP Smart Mobile to automatically convert the website to mobile version depends on the devices. It works nicely, but I want to use sub domain m.mydomain.com rather than mydomain.com IF ONLY my website in mobile version. In short, m.mydomain.com and mydomain.com refer to the same website and database, m.mydomain.com address only display for mobile users. Is it possible to do? If yes, how?
Thanks for any enlightment for this case.
additional information: I'm using linux server with apache web server.
The way that I would use it is to create a virtual host for both the domain and the mobile subdomain (the vhost file goes in /etc/apache2/sites-available) :
<VirtualHost *:80>
ServerAdmin root#mydomain.com
DocumentRoot /var/www/path/to/document/root
ServerName mydomain.com
<Directory /var/www/path/to/document/root>
AllowOverride all # allow overriding of options with .htaccess
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root#mydomain.com
DocumentRoot /var/www/path/to/document/root
ServerName m.mydomain.com
<Directory /var/www/path/to/document/root>
AllowOverride all # allow overriding of options with .htaccess
</Directory>
</VirtualHost>
You will then need to enable the virtual host and restart apache. How to do this can vary depending on which linux distro you are using.
Once the vhosts are set up, both the domain and the subdomain will point to the same website. I'm assuming that your wordpress plugin can redirect mobile clients to the subdomain.
Update: You can use javascript to do the redirect, as long as you know that you are dealing with a mobile client.
var path = window.location.pathname,
host = window.location.host,
mobileVersion = 'http://m.' + host + path;
window.location = mobileVersion;
I also just had a thought, that the virtual host may be entirely unnecessary, as long as there is an A record for your subdomain. Sorry about that.

Resources