How to Fix Common Website Problems on a Linux Server

Sometimes, your website or server might not work as expected. Knowing where to check and understanding what might be causing the problem can help you fix it quickly and effectively.

This guide will teach you simple steps to identify and solve these issues so that your website can run smoothly again.

When your website isn’t working, the problem is often something common. Let’s take a quick look at the most likely issues:

Is the web server installed and running? Make sure the web server software is properly installed and active.
Are the server settings correct? Check the configuration files for any errors. Small mistakes can cause big issues.
Is the firewall blocking access? Ensure the server ports are open and not blocked by a firewall.
Are DNS settings correct? Verify that your domain points to the right server location.
Is the site content accessible? Confirm the document root is set to the folder where your files are stored.
Are the correct files loading? Ensure the server serves the right index files (like index.html).
Do file permissions allow access? Check that files and folders have the right permissions and ownership.
Do settings restrict access? Review configuration files to ensure they aren’t blocking access accidentally.
Is the database working? If your site uses a database, make sure it’s running and the site can connect to it.

These steps cover the common reasons websites fail to load. To figure out the exact issue, you can check the server’s log files or look at the error messages in your browser.

Next, we’ll explain each of these points in more detail so you can troubleshoot effectively.




Look at the Logs

When your website has issues, checking the log files is a great starting point. Logs contain detailed information about errors and can help you identify what’s going wrong.

For example:

  • Web server logs: If you’re using Apache on Ubuntu, the logs are usually found in the /var/log/apache2 folder. Look inside to see error messages related to your server.
  • Database logs: If your website uses a database and there’s a problem, its logs are also likely stored in the /var/log directory.

Here’s how to use logs effectively:

  1. When you start services, pay attention to any error messages displayed. These can offer quick hints about the problem.
  2. If you visit your website and see an error page, check the message—it might give clues about what’s wrong (although logs are usually more specific).

Quick Tip: Copy parts of the error messages from your logs and search for them online. Many people share solutions for common issues, so this can lead you to the answer faster.

By reviewing logs and error messages, you can save time and find out exactly what needs fixing.




Is Your Web Server Installed?

To run your website, you need a web server. In most cases, this is a software like Apache or Nginx. Sometimes, you might be using a container like Docker, which doesn't require a separate web server. However, for most setups, you will need to install one.
If you've already set up a server, you're probably fine. But there are situations where you might accidentally uninstall it when updating or installing other software.

Here’s how to check and install the web server you need:

For Ubuntu or Debian users:

To install Apache, open your terminal and type:

Copy Code

sudo apt-get update sudo apt-get install apache2

The process will be called apache2.



To install Nginx, type:

Copy Code

sudo apt-get update sudo apt-get install nginx

The process will be called nginx.


For RHEL, Rocky Linux, or Fedora users:

To install Apache, type:

Copy Code

sudo dnf install httpd

The process will be called httpd.



To install Nginx, type:

Copy Code

sudo dnf install nginx

After installation, Nginx won’t start automatically, so you’ll need to start it manually. Read on for instructions on how to do that.


By following these steps, you can make sure that your web server is properly installed and ready to serve your site.




Is Your Web Server Running?

After confirming that your web server is installed, the next step is to check if it’s running. Here's how you can easily find out:

Step 1: Check Active Processes

One way to check if your server is running is by using the netstat command, which shows processes using ports on your system.

Run the following command:

Copy Code

sudo netstat -plunt | grep nginx

Replace nginx with the name of your web server process (e.g., apache2 for Apache).



Example Output:

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15686/nginx: master
tcp6 0 0 :::80 :::* LISTEN 15686/nginx: master

If you see a result like this, it means the server is running. If no output is returned, the server is either not running or you used the wrong process name.

Step 2: Start the Server (If Not Running)

If your server isn’t running, you can start it using the systemctl command, which manages background services in most Linux distributions.

For example, to start Nginx, type:

Copy Code

sudo systemctl start nginx

If you’re using a different server, replace nginx with the appropriate name, such as apache2 or httpd.


Step 3: Verify Again

After starting the server, run the netstat command again to ensure the service is active and listening on the correct ports.
By following these steps, you can easily check and manage your web server’s status. If your server isn’t running as expected, try troubleshooting with additional commands or consult the logs for more details.




