Hello,
I have a drupal 10.0.9 site running in a virtual machine under Ubuntu 22.04 to explore drupal.
Recently the “Status report” suggested that I had to upgrade to drupal 10.1.0.
Looking into the 10.1.0 Release notes it suggested that upgrading was as simple as running the following commands:
$ cd To_Document_Root
$ sudo -u www-data composer update "drupal/core-*" --with-all-dependenciesUnfortunately the composer command generated an error that it couldn’t delete the “/var/www/drupal/sites/default/default.services.yml” file and when I went to my drupal site the graphical interface was replaced by a bunch of links.
I reinstalled the drupal 10.0.9 site from backup and started to experiment.
Here is the log describing the upgrade process that resulted in a working drupal 10.1.0 site. <!--break-->
- Login to the drupal site as a user with "Administer software updates" permission.
- Put the site into maintenance mode.
Important: Don’t logout because drupal prevents you to login after the execution of the composer command. - Backup files and database
$ cd /var/www $ sudo cp -rp /var/www/drupal drupal_backup - Temporary change the “/var/www/drupal/sites/default/” permissions.
$ cd /var/www/drupal/sites/ $ sudo -u www-data chmod 755 default - Use composer to update your site and all dependencies to the latest version of Drupal:
$ cd /var/www/drupal $ sudo -u www-data composer update "drupal/core-*" --with-all-dependencies - Reset the “/var/www/drupal/sites/default/” permissions.
$ cd /var/www/drupal/sites/ $ sudo -u www-data chmod 555 default - Mix in your customizations.
$ tkdiff /var/www/drupal/.htaccess /var/www/drupal_backup/.htaccess $ tkdiff /var/www/drupal/composer.json /var/www/drupal_backup/composer.json $ tkdiff /var/www/drupal/robots.txt /var/www/drupal_backup/robots.txt $ tkdiff /var/www/drupal/sites/default/default.settings.php /var/www/drupal_backup/sites/default/default.settings.php $ tkdiff /var/www/drupal/sites/default/settings.php /var/www/drupal_backup/sites/default/settings.php $ tkdiff /var/www/drupal/sites/default/settings.php /var/www/drupal/sites/default/default.settings.php - Using the browser and the still logged in user with "Administer software updates" permission, run update.php by visiting:
https://localhost.localdomain/update.phpThis will update the core database tables.
- The graphical interface is gone! - Click the "Continue" link. - Click the "Apply pending updates" link. - The graphical interface is restored! - Click the "Administration pages" link. - Goto Reports : Status report - Run the Cron - No errors should be displayed! -
Verify that everything is working as expected.
-
Switch off Maintenance mode.
Question: Is this a valid upgrade method or is there a more easy one?
Regards,
Albert
Comments
There is a easier and better way
Your original error:
was due to permissions. I notice that you're using sudo to run composer as the webserver (
www-data) , and this file was for some reason not owned by webserver, so composer was unable to replace it.I understand that the decision to use sudo comes from here: https://www.drupal.org/forum/support/installing-drupal/2023-01-04/using-... I'll take a look at that and try to understand your requirements. IMHO, sudo is probably not the right solution for this, but I need to better understand the use case.
IMHO, running composer as the web server is not a good idea. This makes anything in your code base downloaded by composer owned by the webserver, which creates a very large attack surface area. If some threat agent manages to compromise the webserver, they can do whatever they want, including altering or replacing your entire code base. Drupal's security philosophy is very much defence in depth, so even if your web server is compromised, your site's code base should still be protected.
If you're the single person managing the code base, make sure the code base is owned by you, and run composer as yourself in order to update it. Apart from the public and private file system, the web server should not have more than read access to files, while you yourself have full access (e.g.: 744).
When you've set up file permissions correctly, you shall be able to update the core with this:
The last two lines uses drush to first run the database update script, and then rebuild all caches.
If there is a team of people managing the code base, a slightly more complex setup is required, involving the group bit, but it sounds like you're the sole maintainer of the code base, so I'll leave it at that.
- gisle
Thoughts about easier and better way
Hello Gisle
The parent directory seems to be the problem:
The 555 protection, which seems to be needed by drupal, prevents composer from moving, removing the file /var/www/drupal/sites/default/default.services.yml and creating another file in the default directory.
If the website is owned by www-data, how can composer update it, when not executed by user www-data?
I probably have to create a new user, which manage the code base, and give other people which also need to manage the code base, access to tha t user.
Are you suggesting that I have to move the drupal directory somewhere in my home directory, make myself owner of it and change the protection of all the items under the drupal directory to 755 allowing www-data to access it via the world bit (5) and giving me full access.
Won't using the 744 protection, you suggested, produce problems on directories?
To make it work I probably have to create a symbolic link from /var/www/drupal/ pointing to the drupal directory in my home directory.
Is this corrector or is there a better solution?
Regards,
Albert
I always learned that a
AFAIK, this has never been the case. I am in charge of more than 100 websites under Apache2 (Drupal, Wordpress, Grav). None of these are owned by the user
www-data. There has never been a problem updating these, using standard best practices. What is the source of what you've "always learned"?This setting is not required by Drupal. On a Unix and Gnu/Linux system, directories need to be treated different that ordinary files. To be processed correctly by composer, directories need 755, and composer must be used without sudo.
It can't (well it can, but how to do it introduces so bad practices that I won't tell you how to). That's why it is a very bad idea to have the website owned by www-data.
No. I suggest you leave it where it is, but owned by you, and that when updating, you run composer without sudo.
I didn't address directories, only files. For directories, use 755.
Don't move the drupal directory to your home directory. Only fix the permissions.
Edit: Permission for directories should be 755.
- gisle
Learned a lot from this thread
Hello Gisle,
I learned a lot from this thread, seems google isn't always write.
I'll put your advice to the test on my local test site and let you know the results.
Many thanks.
Regards,
Albert