Magento Server Troubleshooting: Diagnose and Fix Common Issues

Magento Server Troubleshooting: Diagnose and Fix Common Issues. Running a successful online store powered by Magento (Adobe Commerce) is incredibly rewarding, but comes with challenges. One of the most crucial aspects of maintaining a Magento-based e-commerce platform is operates smoothly and efficiently. However, like any complex system, Magento servers  experience a range of issues that may disrupt the shopping experience for your customers or impede your administrative tasks. This is where Magento Server Troubleshooting becomes an essential skill.

 In this guide, we teach you how to diagnose and resolve common server issues that affect your Magento 2 store.

Common Magento Server Issues and Their Fixes

In this section, we go over some common Magento server issues and provide practical solutions to keep your online store running seamlessly. Let’s dive in. 

1. Magento is Running Slow

Is your Magento-powered e-commerce store starting to feel a bit sluggish? Unfortunately, slow speeds lead to higher bounce rates, lower conversion rates, and poor user experience. In this section, we go the issues and fixes:

Update to the Latest Version of Magento

Check if you’re running the latest version of Magento. If not, run a quick update and see if the slow speed issue resolves. Newer versions of Magento come with enhancements that improve performance significantly.

Check Third-Party Extensions

While third-party extensions are a lifesaver, they’re a double-edged sword. Some extensions are poorly optimized, and their code might not align with Magento’s best practices. Others may conflict with each other, causing instability and slowdowns. If you suspect an extension could be slowing down your site, disable all your extensions one by one and measure the impact on your speed. 

Minify JavaScript and CSS

Minifying the CSS and JS files refers to the process of removing unnecessary characters and formatting from your code. In essence, this process gets rid of whitespace and comments. It also shortens variable names without altering the code’s functionality. After minifying, the files become smaller and load faster, making your site more responsive.

Enable Varnish Cache

Varnish Cache is a powerful open-source caching solution to significantly enhance the performance of your Magento store by caching HTTP requests and responses. It acts as an intermediary between the client (typically a web browser) and the backend server (like your Magento server). When a user requests a page, Varnish Cache stores a copy of the response. If another user requests the same page, Varnish serves the cached response directly, avoiding the need to re-fetch the content from the backend server.

Upgrade Your Hosting

If your hosting is at fault, then it may be because of two issues – inadequate resources or the server is located too far from your users.  Make sure your hosting plan has the recommended CPU, RAM, and disk space to handle Magento’s demands. Also, pick a server located closer to your users. 

Optimize Front-End Content

Next, go for a well-optimized, lightweight theme that is designed for performance to speed things up. Also, compress and optimize images to reduce their file sizes without sacrificing quality. This significantly improves page load times. For this, use Magento’s built-in compression tools.

Use a (Content Delivery Network) CDN

By implementing a CDN, you  leverage its infrastructure to distribute content efficiently, reduce latency, enhance website speed, and ultimately provide a better user experience for your Magento store visitors.

To diagnose slow speeds, use tools like Google PageSpeed Insights, GTmetrix, Pingdom, or WebPageTest to measure the load times. Also, pay attention to user feedback, especially regarding slow load times. 

2. Magento Upgrade Issues

Next point of Magento Server Troubleshooting: Diagnose and Fix Common Issues is an upgrade. Upgrading Magento is hit and miss with errors occurring during the process for a variety of reasons. Here are some of the errors you might encounter and their fixes: 

Composer Error

Magento’s Composer can generate an error during an upgrade for a variety of reasons. These include timeout issues, exceeding the memory limit, authentication errors, or having the wrong version of the composer. 

To fix Composer-related issues, download the latest version of Composer and upload it to your Root Folder. Also, ensure that your Composer authentication credentials are correct and up to date. 

PHP Error

PHP related errors during a Magento upgrade can occur for various reasons, including an incompatible PHP version, misconfigured PHP settings, or exceeding the PHP memory limit. To sort this out, update PHP to the latest version. For example, if you’re running Magento 2.4.6, you need to install PHP version 8.1 and above.

