davidalger / capistrano-magento2

Magento 2 specific tasks for Capistrano 3
https://rubygems.org/gems/capistrano-magento2
Open Software License 3.0
228 stars 75 forks source link

Customize .htaccess in pub folder #130

Closed RaFr closed 5 years ago

RaFr commented 5 years ago

Is there a solution to customize the .htaccess file in pub folder on production and staging server? It seems that this file is always downloaded from magento repository, if i edit the file on the development server, the modifications don't reach the staging and production server.

giacmir commented 5 years ago

Hi @RaFr, the best way to accomplish this, in my opinion, is to use a patching mechanism (like magento/ece-tools or cweagans/composer-patches). Otherwise you can add your modified file somewhere in you repo and add a capistrano task attached to the updated hook.

RaFr commented 5 years ago

Hi @giacmir, thank you for your answer. Could you give some details on how can i " add a capistrano task attached to the updated hook " please? or a link to an example? i while ago i tried to create a second htaccess file with a different name in the pub folder, and i added a task to the file deploy.rf to rename the file to .htaccess on the production server when deploy:finished, but it didn't work. i don't know if i did it wrong or it simply can't be done that way. i rename the file manually now for each release, but it is more secure if it can be done in the script. thanks

davidalger commented 5 years ago

@RaFr This is typically caused by composer install marshaling the files from magento/magento2-base into place when the package is unwrapped into the release directory; not really an issue with Capistrano or this gem per-se.

I generally resolve the need to commit files Magento base module copies outside the vendor by adding it to the extras section in my composer.json file. For example on a project I'm currently working on we have the following (I'm not sure the magento-force is needed for override or not, but include it here for completeness of my working example):

    "extra": {
        "magento-force": "override",
        "magento-deploy-ignore" : {
            "magento/magento2-base": [
                "/dev/tools/grunt/configs/themes.js"
            ]
        },

See this for details: https://github.com/magento/magento-composer-installer/blob/master/doc/Deploy.md#prevent-single-files-from-deploy

Alternatively, the changes could be applied during the composer install using the cweagans/composer-patches package

RaFr commented 4 years ago

@davidalger thank you for the suggested solutions