Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

When Apache does not load index.php on Ubuntu, the cause is almost always one of four configuration breaks: the request is reaching a different virtual host or DocumentRoot, Apache is choosing another directory index, PHP has no active handler, or an application’s .htaccess rules are being ignored. A directory listing, a download containing PHP source, an index.html page, and a 403/404/500 response each point to a different layer.

Work through the checks in order. First identify the virtual host and file Apache is actually serving, then verify the file and permissions, inspect DirectoryIndex, choose either libapache2-mod-php or PHP-FPM, and finally test rewrites and logs. Do not configure both PHP execution paths accidentally.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How Apache decides what to do with a directory request

A request such as https://example.test/ passes through several independent decisions:

  1. Virtual-host selection: Apache matches the host name and port to an enabled site.
  2. Filesystem mapping: that site’s DocumentRoot becomes the directory Apache searches.
  3. Directory index selection: mod_dir uses the DirectoryIndex list to choose a file when the URL ends in a slash. Apache’s documentation describes this directive as the list of resources to look for when a client requests an index of a directory.
  4. PHP handling: if the selected file ends in .php, Apache must pass it to a PHP handler rather than return its bytes as text.
  5. Application routing: a framework may use .htaccess and mod_rewrite to send the request to a front controller.

A failure at an earlier stage can make a later, correctly configured stage appear broken. For example, changing the DirectoryIndex in one site file cannot fix a request that is being served by another virtual host.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application: attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Economical &Reusable: Built durable materials with a long-lasting battery,our CAGIWIRU air duster it's a sustainable alternative to disposable air cans.

Diagnose the symptom before changing configuration

What you see Most likely layer First check
An index.html page appears Index ordering or a different document root Active virtual host and DirectoryIndex
PHP source is displayed or downloaded No PHP handler attached Enabled PHP module or FPM handler
A directory listing appears No matching index file and Indexes enabled File path, filename case, and DirectoryIndex
404 for /index.php Wrong DocumentRoot, missing file, or rewrite target Resolved path and access log
403 Forbidden Filesystem or Apache directory permissions Parent-directory execute bits and the <Directory> block
500 Internal Server Error PHP fatal error, invalid Apache syntax, or rewrite rule Apache error log and PHP/FPM log
502/503 or “connection refused” FPM service or socket mismatch Running FPM service and actual socket path

1. Find the virtual host and DocumentRoot Apache is using

Do not assume the directory you edited is the one receiving the request. Ubuntu commonly has a default site enabled alongside one or more custom sites.

  1. List the virtual hosts Apache has loaded:
    sudo apache2ctl -S
  2. Note the host, port, configuration file, and the virtual host marked as the default for that address.
  3. Open the matching site file, usually under /etc/apache2/sites-enabled/, and read its DocumentRoot value:
    sudo grep -R "DocumentRoot" /etc/apache2/sites-enabled/
  4. Confirm that the host name in the browser matches the site’s ServerName or ServerAlias. A request made by an IP address can select a different site from a request made by a DNS name.
  5. Check the effective configuration for syntax errors before reloading anything:
    sudo apache2ctl configtest
    The expected successful result is Syntax OK.

The path that matters is the active virtual host’s DocumentRoot. If it is /var/www/example/public, then Apache will look for /var/www/example/public/index.php, not for a file with the same name under /var/www/html.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Verify the exact index.php path, name, and permissions

Linux filenames are case-sensitive. Index.php, INDEX.PHP, and index.php are different files.

  1. Set a shell variable to the document root you found, then inspect the file:
    DOCROOT=/var/www/example/public
    sudo ls -l "$DOCROOT/index.php"
    sudo stat "$DOCROOT/index.php"
  2. If the file is absent, locate copies and move or deploy the intended one into the active root:
    sudo find /var/www -type f -name 'index.php' -print
  3. Check each parent directory’s permissions. Apache needs execute (x) permission on every directory in the path and read permission on the file. A useful diagnostic is:
    namei -l "$DOCROOT/index.php"
  4. Check ownership and the account used by Apache. Ubuntu’s service commonly runs as www-data, but use the User and Group values in Apache’s configuration as the authority. Avoid making the entire tree world-writable.

A typical static PHP file can be readable by its owner and group without being writable by the web server. Application-specific upload or cache directories may need separate write permissions; do not grant those permissions to the whole document root merely to make the index work.

3. Put index.php in the active DirectoryIndex list

When a browser requests a directory URL, Apache does not automatically prefer PHP. It checks the files named by DirectoryIndex, in order. Ubuntu’s documented default sequence includes index.html index.cgi index.pl index.php index.xhtml index.htm, but a site or distribution configuration can replace that list.

Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
  1. Search the loaded configuration for every relevant declaration:
    sudo grep -R "^[[:space:]]*DirectoryIndex" /etc/apache2
  2. In the intended virtual host or its <Directory> block, set the desired order. To make PHP the first choice:
    DirectoryIndex index.php index.html
  3. If you want only the PHP entry point for an application, use:
    DirectoryIndex index.php
  4. Validate and reload:
    sudo apache2ctl configtest
    sudo systemctl reload apache2