JSON File Error

One of the errors you might encounter is caused by the .json file. Usually, you see the message – “Your requirement could not be resolved to an installable set of packages.” Resolve this issue by removing the lines in the JSON file that are causing the error

Front-End Error

Sometimes, you are unable to open your admin page after upgrading Magento. You see a “page not working” or “404 page not found” error. This error should disappear after updating PHP.

3. 503 Error (Service Temporarily Unavailable)

A Magento 503 error typically indicates that your Magento store is temporarily unavailable, often due to server-related issues. This error is an HTTP status code, and it’s typically displayed to users when the server cannot handle their request at the moment. When it happens, it’s usually because the server is not responding, is overloaded, or is incorrectly configured. Here’s how to fix it:

  1. Using Filemanager or FTP, navigate to the Magento root directory.
  2. Locate the maintenance.flag file and delete it. It should be in the Var folder. 
  3. Finally, clear the Magento cache by running the following command: 
				
					php bin/magento cache:flush
				
			

4. The 503 error should clear this point. However, you may encounter the “Please Upgrade your database” error. Run the following command from Magento’s root directory: 

				
					php bin/magento setup:upgrade
				
			

4. CSS and JS Not Loading

CSS and JS not loading
CSS and JavaScript dictate the visual and interactive aspects of your e-commerce site. When they have issues, you end up with an unattractive website that frustrates visitors and jeopardizes your business. Fix this issue in the following two ways:

Using Composer

  1. Access the command prompt on your server.
  2. Use the cd command to enter the root directory of your Magento 2 installation.
				
					cd /path/to/your/magento/root
				
			

3. Verify that Composer is installed on your server by running the following command:

				
					composer --version
				
			

If Composer is not installed, you can follow the official Composer installation instructions to set it up.

4. Use the following command to deploy Magento’s static content, including CSS and JavaScript files:

				
					bin/magento setup:static-content:deploy
				
			

5. Clear the Magento cache to ensure that the updated static files are loaded correctly:

				
					bin/magento cache:flush
				
			

To apply the changes and restart your Magento server.

Editing XML Files

  1. Open a terminal or SSH client to access your server’s command line.
  2. Navigate to your Magento root directory.
				
					cd /path/to/your/magento/root
				
			

