mikipetri74's picture

I am not a web dev in any way. I don’t know any languages other than bad English. But somehow I usually get by when working on projects. But I had a real stumper yesterday. I was trying to integrate some code (php site with a MySQL database) into a Turnkey Linux LAMP stack LXC on Proxmox. I figured out how to import the database and allow for the connection. I also compared settings to an existing TKL box that works. But I could not for the life of me get it past the point where the index.php file was redirecting me to the login page but it didn’t go to the right location. There was a complex .htaccess file at work as well but no matter what I did to the Apache .conf file I just couldn’t get it to work. Are there any good resources on TKL and how to configure it? It’s a pretty great kit but there are so many options I could use some guides or tutorials on how to integrate a web app into a LAMP stack from TKL? I don’t even get why the reverse proxy server sometimes requires the trailing slash and sometimes it’s fine.

Jeremy Davis's picture

You didn't note what/how you are configuring things. COnsdiering what you've written, I'd hazard a guess that you've used Webmin?! Personally, I'm a CLI user. Webmin can be handy sometimes for some things, but personally I often find that it's a bit convoluted and confusing. Obviously YMMV, but I would encourage you to use the commandline, especailly for configuring Apache. For most common stuff, it's actually fairly straight forward IMO.

If you (are using Webmin and) want to persist with Webmin, then I'd like to suggest the Webmin docs. You'll find all the separate module docs here, e.g. Apache conf.

If you're up for using the commandline (and perhaps even if you're not) then you'll find the main Apache docs useful too. Adjusting config via commandline is as simple as editing the relevant text file(s) and restarting Apache to apply the changes. If you're not that familiar with Linux commandline, then I suggest that you use the nano text editor. It's pretty much like a commandline version of Windows Notepad (which won't mangle Linux files). Use it like this:

nano path/to/file/to/edit

One thing worth noting though is that by default, Apache uses a single massive monolithic config file. On Debian (what TurnKey is based on) the config is split up into more user friendly (IMO at least) chunks. I would encourage you to follow this convention set by Debian.

For example if you want to add a new "site" aka "virtual host", create a new conf file, e.g. /etc/apache2/sites-available/new-site.conf and then put your config relevant to this site in the config. If you want, you can copy the default site as the base (and edit as per requirements). To enable your new site, disable the default site and apply the changes, try this:

a2dissite 000-default
a2ensite new-site
systemctl restart apache2

It's perhaps also worth noting that technically speaking, behind the scenes, Apache just reads all the config as if it were still one big file. Most times if something is configured twice, the later config will overwrite the earlier one(s). So if you are sure that you have configured it correctly, but it's not working as you believe it should, it's worth checking that the setting isn't being overwritten somewhere else in the config.

I'm happy to assist more with specifics but it's probably best if you can describe the issue or unexpected behaviour, and share what the config currently is (another reason why the commandline is often better, it's much easier to copy paste config snippets from files, that take screenshots, crop them and annotate them so they make sense...).

With what you've described so far though, to ensure redirection works, you most likely need to enable the rewrite module (and apply the change), like this:

a2enmod rewrite
systemctl restart apache2

If the redirection is being done (or meant to be being done) by an .htaccess file, then you'll need to make sure that your site file has the relevant setting. In this case the directive is AllowOverride. As noted in the docs, it needs to be within a <Directory> section. So look in the relevant site file (e.g. /etc/apache2/sites-available/new-site.conf) and ensure it's there in the right place. E.g. the snippet should look something like this:

<Directory /var/www/your-site>
    AllowOverride all

And to answer your questions re the trailing slash, that will depend on what is doing the redirect and how it is configured. As a general rule, I would argue that if it's configured correctly, it shouldn't matter whether there is a trailing slash or not. But without having some more specifics it's hard to know why it does in some circumstance but not others (e.g. redirects can even be done within PHP).

Add new comment