Creating Copy of Contao-Based Website
by Thomas Urban
Contao 4.x was built with Symfony Framework and due to using some additional code caching duplicating a site takes a little more than it did with previous versions.
Copy Data
First you need to copy all files of existing website into new folder. This is as simple as it sounds.
cp -pR my-website copy-of-website
Next the database must be copied, too.
mysqldump -u oldDbUser -p oldDbName >my-dump.sql
mysql -u newDbUser -p newDbName <my-dump.sql
This, of course, requires having set up a new database with its separate user and a different password.
Adjust the file copy-of-website/app/config/parameters.yml and set the new database configuration. In addition you need to change the value of secret to a different value.
Refresh Cache
Here comes the extra step required due to code caching. Log in to the server via SSH or open a console by any other means. Make sure you are the user as is used by webserver or PHP engine for accessing files later. Then run these commands:
cd copy-of-website
vendor/bin/contao-console cache:clear
vendor/bin/contao-console cache:warmup
This will remove the code cache of original website and replace it with a new version. Without this the new website keeps modifying the database of original one due to not actually checking parameters.yml file on every request but using some derived code from cache.
Troubleshooting
If you get blank screens or any errors after refreshing cache you most probably missed to run those commands as user of webserver or PHP engine. You might need to fix the ownership with a command similar to this one:
cd copy-of-website
chown www-data:www-data -R var/cache/prod