4

I have the following problem: I made 10 WordPress sites for 1one client and now he needs me to configure the domains in his VPS.

Based on some searches I did on the internet, the first thing I needed to do was create a new file of configuration within /etc/apache2/sites-available and enable it with a2ensite. Perfect! I did it and it was as follows for each site:

<VirtualHost *:80>
    ServerAdmin (my email)
    ServerName (configured domain)
    ServerAlias (configured domain)
    DocumentRoot /var/www/html/10_sites/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/html/10_sites>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

My .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteBase /10_sites/
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

</IfModule>

After that, I had to go to the websites and change the website address, I went there and changed it to the correct address.

After enabling the 2 configurations it worked as I wanted today it opens the site in the domain. So theoretically everything would be right.

But then I came across a problem, when I open the site and I go to the administrative area (/wp-admin) and I try to login it says:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at (my email) to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

11
  • 3
    "More information about this error may be available in the server error log." so what does the error say? Oct 3 '20 at 15:58
  • @DavidPostill Beat me to it! Honestly, I look at this and I don’t think this is an Apache issue at all but an issue with the code and config (WordPress) for each of the 10 sites. I would recommend not only checking the error logs for Apache ({APACHE_LOG_DIR}/error.log) but also would recommend simplifying the .htaccess to the recommended default basic WordPress .htaccess config which can be found here. I think the issue is: Are you using WordPress in multisite mode or do you have multiple WordPress installs for each site? Oct 3 '20 at 16:04
  • what des the PHP error log say? Does this issue happen if you try to access the readme.html file? A 500 error is just a super generic something went wrong message, you have not shared the actual error message with us, and nobody can help without the error message
    – Tom J Nowell
    Oct 3 '20 at 16:42
  • 1
    Why do you have all those rewrite rules? WordPress doesn't need anything like that complex.
    – davidgo
    Oct 3 '20 at 20:05
  • 1
    @davidgo That .htaccess ruleset comes directly from the multisite example on the official WordPress site [as seen here. Oct 3 '20 at 23:42
1

it opens the site in the domain

Have you tested inner pages, not just the homepage?

A seeming inconsistency in your config is that you have defined DocumentRoot /var/www/html/10_sites/ in your vHost(s) yet you have set RewriteBase /10_sites/ in your .htaccess file.

Unless your site files are located in /var/www/html/10_sites/10_sites/ (yes, the last directory repeated twice) then you will get a rewrite-loop (500 Internal Server Error) for any requests other than the homepage (including /wp-admin pages), since index.php will not be found.

Requests for the homepage, ie. http://example.com/, will work OK since this does not rely on the mod_rewrite directives in .htaccess to route the request to index.php. Instead, this is handled by mod_dir and the DirectoryIndex.

I did it and it was as follows for each site:

However, there are other inconsistencies with your config...

If you are using WordPress multisite (as implied by your .htaccess file) then you should not be defining a vHost for each domain (at least there is no need to unless you specifically need separate log files from the get go*1 or to perhaps customise the config per domain - neither of which is suggested by your config). You would simply include a ServerAlias for each domain. (There is no need to define ServerName and ServerAlias the same - as implied by your config.)

(*1 The config you posted implies you are using a single access and error log for all domains. This is more performant than using separate log files for each domain, however, you need to customise the log format to include the requested hostname (which you have not done). Otherwise, you will not be able to split the logs later.)

But if you are not using WP multisite then you shouldn't be defining the same vHost for each domain (as implied by your <VirtualHost> config).

6
  • Well, I followed your advice and removed RewriteBase /10_sites from my .htaccess and it worked as you did, but if I remove ServerName it goes to another WordPress installation that has no relation to these 10 sites (goes to another domain that this directly in /var/www/html). Anyway, it solved the problem of opening the other pages of the site, but when I try to access, for example, wp-admin it directs to domain.com/var/www/html/10_sites/wp-admin and ends up giving a 404 error, so if I go back .htaccess wp-admin works, but again does not open other pages besides home. Oct 6 '20 at 0:10
  • "removed RewriteBase /10_sites" - don't remove it entirely, it should be set to RewriteBase /. "remove ServerName" - Again, you shouldn't remove ServerName entirely - set this to some default. But set a separate ServerAlias for each domain you want to match.
    – MrWhite
    Oct 6 '20 at 0:22
  • Perfect friend, it was right in the way you explained, but still when I try to access the panel /wp-admin/ says: Error: The use of cookies is disabled in your browser. You need to enable cookies to use WordPress. I searched the internet about it, cleared the cache as requested and such, defined the define('COOKIE_DOMAIN', false); and to no avail, it seems to me something of the configuration. I'm sorry if something isn't clear, I'm using Google Translate to communicate with you :\. Oct 6 '20 at 22:25
  • I noticed a new problem, the other sites for example site1, site2 went down after this configuration, so it didn't help much. Oct 6 '20 at 22:54
  • "Error: The use of cookies is disabled in your browser." - That would seem to be a very different problem, not related to the Apache server config. "The other sites went down" - Make sure the paths are correct. Such a change to the server config shouldn't have caused "sites to go down" - although I'm not sure exactly what you mean by that.
    – MrWhite
    Oct 6 '20 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.