Troubleshooting Magento 1.9 Setup on Docker and Docker Compose
If you’re facing a 500 error while setting up your Magento 1.9 application on Docker using Docker Compose, don’t worryâyou’re not alone! Let’s troubleshoot this issue step by step.
Check Your Environment Variables
Your docker-compose.yml file looks clean, but I noticed an issue with the environment variables for MySQL. Currently, you have:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=magento
- MYSQL_USER=root
- MYSQL_PASSWORD=root
By default, Magento expects a user named Magento or magento, not root. Also, it’s a good practice to use different passwords for the root user and the application database user. Change your environment variables like this:
- MYSQL_ROOT_PASSWORD=strong_root_password
- MYSQL_DATABASE=magento_db
- MYSQL_USER=magento_user
- MYSQL_PASSWORD=strengthy_magento_password
Update Your Dockerfile
Your Dockerfile is well-structured, but I recommend adding a few more dependencies to ensure Magento runs smoothly. Update your file as follows:
FROM php:7.1-apache
COPY .:/var/www/html/
RUN apt-get update && apt-get upgrade -y
# Install required PHP extensions
RUN docker-php-ext-install mysqli pdo_mysql zip
# Install Node.js and Yarn (for Magento static content deployment)
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash \
&& apt-get install nodejs yarn -y
EXPOSE 80
I added the pdo_mysql extension, which is required for MySQL database operations in Magento. I also removed the apt-transport-https, curl, and nodejs installation commands as they are not necessary anymore.
Update Your Mage_is_developer_mode Environment Variable
In your docker-compose.yml file, change:
- MAGE_IS_DEVELOPER_MODE=true
to:
- MAGE_IS_DEVELOPER_MODE=1
This will enable Magento’s developer mode. In this mode, you’ll get more detailed error messages, which should help you diagnose the issue.
Verify Your Apache Configuration
Although not specified in your question, ensure that your Apache configuration is correct and compatible with Magento 1.9. You can find the official Magento documentation on Apache configuration here.
If you still face issues after implementing these changes, check your application logs located at /var/www/html/var/log/ inside your container.
Conclusion
In most cases, ensuring the correct MySQL configuration and enabling Magento’s developer mode should help you resolve the 500 error. If you’re still facing difficulties, please share more details about the environment and any relevant log messages for further investigation.
I recommend keeping your Magento installation up-to-date with the latest security patches and using a supported version whenever possible. For more information on Magento development best practices, check out our blog post Optimizing Magento Performance with Docker at Laravel Company.
Happy coding!