Is Your Web Server Configuration File Correct?

If your web server won’t start, the problem is often caused by errors in the configuration files. Both Apache and Nginx require their files to follow strict rules, so even a small mistake can stop your server from running.

Step 1: Locate the Configuration

The configuration files are usually stored in a directory under /etc/ named after your web server:

Apache on Ubuntu/Debian:

Copy Code

cd /etc/apache2


Apache on RHEL, Rocky Linux, or Fedora:

Copy Code

cd /etc/httpd


Nginx (all distributions):

Copy Code

cd /etc/nginx

Step 2: Identify Syntax Issues

When a web server fails to start, it typically provides an error message pointing to the configuration file and the line where the problem begins. Use this information to start troubleshooting.


Step 3: Test the Syntax

Both Apache and Nginx have built-in commands to check if the configuration syntax is correct:

Apache:

Copy Code

apache2ctl configtest


Output Example:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name...
Syntax OK

"Syntax OK" means no critical errors. Warnings like the example above are usually minor.


Nginx:

Copy Code

sudo nginx -t


Output Example::

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


If there’s a mistake, like a missing semicolon, you’ll see an error:

Copy Code

nginx: [emerg] invalid number of arguments in "tcp_nopush" directive in /etc/nginx/nginx.conf:18 nginx: configuration file /etc/nginx/nginx.conf test failed

Step 4: Fix the Errors

Correct the issues mentioned in the error messages. For example:

  • Apache: Add a missing ServerName directive if prompted.
  • Nginx: Always end statements with a semicolon.

Step 5: Retest

After making corrections, run the syntax test command again. Repeat until the configuration passes without errors.

Using these steps, you can quickly spot and fix configuration errors, helping your web server start and run smoothly.




Are the Ports You Configured Open?

Web servers typically use port 80 for HTTP and port 443 for HTTPS (secured with SSL/TLS). To allow visitors to access your site, these ports must be open.

How to Check if the Ports Are Open

You can test your server’s ports using the netcat command from your local machine. Here's how:

1. Replace 111.111.111.111 with your server’s IP address.
2. Run this command to check if port 80 is open:

Copy Code

nc -z 111.111.111.111 80

If the port is open, the command will complete immediately.

If it’s not open, the command will keep trying unsuccessfully until you stop it by pressing CTRL+C.


If the port is closed, review your firewall settings to ensure port 80 (for HTTP) and port 443 (for HTTPS) are allowed.




Are Your DNS Settings Correct?

If you can access your site using its IP address but not its domain name, the issue could be with your DNS settings.

Check DNS Records

Your DNS settings need to include an A record (for IPv4) or AAAA record (for IPv6) pointing to your server's IP address. To verify:

1.Use the host command to check the A record:

Copy Code

host -t A example.com

Output Example:

example.com has address 93.184.216.119

The returned IP should match your server’s IP address.

2. For IPv6 (AAAA record), type:

Copy Code

host -t AAAA example.com

Output Example:

example.com has IPv6 address 2606:2800:220:6d:26bf:1447:1097:aa7

Be Patient with DNS Changes

If you recently updated your DNS records, it might take time for the changes to propagate. This delay depends on your domain registrar and global DNS servers.


Tools to Check DNS Propagation

You can use tools like WhatsMyDNS to see if your DNS updates are live worldwide. Propagation usually completes within 30 minutes but can take longer in some cases.
By following these steps, you can ensure both your ports and DNS settings are configured properly for your site to be accessible.




Make Sure Your Server Configuration Matches Your Domain

Even if your DNS settings are correct, you need to verify that your web server's configuration files are set up to handle your domain name properly. These files tell the server how to respond to domain requests.

Checking Apache Virtual Host Files

If you’re using Apache, your virtual host file determines how the server handles traffic for your domain. For example:

  • File path: /etc/apache2/sites-enabled/000-default.conf
  • Example content:

Copy Code

<VirtualHost *:80> ServerName example.com ServerAlias www.example.com ServerAdmin admin@example.com DocumentRoot /var/www/html ... </VirtualHost>

This configuration:

  • Directs traffic on port 80 for example.com and www.example.com.
  • Defines the location of your website’s files ( /var/www/html ).

Checking Nginx Server Block Files

For Nginx, server block files work similarly to Apache virtual hosts. Here’s an example:

  • File path: /etc/nginx/sites-enabled/default
  • Example content:

Copy Code

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name example.com www.example.com; ... }

This configuration:

  • Listens for requests on port 80 for example.com and www.example.com.
  • Defines the root directory of the site ( /usr/share/nginx/html ).



Is Your Web Server Pointing to the Right File Location?

Your web server must know where your website files are stored to serve them correctly. If it’s not configured to look in the right directory, you’ll encounter errors when trying to access your site. Both Apache and Nginx allow you to set the file location in their configuration files.

Apache: DocumentRoot Directive

In Apache, the location of your files is set using the DocumentRoot directive within the virtual host configuration. Here’s an example:

  • File: /etc/apache2/sites-enabled/default
  • Example content:

Copy Code

<VirtualHost *:80> ServerName example.com ServerAlias www.example.com ServerAdmin admin@example.com DocumentRoot /var/www/html ... <VirtualHost>

This tells Apache to serve files for example.com and www.example.com from the /var/www/html directory.


If your files are stored elsewhere, update the DocumentRoot to match the correct folder. For instance:

Copy Code

DocumentRoot /path/to/your/site

Nginx: Root Directive

In Nginx, the file location is set using the root directive in the server block. Here’s an example:

  • File: /etc/nginx/sites-enabled/default
  • Example content:

Copy Code

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name example.com www.example.com; ... }

This tells Nginx to serve files for the domain from the /usr/share/nginx/html directory.


If your files are stored elsewhere, modify the root line:

Copy Code

root /path/to/your/site;



Is Your Web Server Displaying the Correct Index File?

When you visit your site, the web server usually serves a default file like index.html or index.php for the homepage or a directory. If this isn’t happening, the server may not be configured correctly to prioritize the correct file.

How to Check in Apache

In Apache, the default index files are set using the DirectoryIndex directive. This is often specified in your virtual host file for specific directories. For example:

  • File: /etc/apache2/sites-enabled/default
  • Example:

Copy Code

<Directory /var/www/html> DirectoryIndex index.html index.php </Directory>

This configuration tells Apache to look for an index.html file first. If it doesn’t find one, it will serve index.php. If neither file exists, Apache won’t know what to serve.



To set defaults for the entire server, you can edit the mods-enabled/dir.conf file:

  • File: /etc/apache2/mods-enabled/dir.conf
  • Example:

Copy Code

DirectoryIndex index.html index.php

Make sure the index file you want is listed here and that it exists in your site’s document root.

How to Check in Nginx

In Nginx, the index directive sets the order of index files. Here’s an example:

  • File: /etc/nginx/sites-enabled/default
  • Example:

Copy Code

server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm; server_name example.com www.example.com; }

This tells Nginx to serve index.html as the default file, with index.htm as a backup. If neither file exists, Nginx won’t display an index.

Steps to Fix

1. Verify Index Files Exist:
  • Check your document root (e.g., /var/www/html or /usr/share/nginx/html).
  • Ensure the file you want, like index.html, is present.
2. Update Configuration:
  • If the correct index file is missing, upload it to the document root.
  • If the file exists but isn’t being served, update the DirectoryIndex (Apache) or index (Nginx) settings in the configuration files.
3. Restart the Server:
  • Save your configuration changes and restart the server:

Copy Code

# Restart Apache sudo systemctl restart apache2 # Restart Nginx sudo systemctl restart nginx



Are Permissions and Ownership Set Correctly?

To serve files on your website, your web server needs permission to read and access the files and directories. If permissions and ownership aren’t set up properly, your server won’t work as expected.

Understanding Web Server Users and Groups

Web servers like Apache and Nginx run under specific system user accounts, which need access to your files:

Ubuntu/Debian:
  • Apache and Nginx run as the user www-data and belong to the www-data group.
RHEL/Rocky/Fedora:
  • Apache runs as the user apache in the apache group.
  • Nginx runs as the user nginx in the nginx group.

Checking File and Directory Permissions

To check the permissions and ownership of your web files, use the following command:

Copy Code

ls -l /path/to/web/root

Here’s what to look for:

