TL;DR Filepaths contain old subdomain prefix after find replace database and site code, can't determine cause.
I have a hosted site on mywebsite.com/drupal
, I want to move it to my computer localhost
.
I have a LAMP stack and I compress and download the contents of mywebsite.com/drupal
and export its mysql database, mydb.sql
, using phpmyadmin.
I uncompress and place all the files from mywebsite.com/drupal
in /var/www/html/
, I create a new database, local.db
, locally and import mydb.sql
. I edit /var/www/html/sites/default/settings.php
$databases array and connect it to local.db
.
I ensure all files permissions are correct by running
chown user:user -R /var/www/html/
chmod -R 755 /var/www/html/
I can then access my site using a browser and going to localhost, however the images are missing none of the links work.
Initially I thought the cause was that there are many instances in the database and my site code still containing filepaths with the subdomain /drupal/
prefix, images for example:
src="/drupal/sites/default/files/inline-images..."
When I move the site to localhost
, it should just be:
src="/sites/default/files/inline-images..."
To solve this, I did a find /drupal/
and replace /
in my database, reimported it and then used grep -rl '/drupal/' ./ | xargs sed -i 's_/drupal/_/_g'
on /var/www/html/
.
I thought this would have resolved the problem, however when I access localhost
, the problem persists, images and links still contain the /drupal/
prefix in their filepaths. I've read on a few migration guides that I should flush all caches on the drupal backend before moving (which I did) and also potentially flush the mysql cache using phpmyadmin, however I get an error #1146 - Table 'mydb.cache' doesn't exist
when I try to execute the truncate commands.
Other guides mention .htaccess
, which I copied over from mysite.com/drupal
, admittedly I don't understand everything inside it deeply, but I can't find any code which is prefixing filepaths with /drupal/
.
As a sanity check, I created /var/www/html/drupal/
and copied my site and then everything works fine.
I don't understand, how can the filepaths remain the same when I have changed all instances in the database and site code? I think there is something easy I'm missing but I can't figure it out.