Why aren't my virtual host settings in LAMP/Ubuntu working?
I have created a linode with a LAMP stack running on Ubuntu 22.04, and intend to use it to host a number of websites. I have followed this guide several times, using different server names and domains.
https://www.linode.com/docs/guides/configure-apache-to-run-multiple-wordpress-sites-on-one-linode/
But the furthest I get is to have a domain point to the IP of the linode, rather than obeying the virtual host as I interpret its purpose. I have never been able to get to the wordpress setup stage as it's listed at the end of the article — using [ip]/domain.com/public_html — I have only been able to see a site when I've placed it in var/www/[reverse dns]/public_html/[my sub folder] folder and visited it via [ip]/[my sub folder]. I created a domain in linode (NS are pointed to linode) for mydomain.org using default records for this linode, it only points to the original linode IP, regardless of what I've placed in the virtual host files.
My conf file looks like this (targeting the site I can actually see), in sites-available and sites-enabled once I run the enable script:
<VirtualHost *:80>
# The primary domain for this host
ServerName mydomain.org
# Optionally have other subdomains also managed by this Virtual Host
ServerAlias mydomain.org *.mydomain.org
DocumentRoot /var/www/123-456-789-012.ip.linodeusercontent.com/public_html/mydomain
<Directory /var/www/123-456-789-012.ip.linodeusercontent.com/public_html/mydomain>
Require all granted
# Allow local .htaccess to override Apache configuration settings
AllowOverride all
</Directory>
# Enable RewriteEngine
RewriteEngine on
RewriteOptions inherit
# Block .svn, .git
RewriteRule \.(svn|git)(/)?$ - [F]
# Catchall redirect to www.example1.com
RewriteCond %{HTTP_HOST} !^www.mydomain\.org [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.mydomain.org/$1 [L,R]
# Recommended: XSS protection
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
Header always append X-Frame-Options SAMEORIGIN
</IfModule>
</VirtualHost>
Am I missing something obvious?
2 Replies
I suggest that you make this file inactive and substitute a 'bare bones' virtual host file. You can find them all over the net. Even Linode has one in one of their guides, but I forget where.
How are you creating your LAMP stack? Is it through the Set Up Apache to Run Multiple WordPress Sites on a Single Linode guide using sudo tasksel install lamp-server
or is it through the Linode Marketplace? Based on the directory name of your Document Root
, I'm guessing you deployed it from the Marketplace, since that's the default configuration when deployed that way. If not, the following instructions should still work.
My suggestion would be to delete that directory and fully follow the instructions in the "Apache/Multiple Wordpress Sites" guide, using the file structure noted there. Make sure to remove the file in /etc/apache2/sites-available/
as well.
If you'd like to keep those files as a reference, you're free to do so. You can use the command a2disssite 123-456-789-012.ip.linodeusercontent.com
to disable that site so that the .conf
file is no longer being served.
Now, when it comes to your virtual hosts file and accessing WordPress, the issue I found when testing this was first, that the example file was redirecting to HTTPS when there are no SSL certificates installed. to disable this, change the status of the RewriteEngine
:
# Disable RewriteEngine
RewriteEngine off
Save the file and reload Apache.
Then, instead of navigating "<your.ip.address>/domain.com/public_html" in your browser, try "http://yourdomain.org/wp-admin". I'm not sure if this is an Ubuntu 18.04 vs. Ubuntu 22.04 or a newer version of WordPress thing, but this is what I found worked for me. You will then be able to go through the WordPress setup and installation. </your.ip.address>
Then if you want to install an SSL certificate in the future, all you have to do is install Certbot and re-enable the rewriteEngine
before you run the certbot --apache
command.