It appears that it is not currently possible to install the latest Magento Community Edition within a subdirectory (or there are steps required, which are not in the Documentation that I can find?) with a fresh install.
I have tested this 3-4 times in the last 2 days. If you install it into the root it works as anticipated, if you install it in a subdirectory – the install says it has worked but the index.php is missing and the .htaccess file is still the default one that comes with the composer project setup.
This works for root folder:
--base-url="http://www.fieldhockey.co"
This does not work for the subdirectory:
base-url="http://www.fieldhockey.co/store"
All the other setup:install parameters are the same in both attempts.
I found little about this issue so that is why I have created this – perhaps someone can try this out on a different setup than mine:
Cent OS 7.9 (v92.0.10)
PHP 7.3.27
Apache 2.4.46
My Question(s)
So my questions on the back of this issue – how do I then move the installation to a subdirectory? And is it correct that there is no index.php – even when the install works in the root and the site displays?
Updating the base_url in the database to include it and moving all files into that directory and then clearing the cache & reindexing does not work?
Just out of curiosity – I took the default index.php script and .htaccess from a site I setup on 2.4.1 back in November… and now my store works in the subdirectory after moving the files from the root directory (but the admin cannot load any CSS etc or 2FA so I cannot login).
UPDATE – 19/02/2021 – 13:24pm (GMT)
I think the issue is the install itself not the subdirectory – to test this theory I will install 2.4.1 and see if I get better results.
UPDATE – 19/02/2021 – 15:10pm (GMT)
2.4.1 successfully installed in root, both front end and backend are working. I will now attempt to move the site into the store directory manually. If that fails I will attempt to install it to the subdirectory directly.
UPDATE – 19/02/2021 – 15:52pm (GMT)
Moving worked thou came across an issue I hadn’t seen mentioned before regarding the JS/CSS breaking when relocating to a new directory. There is a .htaccess file in the /pub/static/ directory which doesn’t seem to be created when a new static folder is generated – so you probably shouldn’t rename the /pub/static/ directory to force it to be regenerated.Magento 2.4.1 – Moved site to a subdirectory – CSS & JS Broken – cleared Cache still broken [SOLVED]
SO ANYONE ANY IDEAS?
At this stage I cannot understand why 2.4.1 is working but 2.4.2 isn’t – I cannot see any mention in the release notes pertaining to a non optional module or version of anything significant (PHP, Apache, ElasticSearch, Composer etc)
I can keep it on 2.4.1 but it isn’t really the point, I should be able to use 2.4.2 is I want to and have the means to do so?
I hope this helps anyone else trying to do this, I will work with 2.4.1 for a few weeks and then try to upgrade again.
3
Answers
In 2.4.2, Magento moved the index.php to the /pub/ folder for security purposes.
I’m trying like you to create a subdirectory : example.com/nl
I moved my "nl" folder in /pub/ and changed the require from
to
In admin, urls for secure and non-secure :
Sadly when I go to https://example.com/nl/ the site display a 404 even though it displays the correct theme design, the correct translations etc…
Tomorrow I’ll try again and keep you updated if I succeed.
Maybe this already give you a hint though…
I managed to make it work, a bit hacky though.
I’ll take my example, I want to do : example.com/nl.
I created a folder "nl" in the root folder. I added a .htaccess in it with the content :
Then I created a "nl" folder in the "pub" folder.
This folder contains 2 files : .htaccess, index.php.
.htaccess is a copy/paste of the "pub" one, I just added :
It’s not mandatory you can do set your store via the index.php, it’s explained in it by Magento.
index.php is a copy/paste of the "pub" one.
I just added another "../" in the require.
In admin :
My vhost point to the root:
ServerName example.com
ServerAlias example.com
My main issue there was that the site was accessible but Magento had trouble to rewrite and every page was in 404. Here comes the hack.
In the "pub/index.php" file I added the following line before Magento instantiates everything:
Looks like it works fine but I didn’t push the tests further.
After Installed magento 2.4 version your localhost support with /pub directory like
{localhostname}/pub/index.php
We can access without pub directory follow below steps
1. Copy .httaccess file from pub folder and override it to root .htaccess file
2. Upload pub/index.php file to root magento directory
3. Add below code in app/etc/env.php file