Catching and fixing “Internal Server Error” – apache2


One of the most popular and not always logged apache2 error is “Internal Server Error”. In this article I will analyze the possible causes and solutions from the Internet and personal experience. Sometimes this error is not quite obvious.

All situations are described for the Ubuntu Linux 22.10 operating system.

Well, of course, the first thing you should do is try restarting the service.

sudo systemctl restart apache2

If that doesn’t help, then move on.

1. Configuration

1.1. Web Application Configuration Error

First of all, I recommend making a request to your site locally, directly from the server.

curl localhost:80

If you do not see “Internal Server Error”, but see the html page, then 99% of the problem is in the configuration files and access settings.

Check file: /etc/apache2/sites-available/your_app.conf
where your_app.conf is the name of your configuration file, or the standard conf file is “000-default.conf”

What does he look like:

/etc/apache2/sites-available/your_app.conf

/etc/apache2/sites-available/your_app.conf

The line “Require ip 127.0.0.1” says that only connections from the local host are allowed.

Solution: replace the line “Require ip 127.0.0.1” with “Require all granted”
Also “Require all granted” should be in /etc/apache2/apache2.conf

/etc/apache2/apache2.conf

/etc/apache2/apache2.conf

1.2. Old config file

It may not have been selected or enabled when creating a new web application configuration file.

Solution:
1. Turn off the standard configuration file
2. Turn on your
3. Restart apache2

a2dissite 000-default.conf 
a2ensite your_app.conf 
systemctl restart apache2 

2. Permissions

The problem occurs when the permissions of your project files do not match what you expect.

2.1. File owner

Your project files are not owned by the www-data user.

Project folder (your_project) is not owned by user www-data

Project folder (your_project) is not owned by user www-data

Solution:

sudo chown -R www-data:www-data your_project/

PS It happens that apache2 does not create the www-data user during installation, there is nothing wrong with that, you can do without creating it. The rights function perfectly and the site works.

2.2. File permissions

The error can also occur when the owner is set correctly, but still does not have access to files due to permission settings.

Solution:

sudo chmod -R 755 your_project/

2.3. Web application works with system files

“Internal Server Error” occurs when your web application interacts with system files that do not have execute permissions. It sounds as strange as it really is, why can’t I read files that have read permission? Still I do not understand. But this problem is solved if you give the files the right to execute.

Solution:

sudo chmod -R 777 your_project/files/

3. A bug in your web application code

It is also a common situation when apache2 is configured correctly, but still this unlogged error “Internal Server Error” occurs, then you should trace whether your application is working at all.

For example, if it can’t connect to the database, you’ll still see “Internal Server Error”. It is worth checking whether the password is correct and whether there is access to the database. Or it’s possible that the web application just started before the database, in which case a simple restart of apache2 will help.

If your application interacts with an external resource and it is not available or the response time limit is exceeded, then you will see “Internal Server Error” again.

4. Reinstall apache2

If all the above steps did not help you, then there may be a problem with apache2 itself, then you need to try reinstalling it:

sudo apt update
sudo apt install --reinstall apache2

If you have not solved your problem, then here are more possible causes and directions for further search.

  • .htaccess syntax error. If you are using Apache as your web server, then most likely you have an .htaccess file in your site’s root directory. Incorrect syntax or a non-existent module directive can result in a 500 error.

  • Problems with plugins and themes. If you are using WordPress or a similar CMS, the 500 error may appear after updating or changing a plugin or theme.

  • Server problems. A corrupted file system or exhausted memory can result in a 500 error.

  • Node.js modules. If you have a Node.js site, updating modules can cause an internal server error 500.

  • Quite often, malicious code injected into your site results in a 500 error.

  • Incompatible module. Loading an incompatible PHP or Apache module causes a 500 error.

PS I hope someone helped. Good luck.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *