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

If one Apache virtual host serves PHP while another downloads the .php file, displays its source, returns a 503/502, or shows the wrong site, the failure is usually a configuration mismatch rather than a PHP-code problem. Apache first chooses a virtual host from the connection’s IP and port and the request’s Host header. Only then do that host’s PHP handlers, proxy rules, and logs matter. Prove which vhost received the request, identify whether it uses PHP-FPM or mod_php, and configure a handler for real PHP files in that vhost. The procedure below works for Apache 2.4 installations while calling out legacy mod_php limitations.

What Apache has to decide before PHP can run

A browser request passes through two separate decisions. First, Apache selects a virtual host. Second, the selected host maps a PHP filename to an execution method. A correct PHP handler in the wrong vhost is functionally the same as no handler at all for the site you are testing.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

How name-based virtual-host matching works

Apache starts with the connection’s local IP address and port. Among virtual hosts bound to that pair, it compares the request’s Host header with each ServerName and ServerAlias. The matching host wins. If no name matches, Apache uses the first virtual host for that IP-and-port combination as the default. That is why a typo, an omitted alias, a duplicate name, or a request sent to an unexpected listener can display another site’s HTML.

The address in a browser’s bar is not enough to prove the match. DNS, a proxy, a hosts-file override, an HTTPS terminator, or a nonstandard port can change the request that reaches Apache. Test the exact listener and send the intended host name explicitly.

#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:Upgraded 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.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

Why a handler can work in one host and fail in another

Apache directives may be global, inherited, or confined to one <VirtualHost> block. If a PHP-FPM SetHandler appears only in the first host, a second host can return source code or a download even though PHP is installed and the first site works. Conversely, a global rule can execute files in hosts that were meant to serve static content. Keep the execution rule in the host that owns the application and verify the selected host before changing PHP settings.

Step 1: Prove which virtual host handled the request

Do this before editing PHP configuration. It prevents fixing a perfectly good vhost while testing a different one.

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

Read Apache’s parsed vhost map

  1. Run apachectl -S (some distributions expose the same check through a distribution-specific Apache control command).
  2. Find the expected ServerName, every required ServerAlias, and the IP-and-port pair used by the listener.
  3. Note the default vhost shown for that pair. It is the host Apache will use when the name does not match.
  4. Look for duplicate names, an accidental wildcard or catch-all host, and a host bound only to IPv4 while the request arrives over IPv6.

This command reports Apache’s parsed configuration, not merely the text in a file. A typo in an included file, a disabled site, or a different configuration tree can therefore become visible immediately.

Send an explicit Host header

To test a local HTTP listener without relying on DNS, request the listener’s address and supply the production name yourself:

curl -H "Host: example.test" -i http://127.0.0.1/

For HTTPS, use the hostname in the URL so the TLS name and HTTP Host are both realistic; if you must test a certificate that is not publicly resolvable, use an appropriate local name-resolution method rather than judging the vhost from an IP-only URL. The important diagnostic detail is that Apache’s name-based selection uses the HTTP host value after the connection reaches the correct IP and port.

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

Give each vhost a visible log identity

Use separate access and error logs for each host, or include the virtual-host field (commonly %v) in a shared access-log format. Request a deliberately missing path such as /vhost-check-that-does-not-exist and confirm which log receives the 404. Then request the PHP URL and inspect errors in that same host’s error log. This distinguishes a PHP-FPM failure from a request that never reached the intended configuration.

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

Step 2: Identify the PHP execution model

Apache can execute PHP through an embedded module (mod_php) or pass requests to a separate PHP-FPM process manager. Do not combine snippets from both models without understanding which one is active.

Characteristic PHP-FPM with mod_proxy_fcgi mod_php
Process model PHP runs in a separate PHP-FPM pool; Apache proxies FastCGI requests. PHP is loaded inside Apache worker processes.
Apache MPM Compatible with threaded event and worker MPMs. Typical non-ZTS builds require the prefork MPM.
Operations PHP workers can be managed and restarted independently of Apache, with pool-level resource controls and process isolation. PHP lifecycle and memory use are tied to Apache workers.
Recommended use Preferred for modern Apache 2.4 deployments according to Apache and PHP documentation. Useful for existing legacy installations when the module and MPM requirements are satisfied.

Check what Apache has loaded

Run apachectl -M and inspect the output for the active MPM, proxy_module, proxy_fcgi_module, or a PHP module. The exact module name can vary with the PHP package, but an absent PHP module means a mod_php handler cannot work. An absent proxy-FCGI module means a PHP-FPM proxy: handler cannot work. Check the PHP-FPM service separately; Apache’s module list does not prove that a PHP-FPM pool is running.