Test both the directory URL and the file URL. https://example.test/ exercises DirectoryIndex; https://example.test/index.php bypasses index selection and tells you whether PHP execution itself works.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Choose one PHP integration method

Apache can execute PHP through the Apache module commonly packaged as libapache2-mod-php, or it can forward PHP requests to PHP-FPM through FastCGI. They are different process models and configuration paths.

Characteristic mod_php PHP-FPM
Apache integration PHP is loaded directly as an Apache module Apache uses mod_proxy_fcgi to forward requests
Ubuntu package path libapache2-mod-php plus the PHP package A versioned php-fpm package and the Apache proxy modules
Process model PHP runs inside Apache workers A separate FPM master and worker pool handles PHP
Version/socket management Apache loads the enabled PHP module version Apache must point to the socket or endpoint belonging to the installed FPM version
Typical failure signal Source is returned when the module is absent or disabled 502/503 errors or connection failures when FPM is stopped or the socket is wrong
Virtual-host setup Usually module-wide after enabling the matching module Often a versioned FPM Apache configuration or an explicit SetHandler

Modern PHP documentation recommends PHP-FPM with Apache’s mod_proxy_fcgi for modern deployments. Whichever method you choose, remove or disable conflicting handlers and verify the actual installed version rather than copying a socket name from an unrelated example.

5. Repair a mod_php installation

Use this route when you intentionally want PHP loaded as an Apache module and your Ubuntu repositories provide the required package.

  1. Install PHP and the Apache module:
    sudo apt update
    sudo apt install php libapache2-mod-php
  2. Inspect the enabled module files:
    ls -l /etc/apache2/mods-enabled/php*.load /etc/apache2/mods-enabled/php*.conf
    You should see a matching versioned .load and .conf file. If no matching files exist, list available modules under /etc/apache2/mods-available/.
  3. Enable the installed version if necessary. Replace X.Y with the version shown by php -v and the filename in mods-available:
    sudo a2enmod phpX.Y
  4. Check the configuration and restart Apache so the module is loaded:
    sudo apache2ctl configtest
    sudo systemctl restart apache2
  5. Confirm that the command-line PHP version and the enabled Apache module are intended to match. A different command-line version can exist on the same machine; the enabled Apache module is what handles web requests.

If Apache still sends the PHP source after a restart, inspect the response headers and error log. A missing SetHandler, a disabled module, or a competing configuration can leave .php treated as an ordinary text file.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black | LED mouse pad with 14 lighting modes, covers keyboard & mouse, anti-slip rubber base, waterproof surface, USB powered
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

6. Configure PHP-FPM through FastCGI

FPM is a separate service. Installing it does not make Apache use it until the proxy integration and the correct endpoint are configured.

  1. Identify the PHP version and installed FPM service:
    php -v
    systemctl list-unit-files 'php*-fpm.service'
  2. Install the FPM package for the intended version, if it is not already present. On Ubuntu the package name is versioned, for example php8.3-fpm; use the version available for your release rather than copying that example blindly.
  3. Enable Apache’s proxy modules:
    sudo a2enmod proxy proxy_fcgi setenvif
  4. Find the socket actually created by FPM:
    ls -l /run/php/
    Look for a file such as php8.3-fpm.sock. The number must match the running service.
  5. Enable Ubuntu’s matching FPM Apache configuration when available. The configuration name is versioned, such as:
    sudo a2enconf php8.3-fpm
  6. If you use a custom virtual-host configuration, attach PHP files to the real socket. This example must be edited to the installed version and path:
    <FilesMatch ".php$">
    SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost/"
    </FilesMatch>
  7. Start and enable the matching service, then validate and restart Apache:
    sudo systemctl enable --now php8.3-fpm
    sudo apache2ctl configtest
    sudo systemctl restart apache2

Use systemctl status php8.3-fpm with your actual version to check whether the service is running. If Apache reports a gateway error, do not guess a socket name: compare the configured path with /run/php/, then read both Apache’s error log and the FPM service log.

7. Make .htaccess rules take effect

Many PHP applications do not serve every route from a physical file. They rely on .htaccess to enable a front controller and rewrite requests to index.php. Apache’s AllowOverride setting determines whether those per-directory directives are read. With AllowOverride None, the file can exist and still have no effect.

  1. Open the <Directory> block that covers the active document root. It may be in the virtual-host file or in a file under /etc/apache2/apache2.conf.
  2. Set an override class appropriate to the application. A common starting point is:
    <Directory /var/www/example/public>
    AllowOverride FileInfo Options
    Require all granted
    </Directory>

    Use the narrowest override permissions that support the application; AllowOverride All is broader than necessary for many sites.
  3. Enable rewrite support if the application requires it:
    sudo a2enmod rewrite
  4. Validate and restart Apache:
    sudo apache2ctl configtest
    sudo systemctl restart apache2

If a rewrite rule causes a 500 response, temporarily rename .htaccess and retest the direct /index.php URL. Then restore the file and correct the specific directive shown in the error log. This separates PHP execution from routing problems.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

8. Test PHP with a temporary probe, then remove it

Create a short-lived file in the active document root to prove that Apache is executing PHP, not merely finding the file:

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.
<?php
phpinfo();

Save it as phpinfo.php, request https://example.test/phpinfo.php, and check the page for the PHP version, loaded configuration file, Server API, and enabled extensions. A page showing PHP information confirms that a handler is active; it does not prove that your application’s framework or database configuration is correct.

Delete the probe immediately after testing:

sudo rm /var/www/example/public/phpinfo.php

The page exposes runtime paths, modules, environment details, and configuration values. Leaving it publicly accessible is an avoidable information disclosure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

9. Read the logs instead of guessing

Use a second terminal while making one request at a time. Ubuntu’s main Apache error log is commonly /var/log/apache2/error.log; a virtual host may also define its own ErrorLog and CustomLog.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Watch the error log: sudo tail -f /var/log/apache2/error.log
  • Find the site’s access log in its virtual-host configuration and watch it with sudo tail -f /path/to/access.log.
  • Check service state and recent messages: sudo systemctl status apache2 and sudo journalctl -u apache2 -n 100 --no-pager.
  • For FPM, use the matching unit, for example sudo journalctl -u php8.3-fpm -n 100 --no-pager.
Log clue Interpretation Action
File does not exist Apache mapped the request to a path without that file Recheck virtual host, DocumentRoot, and filename case
client denied by server configuration The directory or file is blocked by Apache access rules Inspect the applicable <Directory> block and Require directives
AH01276: Cannot serve directory No usable index and directory listing is not allowed Put the intended file in the root or correct DirectoryIndex
PHP source appears in the browser with no PHP error The request was treated as static content Enable the intended module or FPM handler and restart Apache
proxy_fcgi:error or socket connection failure Apache cannot reach the configured FPM endpoint Check the running service and exact socket permissions/path
Invalid command 'RewriteRule' mod_rewrite is not enabled or the directive is outside an allowed context Enable rewrite and adjust AllowOverride or virtual-host configuration

Common repair scenarios

Apache shows index.html but you want index.php

Confirm that both files are under the active document root. Then place index.php before index.html in the effective DirectoryIndex list and reload Apache. If the result does not change, run apache2ctl -S again; you are probably editing a site that is not receiving the request.

A directory listing appears

Apache found the directory but none of the files in its index list. Verify the exact path and case of index.php, check its read permissions, and inspect any site-level DirectoryIndex override. If listings are not required, remove Indexes from the applicable Options directive rather than exposing filenames.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

The browser downloads PHP source

This is an execution-handler problem, not an index-order problem. Test /index.php directly, check for an enabled php*.load/php*.conf pair if using mod_php, or verify the FPM SetHandler and socket if using FPM. Restart Apache after changing the handler.

The site returns 403

Use namei -l to inspect every parent directory, confirm Apache’s service account can traverse the path, and read the exact denial in the error log. Also check the virtual host’s Require directives; filesystem permissions alone do not override Apache authorization rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The site returns 404 only for application routes

Request /index.php directly. If it works, PHP is probably healthy and the failure is routing. Check that .htaccess is present, AllowOverride permits its directives, and mod_rewrite is enabled. If the direct file also returns 404, return to the virtual-host and document-root checks.

The site returns 502 or 503 after switching to FPM

Check the FPM unit state, the socket filename under /run/php/, and the socket’s ownership and permissions. The Apache configuration and running FPM service must refer to the same PHP version. Logs normally identify whether the socket is missing, refused, or inaccessible.

Final verification checklist

  • sudo apache2ctl -S identifies the intended virtual host.
  • The active DocumentRoot contains the intended, correctly cased index.php.
  • Apache can traverse parent directories and read the file.
  • DirectoryIndex includes index.php in the desired order.
  • Exactly one PHP path is intentional: mod_php or PHP-FPM.
  • The selected handler’s module, service, socket, and PHP version agree.
  • .htaccess is used only when the relevant AllowOverride permits its directives.
  • mod_rewrite is enabled when front-controller routing needs it.
  • apache2ctl configtest returns Syntax OK before a reload or restart.
  • The temporary PHP information file has been deleted.
  • The Apache access and error logs show the expected status for both / and /index.php.

Once these checks pass, Apache will either select index.php for the directory request or report a specific application-level error that can be fixed within PHP itself. The key is to diagnose the request path in order: virtual host, file, index selection, PHP handler, then rewrites.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.