lando / php

The Official Lando PHP plugin.
https://docs.lando.dev/php
GNU General Public License v3.0
16 stars 16 forks source link

Allow a .htaccess-lando to override .htaccess #38

Open web-assistant opened 4 years ago

web-assistant commented 4 years ago

I'm trying to override the .htaccess file as instructed in https://docs.lando.dev/config/apache.html#configuration. Adding .htaccess-lando next to the Drupal root .htaccess file doesn't do anything. I have tried rebuilding and also tried adding the custom httpd.conf file taken from https://github.com/lando/lando/tree/master/plugins/lando-services/services/apache. Any ideas how I can get this working?

screen

Running Lando v3.0.3 on Windows 10.

name: thingymajig
recipe: drupal7
config:
  php: '7.2'
  via: apache
  webroot: web
  database: mariadb
  drush: ^8
  xdebug: false
  config:
    php: .lando/.lando.php.ini
    database: .lando/.lando.mysql.cnf
    server: .lando/httpd.conf
    vhosts: .lando/default.conf

proxy:
  appserver:
    - thingymajig.lndo.site
    - www.thingymajig.lndo.site
  mailhog:
    - mail.thingymajig.lndo.site
  pma:
    - pma.thingymajig.lndo.site
  adminer:
    - adminer.thingymajig.lndo.site

services:
  database:
    creds:
      database: thingymajig
      user: thingymabob
      password: easylike123
  appserver:
    overrides:
      environment:
        # Support debugging Drush with XDEBUG.
        PHP_IDE_CONFIG: "serverName=appserver"
  mailhog:
    type: mailhog
    hogfrom:
      - appserver
    portforward: true
  pma:
    type: phpmyadmin
    hosts:
      - database
  adminer:
    type: compose
    services:
      image: dehy/adminer
      command: /bin/s6-svscan /etc/services.d
    portforward: true

tooling:
  xon:
    service: appserver
    description: Enable xdebug for apache.
    cmd: "docker-php-ext-enable xdebug && /etc/init.d/apache2 reload"
    user: root
  xoff:
    service: appserver
    description: Disable xdebug for apache.
    cmd: "rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && /etc/init.d/apache2 reload"
    user: root

excludes:
  - .idea
  - .git
rabauss commented 4 years ago

How does your httpd.conf look like? I guess, it should contain the following line like in the example: https://github.com/lando/lando/blob/3802a60012fa1938ff3cf2f647c4ad7e1baf72a1/examples/apache/config/httpd.conf#L455

EDIT: I see you took them from the services. Could be a bug in the config - but I've never use that feature before.

web-assistant commented 4 years ago

@rabauss I changed the httpd.conf to the one in the link you provided but still get the same issue. The docs say that the override should work with the httpd.conf shipped with Lando, though if I have the .htaccess-lando file with no custom httpd.conf it still doesn't work. I'm rebuilding Lando each time.

hanoii commented 4 years ago

Yes, this is not working for me either. Looking at the /etc/apache2/apache2.conf inside the container it doesn't have .htaccess-lando on it

anacolautti commented 4 years ago

Hi everyone! While the experts figure this out (I wish I could help, but actually I know very little of about the subject) I have a temporal fix for anyone who might need this right away. I was inspired by the issue that enabled this feature to begin with, I tried actually applying their code and it didn't work for me.

This variation of their code did, though:

if [ -e /etc/apache2/apache2.conf ]; then
    if ! grep -e 'AccessFileName .htaccess-lando .htaccess' /etc/apache2/apache2.conf >/dev/null; then
        # force apache to use the .htaccess-lando file
        eval "sed -i 's/AccessFileName .htaccess/AccessFileName .htaccess-lando/g' /etc/apache2/apache2.conf"
    fi
fi

I'm replacing the line in my Apache service that calls my client's .htaccess and calling the file .htaccess-lando instead. I know this is just temporary, until someone fixes this for real, but in took me a few hours to get this working and I thought I could spare them for someone else.

Just remember to add this code to a script, and call it from your .lando.yml file at the services key like this:

[...]
services:
  myservice:
    build_as_root:
      cmd: /path/temporal_apache_patch.sh
[...]

Keep being awesome!

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions and please check out this if you are wondering why we auto close issues.

f-liva commented 3 years ago

When will this hotfix be implemented natively?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions and please check out this if you are wondering why we auto close issues.

reynoldsalec commented 2 years ago

...and this is still totally an issue. Taking a look at this after some folks mentioned it on Slack.

reynoldsalec commented 2 years ago

Ok, so in some ways the "root issue" here is one of documentation.

The Lando Apache service accepts a .htaccess-lando file just fine, but virtually no one uses the standalone Lando Apache service. Typically Lando users are using a WordPress/Drupal recipe that leverages Lando's PHP service, and that service actually uses different Dockerfiles to generate the Apache server, which do not make the changes to httpd.conf necessary to read the .htaccess-lando file.

That said, I think we've had enough consistent interest/confusion in this feature that it should be added to the PHP service.

I'm moving this ticket to the lando/php project, steps for implementation are to...

  1. Create custom httpd.conf with the line AccessFileName .htaccess-lando .htaccess
  2. Make sure that custom config file is copied to the correct location via the Dockerfile (probably /etc/apache2/apache2.conf)
  3. Add tests to the PHP service, similar to the ones on the Apache service testing the custom .htaccess file
reynoldsalec commented 2 years ago

...also noting that when we re-do the PHP service, we should have it consume the Lando Apache service.

yorkshire-pudding commented 2 years ago

Thanks @anacolautti for documenting the workaround. It works a treat.