Chapter 12: Preventing and Fixing Problems Concept: Cache Prerequisite knowledge Concept: Drupal as a Content Management System What is the page cache? The software that runs your site, on each page request, must perform calculations and retrieve data from the database, in order to compose the page that is sent to the web browser or other application that is accessing the site. These calculations take time, which can mean that your page load time is longer than would be desirable. There are several ways that page load time can be sped up, including installing software on the server. The system includes the core Internal Page Cache and Dynamic Page Cache modules, which do not require any additional server software; they use a database cache mechanism to speed up your site. The way these modules work is that during page calculations, intermediate results and the final page output are stored in a special database area (known as the cache). Then the next time a compatible request is made, intermediate or final results, as appropriate, can be retrieved and used rather than redoing the entire calculation. In addition, when content or data that affects a particular calculation is updated, the affected cached data is removed from the cache, forcing that part of the calculation to be redone the next time it is needed. These caching modules normally work reasonably well, and offer at least some speed-up for most sites. However, sometimes the page cache can have problems, such as: Corrupted data in the cache, leading to garbled or incorrect page output Old data remaining in the cache too long, leading to outdated page output Insufficient caching, leading to slow page loads What other data is cached? Independent of whether the two page cache modules are installed on your site, the software that your site runs will still cache the output of many internal calculations. The core systems that cache data include: The theme system caches information in the database cache about which template files are used to render various types of data. If you are developing a new theme and add a new template file, you'll need to clear this cache to have your theme file recognized. CSS and JavaScript files can optionally be optimized and compressed (depending on your site settings). If so, the compressed versions are stored in the file system so that they don't have to be re-optimized too often. If you are developing a module or theme, you may need to either turn off or clear this file cache to have changes to CSS or JavaScript files be recognized. The system locates certain low-level PHP functions and classes, such as hook implementations and plugin classes, from your installed modules and stores information about which module has which functionality. If you are developing a new module or adding features to an existing module, you may need to clear this cache to have your new features be recognized. Related topics If you have problems with your site, the first thing to try to fix it is usually to clear the cache. See Clearing the Cache for more information. Additional resources Learn about additional caching and performance optimization methods in the Drupal.org community documentation page "Caching overview". Clearing the Cache Goal Clear or rebuild your site's internal caches to ensure they are up-to-date with the most recent data, using the user interface or Drush. Prerequisite knowledge Concept: Cache Concept: Additional Tools Site prerequisites If you want to use Drush to clear the cache, Drush must be installed. See Concept: Additional Tools. Steps You can use the administrative interface or Drush to clear the cache. You can also use the rebuild script or Drush to do a more complete cache rebuild. Using the administrative interface to clear the cache In the Manage administrative menu, navigate to Configuration > Development > Performance (admin/config/development/performance). If you cannot access this page in the administrative interface, use one of the other methods to clear or rebuild the cache. Click Clear all caches. A message saying the cache has been cleared appears at the top of the page. If this doesn't resolve the problem that caused you to want to clear the cache, try a rebuild instead. Using the rebuild script Open settings.php (/sites/default/settings.php) in any plain text editor. Add this line to the end of the file and save it: $settings['rebuild_access'] = TRUE; Visit http://www.example.com/core/rebuild.php in your browser (where www.example.com is your site's URL). After a short pause, you should be redirected to the home page of your site, and the cache should be rebuilt. Open settings.php (/sites/default/settings.php) in a text editor. Find the line you added with $settings['rebuild_access'], remove this line, and save the file. Using Drush to rebuild or clear the cache You can use one of two commands: Use the command drush cache:rebuild to clear and rebuild all cached data for a site. After running this command, you will see the output message "Cache rebuild complete." Use the command drush cache:clear to see a list of individual caches and then choose the specific cache you would like to clear. Running this command should produce output like the following: > drush cache:clear Enter a number to choose which cache to clear. [0] : Cancel [1] : drush [2] : theme-registry [3] : menu [4] : css-js [5] : block [6] : module-list [7] : theme-list [8] : render [9] : views Choose a cache to clear by entering the number associated with that cache. Press "Enter" to continue. To clear a specific cache type, you can specify it in the cache:clear command. For example to clear the render cache: drush cache:clear render Videos Clearing the Cache Additional resources Drupal.org community documentation page "Clearing or rebuilding Drupal's cache" Concept: Data Backups Prerequisite knowledge Concept: Drupal as a Content Management System Preparing to Install What is a site backup? If something happens to the computer (or computers) that your site and its database are running on, or if you lose access to this computer, you could lose some or all of your site's data. You could also lose data if your site is hacked, or if someone with administrative privileges on your site deletes or alters data mistakenly from the administrative interface. In order to prevent scenarios like this from being permanent, expensive data losses, it is important to make regular backups of your site's data, and to store them in a location that is separate from the computer where your site is running. The frequency with which you should make data backups, and how many backups you should keep, depends on how frequently your site is changing. If you have a very large amount of content on your site that is being added to or updated many times per day, you would want to make more frequent backups than you would for a site that changes rarely. Also consider that some time could pass between when a data problem occurs and when you notice that it is a problem, so storing a sequence of backups (so that you can go back to the last known good data and retrieve that), rather than overwriting a single backup repeatedly, is a good practice. Another consideration is that whatever format you store your backups in, it is a good idea to verify that you can actually retrieve lost data from your backups. You might want to test several possible data loss scenarios, and make sure that your data can be restored to the site in all cases. In order to make a complete backup of your site, you will need to make copies of the following: The data in the sites directory, including the sites/default/settings.php file. The data in your site's database. A few tables can be truncated, such as those storing the temporary data cache and user login session information, but it is always safe to back up the entire database. Uploaded files, such as images and other attachments. The location of these files is configurable; the standard location is the sites/default/files directory under your site root. In the Manage administrative menu, navigate to Configuration > Media > File system (admin/config/media/file-system) to check the file upload locations; to change them, you'll need to edit your settings.php file. Modules, themes and any other software files you have customized. You can find customized modules and themes in the modules and themes directories respectively. Some people prefer to back up all software files, including core files and contributed modules and themes (which you could recover by downloading them again from the source), rather than trying to pick out specific files that definitely need to be backed up. You can perform a test to confirm whether your backup has been done right by making a development copy of the site (see Making a Development Site). Related topics Updating the Core Software Making a Development Site Concept: Cache Additional resources Drupal.org community documentation page "Backing up a site" The contributed Backup and Migrate module, which can be used to set up automatic backups of the database and uploaded files. Concept: Log What is a Log? Your site captures system events in a log to be reviewed by an authorized individual at a later time. The log is a list of recorded events containing usage data, performance data, errors, warnings, and operational information. It is vital to check the log on a regular basis as it is often the only way to tell what is going on. You can find your site's recent log messages in the Manage administrative menu by navigating to Reports > Recent log messages (admin/reports/dblog). These logs may be cleared by administrators and automated cron tasks, so they should not be used for forensic logging. For forensic purposes, use the Syslog module. Concept: Status Report What is a Status Report? The status report is a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on Drupal.org's support forums and project issue queues or when asking for help on other channels. You can find the status report in the Manage administrative menu by navigating to Reports > Status report (admin/reports/status). Related topics Getting Support Additional resources If you have an error about trusted host settings in your status report, see Drupal.org community documentation page "Trusted Host settings".