0

This is not duplicated Post!

System information: LAMP installed on Ubuntu 18.04

I have two WordPress websites on Digital Ocean droplet, let's say domain1 and domain2. I set up 2 virtual hosts. My domain2 located on /var/www/domain2 works fine but

domain1 is redirecting to /var/www/html instead of /var/www/domain1. Besides this, when I copy all files of domain1 to /var/www/html for testing purposes and hit to domain1, it's giving white screen of death. Additionally : When I put a basic index.html file, it shows properly. But still it shows the index.html file of /var/www/html

let's encrypt already installed for both domains.

Here the contents of relevant files:

/etc/apache2/sites-available/domain1.conf :

    UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin domain1@gmail.com

        ServerName domain1.com
        ServerAlias www.domain1.com

        DocumentRoot /var/www/domain1

        <Directory /var/www/domain1/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain1.com [OR]
RewriteCond %{SERVER_NAME} =www.domain1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

</VirtualHost>

/etc/apache2/sites-available/domain2.conf :

    UseCanonicalName On

<VirtualHost *:80>
        ServerAdmin domain2@gmail.com

        ServerName domain2.com
        ServerAlias www.domain2.com

        DocumentRoot /var/www/domain2

        <Directory /var/www/domain2/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain2.com [OR]
RewriteCond %{SERVER_NAME} =www.domain2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

There is a -le-ssl.conf file for domain2 (coming from let's encrypt). Strangely there is no this kind of file for domain1. I copied and renamed and configured for domain1 but still no luck.

/etc/apache2/sites-available/domain2-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerAdmin domain2@gmail.com

        ServerName domain2.com
        ServerAlias www.domain2.com

        DocumentRoot /var/www/domain2

        <Directory /var/www/domain2/>
            Options FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/domain2/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain2/privkey.pem
</VirtualHost>
</IfModule>

Finally, .htaccess file which is the same for both of websites :

.htaccess

    # BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

I did these if you ask :

  • Restart apache after configurations
  • enabled the .conf files with a2ensite
  • dissabled the 000-default.conf file with a2dissite

Edit: Also, when I google http://my.ip.address it redirects to https://domain1.com with white screen.


Update

Here the apache2 error logs could be related:

[mpm_prefork:notice] [pid 31941] AH00171: Graceful restart requested, doing restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.18.0.5. Set the 'ServerName' directive globally to suppress this message

[php7:warn] [pid 12694] [client ] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0  [php7:error] [pid 12694] [client] PHP Fatal error:  Unknown: Failed opening required '/var/www/html/index.php' (include_path='.:/usr/share/php') in Unknown on line 0

Please note that: I changed the file permissions to 755, still it is the same.

Could be it be ServerName issue? : https://askubuntu.com/questions/256013/apache-error-could-not-reliably-determine-the-servers-fully-qualified-domain-n Here the vhosts file:

127.0.1.1 myhostname myhostname
127.0.0.1 localhost

Stangely my hostname and hostname fqdn is the same. Is that okay?

Looking forward your answers!

  • What does `ErrorLog ${APACHE_LOG_DIR}/error.log` show for this request? – Tero Kilkanen Jul 27 '20 at 13:43
  • Hi @TeroKilkanen! Here these could be related: `[mpm_prefork:notice] [pid 31941] AH00171: Graceful restart requested, doing restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.18.0.5. Set the 'ServerName' directive globally to suppress this message` – Mehmet Dogan Jul 27 '20 at 14:24
  • @TeroKilkanen `[php7:warn] [pid 12694] [client ] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 [php7:error] [pid 12694] [client] PHP Fatal error: Unknown: Failed opening required '/var/www/html/index.php' (include_path='.:/usr/share/php') in Unknown on line 0` – Mehmet Dogan Jul 27 '20 at 14:26
  • Please edit the question and add output error log output there, it can be formatted better there. – Tero Kilkanen Jul 27 '20 at 15:54

1 Answers1

1

The error shows that PHP cannot read /var/www/html/index.php because the file permissions do not allow it.

You need to make sure that file ownership and permissions allow PHP to read the file.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • I changed the permissions to `755` but still, it gives white screen and it doesn't explain why virtual host redirects to `/var/www/html` instead of `/var/www/domain1` @TeroKilkanen Thanks! – Mehmet Dogan Jul 27 '20 at 16:42
  • Have you enabled `domain1` configuration with `a2ensite`? – Tero Kilkanen Jul 27 '20 at 20:50