Changing Magento Directory root for Apache2

Deep Kamal Singh
Nov 2 · 2 min read
Magento 2.3.3 Welcome Screen

Recently I installed Magento2.3.3 on my Mac Catalina over Apache2 with PHP7.2,

I downloaded the self contained package from Magento website , and successfully installed it under <Site_Root>/magento , it was working all fine for me, but you see I have AEM 6.5 also running on my dev machine and (Commerce integration framework implemented with Magento integration) it needs a proxy pass to Magento server on ‘/magento’ path — thus my current installation of Magento on ‘/magento’ base path will actually force me to break this linking,

So the straightforward and simple way out was to simply rename the directory ‘magento2’ to ‘m233’ , which I did — but my new magento installation was not accessible as the base path is etched in Magento’s configuration in DB , cache and in symlinks , which i learned the hard way,

to rename base path or base directory of Magento follow these steps

login to your mysql:

mysql -u root -p

use your magento DB , and run this command to know config_id of base_url configurations:

select * from core_config_data where path like ‘%base_url%’

that gave me two rows one with path web/unsecure/base_url and another with web/secure/base_url , I updated table with command

update core_config_data set `value`=’http://dks.magento/m233/' where config_id=4 

here I changed `value` from ’http://dks.magento/magento/' to ’http://dks.magento/m233/' and similarity the with config_id=5, I changed it to ’https://dks.magento/m233/'

I cleaned the cache & session

rm -rf <magento_directory>/var/cache/*
rm -rf <magento_directory>/var/session/*

and restarted Apache2, I was now able to access Magento site and Admin on new URL — /m233 instead of /magento

but I was not able to see site logo loading up, further when checked on inspector/console i found several CSS, JS and Image resources were coming 403 or 404, now this was confusing — I looked deeper and found out Magento was referring to those files inside

<Magento Root>/pub/static/frontend/Magento/luma/en_US

I simply did a directory listing and found out all files were indeed there, yet it was 403'ing me for those, so I soaked in my ignorance further tried to play around with changing permissions of those files — which resulted in no change, I tried several other random unnecessary steps like rebooting APache, deleting browser cache, deleting Magento cache several times and many other I rather not share \(. .)/

Finally I paid attention to little detail that those pub/static files were actually symlinks, which were still linked to old location <Apache Site Root>/magento/ instead of being linked to <Apache Site root>/m233

Thus I then ran

bin/magento setup:upgrade
bin/magento cache:clean config
bin/magento indexer:reindex

and that did the trick :) ,

so TL;DR;

to change/rename base directory of Magento 2

Rename/Move directory
Make changes in DB - core_config_data
Then MUST run bin/magento setup:upgrade
Clear cache, clear session, Re-Index

Thanks for reading.

Question and comments welcome

Twitter : @dks__ ,

Mail: deepkamal.singh@adobe.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade