How to Check Apache on Ubuntu Without Restarting It

When a website stops behaving, restarting everything is tempting. It is also a good way to disturb the evidence and possibly create a second problem for the first one to talk to.

I prefer to start with a smaller question: is Apache running, and is there an obvious reason it might not be serving the site properly? The goal here is to check the service, inspect its journal and validate its configuration without intentionally editing configuration files or restarting Apache.

That is not quite the same as promising that nothing on the system will change. Commands may be recorded in audit or authentication logs, and even opening a page can create access-log entries or trigger application activity. I have included a browser check as an optional step, with those caveats in mind.

This is not a complete WordPress troubleshooting guide. An active Apache service can still serve a broken application, and valid Apache syntax does not prove that routing or permissions are correct. We are narrowing the problem, not declaring victory over the internet.

What you will need

  • An Ubuntu server with Apache installed as the standard apache2 service.
  • Shell access to the server and permission to use sudo for the journal and configuration checks.
  • Optionally, a browser and the address you normally use for the site. The address is site-specific; use your own rather than an example from someone else’s server.

These steps do not assume a particular virtual host, document root, WordPress configuration or network layout. The commands are intended to inspect the system, not alter its configuration or service state. If your environment requires a strictly controlled investigation, check its auditing and operational rules before running them.

1. Check the Apache service

Connect to the server using your usual method, then run:

systemctl status apache2.service --no-pager -l

This asks systemd for the service’s current status. The --no-pager option prints the output directly, while -l asks for full lines rather than truncated ones.

Look at the Active line first. An active service tells you systemd currently considers Apache to be running. An inactive or failed service gives you a different place to start. The output may also include recent journal entries, but it is only a snapshot, not a complete history.

Don’t mistake an active service for a healthy website. Apache can be running while an application errors, the wrong site is selected, or a request never reaches the server. Servers are quite capable of being technically present and emotionally unavailable.

2. Read the recent service journal

For more context, ask for the most recent 100 Apache service journal entries from the current boot:

sudo journalctl -u apache2.service -b -n 100 --no-pager

The -u option selects the service, -b limits the output to the current boot, and -n 100 limits how many entries are shown. Read the timestamps and messages around the time the problem occurred, if you know it.

Look for messages about startup failures, configuration problems or permission errors. A message is a clue, not automatically the cause of the current fault. Compare its timing with the symptom before rearranging the server around it.

The journal may not contain every Apache request or error. Depending on the site’s logging configuration, relevant detail may be written to separate log files. Their paths are site-specific, so I would check the existing Apache configuration or the server’s documentation rather than assume a location.

Keep the output private. Logs can contain hostnames, client addresses, request paths and other information you may not want to publish. Redact carefully before asking anyone else to review an excerpt.

3. Check the configuration syntax

Next, ask Apache to check its configuration:

sudo apache2ctl configtest

A successful check normally reports Syntax OK. If the check reports an error, read the message and note any file and line it identifies. This command does not reload Apache or apply a configuration change.

A syntax check has limits. It can tell you that Apache can parse the configuration it reads; it cannot prove that the configuration does what you intended, that WordPress is healthy, or that visitors can reach the site. A warning can also appear alongside a successful syntax result, so read the whole output rather than hunting for two reassuring words.

If you decide a configuration file needs editing, make that a separate, deliberate task. Know how you will back out the change, and run the syntax check again before considering a reload. I am leaving the reload out because the right next action depends on what you find.

4. Optionally check the site in a browser

Open the site’s usual address using its actual hostname. A browser on your normal network gives you a browser check, not necessarily a view from the wider internet. If you specifically need to check external access, use a client on a separate external network, provided you are authorised to do so.

A request can have side effects. It may create access-log entries, and the site or its application may perform additional work. Even loading a page is not guaranteed to be harmless. Skip this step if making a request is unsafe or outside the scope of your investigation.

If you do check, note what happens: does the expected page load, does the browser show a connection error, or does the server return an error page? Avoid submitting forms or triggering administrative actions merely for the sake of a test.

Compare the browser result with the service and configuration checks. For example, a running Apache service plus a browser connection error suggests looking beyond Apache’s process state. A page that loads but contains an application error points towards the application and its logs. Neither observation, on its own, identifies the precise cause.

How to tell whether the checks worked

You are looking for useful observations, not a guaranteed repair. The status command should return information about the Apache service. The journal command should show available entries or indicate that there are none for the selected scope. The configuration test should report its result. If you chose to use a browser, it gives you a separate view from that client’s network.

Write down which check disagrees with your expectation and any relevant timestamps. If everything looks normal but the reported problem is intermittent, that is still useful: you have a baseline to compare with the next occurrence. It is less satisfying than a dramatic fix, but my imaginary troubleshooting cape can stay in the cupboard.

Troubleshooting the checks

  • Service not found: Confirm that Apache is installed and managed as apache2.service on this server. A different installation or service name needs its own documentation; don’t substitute a guessed unit name.
  • Permission denied or incomplete journal access: Confirm that your account is authorised to use sudo. If it isn’t, ask the server administrator rather than changing permissions as a workaround.
  • No useful journal entries: The current boot may not include the event, or relevant details may be in Apache’s separately configured logs. Check where this server writes them.
  • Configuration test fails: Use the reported error and location as the starting point. Don’t assume the line mentioned is the only problem, and avoid editing a production configuration until you understand the change and recovery plan.
  • Apache is active but the site still fails: Check the exact browser symptom, if a request is appropriate, then investigate the relevant application, site configuration or network path. Service status alone cannot distinguish them.

What remains unverified

These are general diagnostic steps, not a record of a test on your server. I cannot verify your service state, log locations, Apache configuration, site address or browser result from the information supplied. I also cannot tell you that a restart, configuration change or WordPress repair is needed.

The useful outcome is a smaller question. Instead of a vague report that the website is broken, you might have observations showing that Apache is active, the syntax check passes and a browser receives an application error. That is not a diagnosis, but it is considerably easier to investigate.

Protect your WordPress site with WordFence

Wordfence is a robust and comprehensive security plugin for WordPress websites. It provides advanced protection against cyber threats such as malware, hacking attempts, and brute force attacks. The plugin features a firewall that blocks malicious traffic before it reaches your site, as well as a malware scanner that detects and removes malicious code. In addition to its security features, Wordfence also offers tools for monitoring site activity and performance. It provides real-time traffic monitoring, detailed logs of site activity, and alerts for suspicious behavior. The plugin also includes options for two-factor authentication and password strength enforcement to further enhance site security.

One of the standout features of Wordfence is its community-powered threat intelligence network. This feature enables the plugin to receive real-time updates and insights about emerging threats from a global network of users. This ensures that your site is protected against the latest security risks.

Overall, Wordfence is a highly effective and user-friendly security solution for WordPress websites. Its comprehensive features and real-time threat intelligence make it a valuable tool for protecting your site from cyber attacks. I would highly recommend Wordfence to any WordPress site owner looking to strengthen their site’s security.

Automated PowerShell Script for Updating UserPrincipalNames in Active Directory After Domain Change

You have completed the domain work in relation to your O365 tenancy, however the usernames replicated to AAD are in “username@old suffix.com” format.

Most organizations have inherited a “username@old-domain.local” suffix. Time goes on and the organization changes its name, amalgamates, etc, for whatever reason, effectively changes its name.

The target of the script is the group a on-prem active directory group.

The following script will serve to allow you to run the script wrapped in a scheduled task in order to change the full upn for the usernames in the group with from “username@old-company.local”(no joke intended), through to “firstname.lastname@new-domain.com” format.

I have used the script on a nightly basis but do not see the reason to run it more frequently.

Import-Module ActiveDirectory
$group = "O365 Users"
$newsuffix = "new-suffix.com"
$users = get-adgroupmember -Identity $group |Get-ADUser |sort userprincipalname
$from = "servername@domain.com"
$to = "admin-user@domain.com"
$tofailedrecipient = "poor.sysadmin@domain.com"

foreach ($user in $users){
    $upn = (($user.givenname)+"."+($user.surname)+"@"+$newsuffix).tostring()
    $upnfromad = ($user.userprincipalname).tostring()
    if ($upn -notmatch $upnfromad) {
        Try{
            $emailbody = "<HTML><HEAD><META http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" /><TITLE></TITLE></HEAD>"
            $emailbody = "<BODY bgcolor=""#FFFFFF"" style=""font-size: Small; font-family: Arial; color: #000000""><P>"
            $emailbody += "<p>The following UPNs have been updated:</p>"
            Set-ADUser -Identity $user.SamAccountName -UserPrincipalName "$($user.GivenName).$($user.Surname)@$newsuffix"
            $emailbody += $upn
            $emailbody += "<br>"
            $successMessageParameters = @{
                        Subject = "The following addresses have been updated - $((Get-Date).ToShortDateString())"
                        Body = $emailbody
                        From = $from
                        To = $to
                        SmtpServer = "x.x.x.x"
                        BodyAsHTML = $true
                        }
            $emailbody += "<p>Regards,</p>"
            $emailbody += "<p>Your friendly Office 365 team</p>"
            Send-MailMessage @successMessageParameters
            }
        Catch [Exception] {
            $ErrorMessage = $_.Exception.Message
            $failedMessageParameters = @{
                        Subject = "The following error was encountered when attempting to update the UPN's"
                        Body = ("'$ErrorMessage'") | Out-String
                        From = $from
                        To = $tofailedrecipient
                        SmtpServer = "x.x.x.x"
                        }
            Send-MailMessage @failedMessageParameters -BodyAsHtml
        }
    }
}

Change Suffix To AD Security group

You have completed the domain work in relation to your O365 tenancy, however the usernames replicated to AAD are in “username@old suffix.com” format.

Most organizations have inherited a “username@old-domain.local” suffix. Time goes on and the organization changes its name, amalgamates, etc, for whatever reason, effectively changes its name.

The following script will serve to allow you to run the script ad hoc in order to change the full upn for the usernames in the group with from “username@old-company.local”(no joke intended), through to “firstname.lastname@new-domain.com” format:

param([string] $group)
cls

Import-Module ActiveDirectory
$newsuffix = "new-suffix.com"
$users = get-adgroupmember -Identity $group |Get-ADUser


write-host "The following users are going to be renamed, would you like to procees?"
$users.userprincipalname 
write-host "The above UPNs are affected." -ForegroundColor Red
$confirmation = Read-Host "Are you Sure You Want To Proceed (y) to firstname.lastname@new-domain.com format" 
if ($confirmation -eq 'y') {
    foreach ($user in $users)
        {
            Set-ADUser -Identity $user.SamAccountName -UserPrincipalName "$($user.GivenName).$($user.Surname)@$newsuffix"
        }
}
Sleep 5

Get-ADGroupMember $group | get-aduser | select userprincipalname