Why PHP-FPM is normally the better choice

Apache’s current guidance prefers proxying to PHP-FPM, and PHP’s manual recommends PHP-FPM with Apache’s mod_proxy_fcgi for modern deployments. The model supports independent PHP restarts, process management, and threaded Apache MPMs. Those recommendations do not require an immediate migration of every functioning legacy mod_php host, but they do make PHP-FPM the sensible baseline for a new or repaired Apache 2.4 configuration.

Step 3: Configure PHP-FPM in the selected virtual host

Put the handler inside the <VirtualHost> block that apachectl -S and your explicit-Host test identified. Replace the endpoint below with the actual TCP port or Unix socket used by that host’s PHP-FPM pool.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【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.

Use a narrow handler with an existence check

<FilesMatch ".php$">
    <If "-f %{REQUEST_FILENAME}">
        SetHandler "proxy:fcgi://127.0.0.1:9000"
    </If>
</FilesMatch>

The TCP form sends FastCGI requests to port 9000 on the local address. If PHP-FPM listens on a Unix socket, use the socket form documented for Apache:

<FilesMatch ".php$">
    <If "-f %{REQUEST_FILENAME}">
        SetHandler "proxy:unix:/run/php/php-fpm.sock|fcgi://localhost/"
    </If>
</FilesMatch>

Use the real socket path, including any version or pool-specific directory used by your operating system. A syntactically correct rule pointing at a nonexistent socket produces a gateway error, not PHP output.

Why the -f guard matters

The condition restricts execution to a file that actually exists. Without it, a request for a nonexistent path ending in .php can be sent to PHP-FPM before your front-controller or FallbackResource routing gets a chance to handle it. The result is often an unexpected 404 or 500 for application routes that do not map to a physical script.

The guard also narrows the attack surface. A broad proxy rule can interpret a path such as /uploads/file.jpg/something.php as PHP, depending on path-info handling. Keep upload directories outside the document root where practical, prevent script execution there, and avoid greedy matching rules unless you have explicitly validated the complete path.

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

Confirm the endpoint and permissions

  • Verify that the PHP-FPM pool is running and listening on the same TCP address/port or Unix socket named in SetHandler.
  • For a Unix socket, ensure the Apache runtime user can connect to the socket through every parent directory. A socket can exist yet still reject Apache because of ownership or mode bits.
  • Ensure the requested script is readable by the PHP-FPM worker account and that Apache’s document-root and directory permissions allow the request to reach it.
  • Keep the PHP-FPM pool’s document-root assumptions consistent with Apache’s filesystem path. A proxy can connect successfully and still fail when PHP cannot open the script.

Do not mix unrelated proxy recipes

Some older guides use a broad ProxyPassMatch expression. Replacing a precise FilesMatch rule with that expression can change path-info behavior and make upload paths executable. Start with the narrow rule above, then add path handling only when the application demonstrably needs it and you can validate the resulting filesystem path.

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.

Step 4: Configure mod_php only when you intentionally use it

For mod_php, Apache must load the PHP module, and the selected host must map PHP files to that module. A typical mapping is:

<FilesMatch ".php$">
    SetHandler application/x-httpd-php
</FilesMatch>

The module and handler names depend on the PHP package supplied by your operating system. Confirm the module with apachectl -M; do not assume that installing the PHP command-line binary installed the Apache module as well.

Check MPM compatibility

Most non-ZTS mod_php builds are designed for Apache’s prefork MPM. If Apache is running the event or worker MPM, the module may refuse to load, Apache may fail a configuration test, or the combination may be unsupported by the package. You can see the active MPM in apachectl -M. Do not switch MPM blindly on a production host: changing it can affect other modules and requires a controlled restart or reload plan.

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

Keep the handler in the right scope

If only one site should execute PHP, place the FilesMatch block in that site’s virtual host instead of enabling a global handler for every document root. After editing, use apachectl -S and an explicit-Host request to make sure the test is reaching the host that contains the mapping.

Step 5: Validate, reload, and test safely

  1. Run Apache’s configuration syntax check before touching the live process. The exact command is commonly exposed as apachectl configtest; use the equivalent control command supplied by your distribution if necessary. Fix every syntax error first.
  2. Run apachectl -S again. Confirm that the edited file is included, the expected names are unique, and the intended host remains associated with the correct IP-and-port pair.
  3. Perform a graceful reload using your platform’s Apache service control. The research-backed procedure is a validated configuration followed by a graceful reload; the service command itself differs among distributions.
  4. Request a minimal PHP test through the exact hostname and port. A temporary file containing a simple PHP output statement is enough to prove execution without exposing a full configuration dump.
  5. If you use a phpinfo() file for diagnosis, remove it immediately after testing. It reveals paths, loaded modules, environment values, and other configuration details useful to attackers.