1. Directories:
  • Should be readable and executable by the web server user or group.
  • If you need to upload, edit, or add files, directories must also be writable.
2. Files:
  • Should be readable by the web server user or group.
  • If files need editing, they must also be writable.

Changing Ownership

To assign ownership of a file or directory to the correct user and group, use the chown command.

  • Change ownership of a single file:

Copy Code

sudo chown user_owner:group_owner /path/to/file
  • Change ownership of a directory and all files inside it:

Copy Code

sudo chown -R user_owner:group_owner /path/to/directory

For example, if you’re hosting files for Apache on Ubuntu, set the ownership to www-data :

Copy Code

sudo chown -R www-data:www-data /path/to/web/root

Why Permissions Matter

1. Readable: The web server can access the file or directory content.

2. Executable (for directories): The server can list and enter directories.

3. Writable: Enables adding or modifying files.

Learn More

For a deeper understanding of file permissions, check out guides on Linux file permissions or run the following:

Copy Code

man chmod man chown

Proper permissions ensure your site runs smoothly and securely!




Are You Blocking Access in Your Configuration Files?

Sometimes, your web server settings might block access to certain files or directories, preventing them from being served. These restrictions are often set in configuration files for your web server.

Restrictions in Apache

For Apache, access rules can be added in two places:

1. Virtual Host File: The main configuration file for your site.

2. .htaccess File: A file located within the directory itself.

For example, in Apache 2.4 or later, you might see something like this:

Copy Code

<Directory /usr/share> AllowOverride None Require all denied </Directory>

This configuration means:

  • No settings can be overridden using an .htaccess file in this directory ( AllowOverride None ).
  • Access is completely denied for all users ( Require all denied ).

Restrictions in Nginx

In Nginx, access can be restricted using deny directives, usually found in the server block configuration files.

For instance:

Copy Code

location /usr/share { deny all; }

This directive blocks access to everything in the /usr/share directory.

How to Fix It

If access is being restricted unintentionally, here’s what you can do:

1. Apache:
  • Check the <Directory> blocks in your virtual host file (e.g., /etc/apache2/sites-enabled/default ).
  • Adjust the rules to allow access, such as changing Require all denied to Require all granted.
2. Nginx:
  • Look for location blocks in your server block file (e.g., /etc/nginx/sites-enabled/default ).
  • Remove or modify the deny all; directive if access should be allowed.



Is Your Database Running?

If your website relies on a database (like MySQL, PostgreSQL, or MongoDB), it’s important to check if the database service is up and running.

To do this, you can use the netstat command to check for active database services. Here’s how:

1. Check for MySQL (or another database): Run the following command in your terminal:

Copy Code

sudo netstat -plunt | grep mysql

If your database is running, you should see an output like this:

Copy Code

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 3356/mysqld

This shows that MySQL is running and listening on port 3306.

2. Check for other services: If you use a different database, replace mysql with the name of your database service (e.g., postgresql, mongod, etc.).

Can Your Site Connect to the Database?

Once you confirm the database is running, the next step is to check if your site can connect to it. For example, WordPress stores database connection details in a file called wp-config.php. You should check these settings:

  • DB_NAME (database name)
  • DB_USER (database username)
  • DB_PASSWORD (database password)

To make sure these settings are correct, you can try connecting to the database manually using a command like this (for MySQL):

Copy Code

mysql -u DB_USER -pDB_PASSWORD DB_NAME

If the connection fails, it could be because the information in your configuration file is wrong, or there may be issues with the permissions on the database. Double-check those details and try again.

What to Do If You Can't Fix It

If you’ve checked everything and your site still isn’t working, your next step is to review the logs. Logs can provide valuable information about what's going wrong.

  • Why check logs: Logs help you identify specific issues, like connection errors or permission problems.
  • Where to find logs: Logs for both your web server (like Apache or Nginx) and your database will often contain helpful error messages.
  • When to ask for help: If you're stuck, share your log files and error messages with an experienced administrator. They’ll have a much better idea of what's wrong if you provide those details.


Conclusion

These steps are common troubleshooting tips for web administrators trying to get their sites up and running. By making sure your web server, database, and configurations are correct, you can often solve many issues. If not, don’t hesitate to reach out for help, and remember to include logs to make troubleshooting easier.