Wordpress not working when using Apache virtual hosts - wordpress

I currently use virtual hosts on my computer so that I can manage multiple sites on my computer.
Currently, I use c:/vhosts/php (default localhost) for regular PHP development, c:/vhosts/BTS for Wordpress, and c:/vhosts/cake for CakePHP development. (see below).
Now when I launch my WAMPP and go to http://BTS, it loads the index page but nothing else loads fine. When trying to click on the links, it links to http://localhost/xxxxx instead of http://BTS/xxxxx. What am I missing here? I don't want the server to access localhost since I'm using localhost for other projects. Please help.
<VirtualHost *:80>
DocumentRoot c:/vhosts/php
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/BTS
ServerName BTS
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/cake
ServerName cake
</VirtualHost>

Go into your MySQL database (thru phpmyadmin or whatever) and look for the following fields
In the wp_options table, change
siteurl
home
To http://BTS instead of localhost.
This will update all your links in wordpress.

You need to tell Wordpress what domain it is sitting on.
Login to your Admin CP, it's in settings somewhere

I think is in wordpress options in settings in general, then change in WordPress Address (URL) and in Site Address (URL), both need to be the same:
This is my configure, but you can change it with BTS
And check if it's right in mysql the configure with
select option_name, option_value from wp_options where option_name = 'siteurl';

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>

Home Page Wordpress on Free MAMP does not work

I have installed MAMP (free version) on my Mac and I see the Start Page but I have a problem:
I deployed wordpress but browser say unable to connect (basically I cannot see wordpress page in browser).
In Document Root if I put a static html file I am able to see it in the browser. I am also able to see wordpress administrative pages and all other pages but home page. I have 8888 and 8889 for php and mysql ports. I do not know how to debug the issues. php, apache and mysql do not report any particular problems.
I configured virtual hosts following this guide:
http://foundationphp.com/tutorials/vhosts_mamp.php
The strange thing when I put http://localhost:8888/mywebsite in the browser it is redirected to localhost/mywebsite.
In /etc/hosts I have:
127.0.0.1 localhost
In httpd.conf I activated:
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
and in this file I have:
NameVirtualHost *:8888
<VirtualHost *:8888>
ServerAdmin myuser#gmail.com
DocumentRoot "/Applications/MAMP/htdocs"
ServerName localhost
ErrorLog "logs/mywebsite-error_log"
CustomLog "logs/mywebsite-access_log" common
</VirtualHost>
Hope someone could help.
I found the solution. After several debugging I found that this guide is correct: http://foundationphp.com/tutorials/vhosts_mamp.php
You need: 1. In /etc/hosts add your virtual hosts like:
127.0.0.1 localhost
127.0.0.1 mywebsite
before I only used localhost because I hoped to use this host in browser but I found it's required to define a new host like mywebsite.
In httpd.conf I activated:
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
In this file I have:
ServerAdmin myuser#gmail.com
DocumentRoot "/Applications/MAMP/htdocs"
ServerName mywebsite
ErrorLog "logs/mywebsite-error_log"
CustomLog "logs/mywebsite-access_log" common

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

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.

How to enable wordpress website locally on network and via localhost

My wordpress site works fine on my mac via localhost, using Xammp. I want to view the site on my iPhone. So I type in 192.168.0.2 and voila, it brings up my localhost directory. I then click on the site in question and the content is there but no styling or images. I realise that this is because the paths to all the resources is hardcoded into the wordpress database. So when I am accessing the url via 192.168.0.2/mywebsitename on my iPhone, it's looking for all the resources using a base url of localhost/mywebsitename. Localhost path doesn't exist on my iPhone, only 192.168.0.2 does.
So has anyone found a solution to this little issue? How can I see a wordpress installation by ip address and by localhost access?
For this exact issue, before developing a website. You must create a domain(VirtualHost in apache)
Add the following contents in the file httpd-vhosts.conf, make sure it is included in Apache Configuration. This line ( Include conf/extra/httpd-vhosts.conf ) should be present in httpd.conf
Contents of httpd-vhosts.conf:
NameVirtualHost 192.168.1.26:80
<VirtualHost 192.168.1.26:80>
<Directory "e:/program files/ampps/www/mywebsite">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName 192.168.1.26
ServerAlias 192.168.1.26
ScriptAlias /cgi-bin/ "e:/program files/ampps/www/mywebsite/cgi-bin/"
DocumentRoot "e:/program files/ampps/www/mywebsite"
ErrorLog "E:/Program Files/ampps/apache/logs/192.168.1.26.err"
CustomLog "E:/Program Files/ampps/apache/logs/192.168.1.26.log" combined
</VirtualHost>
(Change the path, ip, etc according to your need). Now after adding the contents. Restart Apache. Now when you access 192.168.1.26 (in my case) from other machine in your network or your same machine. You should see the contents of mywebsite folder directly(or contents index.php if it has any). Now install wordpress using the ip you specified(browser should have that ip in the address bar), in my case 192.168.1.26.
Well I use AMPPS to avoid this headache. It allows me to create domains locally. Also if I have bought a domain say mywebsite.com and i want to add a customized wordpress site on, I create a the domain in the AMPPS with the same name. So the URL of my live website and the local are same. :) Then I simply put the files directly on my server via FTP and obviously import the database on my server.
EDIT: BTW, AMPPS allows to install WordPress in a single click. It has simple interface where you can specify AMPPS to install the WordPress on the created Domain.

Resources