Test both a real script and a nonexistent .php path. The real script should execute through the intended PHP engine; the nonexistent path should follow your application’s normal 404 or front-controller behavior rather than being sent indiscriminately to PHP-FPM.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Symptom-to-cause troubleshooting

Symptom Most likely cause Verification and corrective action
The wrong site’s HTML appears The hostname did not match, names are duplicated, or the request reached the default vhost. Run apachectl -S, send an explicit Host header to the intended listener, and make ServerName/ServerAlias values unique.
The browser downloads a PHP file or displays PHP source No PHP handler exists in the selected vhost, or the required module is not loaded. Confirm the vhost with logs and curl; then add the PHP-FPM SetHandler or mod_php mapping and verify the corresponding module.
A PHP URL returns 503 or 502 The PHP-FPM service is stopped, the TCP endpoint or socket path is wrong, or Apache cannot access the socket. Read the selected vhost’s error log, check the PHP-FPM pool and listening endpoint, and correct the path, port, ownership, or permissions.
Only one vhost executes PHP The handler is global or exists only in another virtual host. Place the handler in the selected host, then verify the parsed map and per-vhost log entry for the request.
Front-controller routes produce an unexpected 404 or 500 A handler is catching nonexistent .php paths before fallback routing. Wrap the handler in <If "-f %{REQUEST_FILENAME}"> so only real scripts are proxied.

Reading the error log without guessing

Errors before PHP starts

Messages about an unknown directive, a missing module, or an invalid SetHandler usually appear during configuration validation or reload. They indicate Apache could not build the requested configuration. Resolve those first; a browser test cannot diagnose a configuration that never loaded.

Errors connecting to PHP-FPM

Connection-refused, timeout, or missing-socket messages point to the FPM service or endpoint rather than to PHP application code. Compare the socket or port in the error with the value in the selected vhost. Then check the FPM pool’s own log and service state. A 503/502 generated by Apache is evidence that the proxy path failed; it is not evidence that the script returned an HTTP 503.

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

Errors after PHP starts

If PHP-FPM logs a script-level parse error, missing extension, or application exception, the Apache routing problem is already past the failing point. Fix the PHP application or pool environment separately, while retaining the vhost and handler configuration that successfully delivered the script.

Security rules for PHP-enabled virtual hosts

  • Match only the extensions your application needs, normally real .php files, rather than proxying every request.
  • Keep the -f existence guard in the handler so virtual routes and arbitrary path suffixes are not sent to PHP.
  • Do not allow script execution in upload, cache, backup, or user-content directories. Store uploads outside the document root when the application permits it.
  • Use distinct logs or a log format containing the virtual-host name. It reduces the chance that an incident in one site is mistaken for a failure in another.
  • Remove diagnostic scripts and avoid leaving detailed PHP configuration output publicly reachable.
  • Restrict PHP-FPM pools and socket permissions to the users and groups that need them. A functioning proxy with unnecessarily broad socket access increases the impact of a compromised site.

When to keep mod_php and when to move to PHP-FPM

Keep a legacy mod_php host temporarily when

  • The application depends on the embedded module and is already stable.
  • The PHP build is compatible with the active prefork MPM.
  • You can apply a precise handler and maintain the host’s security boundaries.
  • A migration can be scheduled and tested rather than performed during an outage.

Prefer PHP-FPM for a new or modernized host when

  • You need Apache’s event or worker MPM for concurrency or other threaded modules.
  • You want PHP workers, limits, and restarts managed independently from Apache.
  • Several applications require separate PHP pools or versions.
  • You want the integration recommended by current Apache 2.4 and PHP documentation.

Changing the execution model is not a substitute for fixing vhost selection. A perfect PHP-FPM pool still appears broken if the request lands in the default host, and a correctly selected host still fails if its handler points to the wrong endpoint.

A compact decision path for the next failure

  1. Wrong content? Stop and prove the vhost with apachectl -S, an explicit Host header, and per-vhost logs.
  2. Right vhost, source or download? Identify the execution model, confirm its module, and add a handler inside that host.
  3. 503 or 502? Treat it as an FPM endpoint, service, or permission problem; compare the configured and actual socket or port.
  4. Only routed URLs fail? Add the real-file guard and retest a physical script plus a nonexistent route.
  5. Configuration will not reload? Run the syntax check and fix module, directive, quoting, or include-file errors before testing in a browser.

Once the selected vhost, handler type, endpoint, and file-safety guard all agree, Apache can pass the request to the intended PHP runtime without affecting neighboring sites.

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.