3. Remove all cached files and sessions located in the var directory. 

				
					rm -rf var/cache/*
rm -rf var/page_cache/*
rm -rf var/session/*
				
			

4. Next, you need to edit the di.xml file, which controls how Magento handles static files. Use a text editor. 

5. Inside the di.xml file, search for the <virtualType name=”developerMaterialization”> section.

6. Look for <item name=”view_preprocessed” xsi:type=”object”>.

7. Change Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink to Magento\Framework\App\View\Asset\MaterializationStrategy\Copy.

8. Delete the old files located in ROOT > pub > static. Be cautious not to delete the .htaccess file.

5. Magento SSL Not Working

If SSL is not working on your Magento server, it might be because it’s not activated or there’s an issue with the database. Here’s how to fix this issue: 

Activate SSL

  1. In the Magento admin panel, go to Stores > Configuration.
  2. Navigate to the General Menu and click on Web to open the settings page. 
  3. Under Settings, click on the Base URLs (Secure) tab. 
  4. Change http:// to https:// in the Secure Base URL fields. Do this for both the frontend and Admin
  5. Click on Save Config to complete the process. 

Resolve Database Issue

  1. Under the core_config_data table run the database query below: 
				
					Select * from core_config_data wherepath = '%web/secure/base_url%';
				
			

2. Search the value column for HTTPS. If you see it, then SSL is properly set up and should work. If it still doesn’t work, then there might be a problem with Ajax call setup. Use the code below to fix it. 

				
					echo Mage::getUrl('MYMODULE/MYCONTROLLER/MYACTION', array('_secure' =&gt; Mage::app()-&gt;getStore()-&gt;isCurrentlySecure()));
				
			

6. Cron Job Failures

Cron jobs are scheduled tasks that are used for various purposes within Magento. These tasks include important operations like reindexing data (which is crucial for performance) and updating currency exchange rates (which is important for international e-commerce).

Unfortunately, Cron jobs fail for various reasons, including misconfigurations, errors in the code being executed, scheduling problems, and server-related issues. Fix these issues by reviewing and verifying your server’s cron configuration. Ensure the cron service is running, the crontab entries are correctly configured, and the environment is set up to run PHP commands as needed for Magento cron tasks.

To keep this issue from recurring, regularly monitor the execution of cron jobs on your server. Check logs and reports or use third-party extensions designed for cron job management. 

7. Allowed Memory exhausted

The error message “allowed memory size of bytes exhausted” signals that Magento tried to consume more RAM resources than is allocated. The memory limit is specified in the php.ini file through the memory_limit directive. Solve this issue in three ways: 

Adjust php.ini Configuration

In your server’s php.ini file, modify certain values to allocate more memory for PHP scripts. Here are the recommended changes:

  • max_execution_time=18000: Extend the maximum execution time for PHP scripts.
  • max_input_time=1800: Increase the maximum input time for PHP scripts.
  • memory_limit=4G: Raise the memory limit to 4 gigabytes ( adjust this value based on your server’s capabilities).

After making these changes, don’t forget to restart your web server to apply the new settings.

Increase Memory Limit for Specific Magento Commands

If you’re encountering memory issues during specific Magento commands like compilation or static content deployment, set a higher memory limit directly for those commands. Here’s how:

For Compilation command:

				
					php -dmemory_limit=4G bin/magento setup:di:compile
				
			

For Deployment:

				
					php -dmemory_limit=4G bin/magento setup:static-content:deploy
				
			

Adjust the memory limit value as needed. Using “4G” in the examples above allocates 4 gigabytes of memory, but increase it further if necessary.

Run Magento Commands Without Memory Limits

Another effective way to address the memory issue is to run Magento commands without memory limits. Achieve this by using the following command format:

				
					php -dmemory_limit=-1 bin/magento ...
				
			

Here are some examples when running upgrade or compilation commands:

				
					php -dmemory_limit=-1 bin/magento setup:upgrade
php -dmemory_limit=-1 bin/magento setup:di:compile
				
			

The “-1” value for memory_limit means no memory limit is set, allowing PHP to use all available memory during script execution.

Diagnosing Magento Server Issues

To diagnose server errors in Magento effectively, do the following:

  1. Check for error messages within Magento, both in the frontend and backend.
  2. Review Magento logs, including the exception log and system log. 
  3. Check the PHP error log for PHP-related issues.
  4. Consider enabling developer mode in Magento for more detailed error messages.
  5. Monitor server resource usage, such as CPU, memory, and disk space.
  6. Ensure that server configurations for PHP, web server, and database are correct.
  7. Examine the .htaccess file for any custom rules or misconfigurations.
  8. Test third-party extensions and custom code for conflicts or errors.
  9. Check server logs and consider contacting hosting support.
  10. Seek help from the Magento community.

This is it. Thank you for reading Magento Server Troubleshooting: Diagnose and Fix Common Issues. We finalise now. Thank you for your time.

Magento Server Troubleshooting: Diagnose and Fix Common Issues Conclusion

Diagnosing and fixing server errors in Magento is an essential skill for any e-commerce website owner or administrator. While these errors are frustrating, they are not insurmountable challenges. By following our guide, you effectively identify, troubleshoot, and resolve server-related issues in your Magento store.

Avatar for Richard Kanyoro
Richard Kanyoro

The world’s biggest problems can be solved by progressively solving the little ones. I write to help people solve the “little” tech problems they face.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x