Question

Need help moving Wordpress site as 2nd domain on Ubuntu nginx

Posted February 14, 2018 786 views
NginxWordPressUbuntu 16.04

I’m having trouble moving a wordpress website to a new LEMP server. lets use “example.com” as the example. I successfully copied the PHP files and the database to the new server and temporarily set it up as “example.org” so the “live” example.com would keep functioning while I worked on the new server. I created a server block for it and example.org was working just fine.
Here is the partial server block code that was working with the .ORG site.

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;
    index index.php index.html index.htm;

    server_name example.org www.example.org;

   location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
}

PLEASE NOTE: We already had a very busy production web site on the LEMP server at “email.example.com”, a sub-domain we use for our email campaigns. That site has been working very well for 6 months. It was using the DEFAULT server block and still is. Here is the code for that site.

# Default server configuration
#
server {
                listen 80 default_server;
                listen [::]:80 default_server;

        root /var/www/html;

                # Add index.php to the list if you are using PHP
                index index.php index.html index.htm index.nginx-debian.html;

                server_name email.example.com mailer.example.com;

                try_files $uri $uri/ =404;
                }
}

Since everything was working great with “email.example.com” the default site, and “example.org” the new site, I decided to point “example.com” to the IP address of the new LEMP server. I edited the Server block for the new site to reflect the server names “example.com www.example.com” as below. I included some redirects, which I hope are correct, so that “example.org” and “example.net” also, hopefully, resolve to “example.com”.

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

                rewrite ^/(.*)$ http://example.org/$1 permanent;
    rewrite ^/(.*)$ http://example.net/$1 permanent;

                location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
}

And YES I also changed the entries in the wp_options wordpress table for “siteurl” and “home” to “http://example.com”.

BUT now when I enter example.com or example.org or example.net into my browser the DEFAULT website *http://email.example.com * appears instead of the new site! But the URL displayed in the Browser is example.com. Right URL but Wrong website.

Please help if anyone can tell me what I may have done wrong.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

As you have already done most of the required steps, this sounds like that the permissions for the /var/www/example.com/html directory are not correct and Apache is unable to read the files in that directory.

What you could do is:

  • Find what user Apache is running with:
  • sudo ps aux | grep apache

The output would looks omething like this:

  • ps aux | grep apache
  • www-data 5131 0.0 1.1 1063424 11428 ? Sl 00:00 0:02 /usr/sbin/apache2 -k start
  • Then get the user (should be the first column, in my case it is www-data) and run:
sudo chown -R www-data:www-data /var/www/example.com/html
  • After that test your site again, if this is still not working, then I would suggest checking your Apache error log for more information:
tail -100 /var/log/apache2/error.log

There you should be able to get more information for further troubleshooting.

Regards,
Bobby

Submit an Answer