DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Enable PHP Sockets on Your Server (CLI, Apache, PHP-FPM and Windows)

A practical, SAPI-aware guide to enabling PHP sockets on Debian/Ubuntu, Windows, Apache, PHP-FPM, and source builds—with exact checks, restart rules, and fixes for CLI-versus-web failures.
Length10 min Posted Quest giverVGSources Team

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.

Enable PHP’s sockets extension in the exact PHP installation and Server API (SAPI) used by your application, restart that long-running process, and verify the web runtime separately from the command line. Distribution packages normally provide a module-enablement workflow; a PHP build compiled from source must be configured with --enable-sockets.

What PHP sockets are—and what “enable” means

PHP sockets are an extension that exposes low-level networking functions such as socket_create(). They are not an application-level library that you install with a project dependency manager. The extension must be present in the PHP build and loaded by the runtime handling your request.

As an Amazon Associate I earn from qualifying purchases.

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.

When PHP says socket_create() is undefined, the usual cause is that the sockets extension is not loaded in that runtime. A successful command-line check does not prove that Apache, PHP-FPM, CGI, or IIS FastCGI has loaded it. Each SAPI can use a different executable, php.ini, and configuration directory.

The reliable sequence is:

  1. Identify the PHP binary, version, and configuration used by the environment you are testing.
  2. Check whether sockets is already loaded.
  3. Enable or install the extension for that exact PHP build.
  4. Restart the SAPI that serves the application.
  5. Verify with a web-SAPI diagnostic and a minimal function test.

Identify the PHP installation and SAPI before editing anything

Do not start by editing the first php.ini you find. A server can contain several PHP versions, and the shell may use a different version from the web server.

Check the command-line PHP

Run these commands in the shell account used for administration:

command -v php
php -v
php --ini

command -v php shows which executable the shell resolves. php -v identifies its version and build information. php --ini reports the configuration file and additional scanned configuration directories used by that CLI binary.

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

These values describe the CLI SAPI only. They do not necessarily describe an Apache module, PHP-FPM pool, CGI process, or IIS FastCGI worker.

Find out what serves the application

  • An Apache installation may use the PHP module integrated into Apache.
  • A reverse-proxy setup commonly forwards requests to PHP-FPM.
  • Windows deployments may use Apache, IIS FastCGI, or another web-server integration.
  • A scheduled job, queue worker, or game-server utility may invoke CLI PHP even when the website uses a different SAPI.

Enable sockets in every SAPI that actually runs code requiring it. Enabling it only for a maintenance shell will not fix a web request, and enabling it only for the web worker will not fix a CLI worker.

Debian- and Ubuntu-style Linux systems

Debian-family PHP packages organize configuration by PHP version and SAPI. A typical layout separates CLI, Apache, and FPM configuration under paths resembling /etc/php/M.N/, with a conf.d directory for enabled modules. The exact version and SAPI directory on your machine are determined by the installed packages.

1. Check whether the CLI already has sockets

php -m | grep -i sockets

The php -m command lists modules loaded by the selected CLI binary. If the output contains sockets, the CLI extension is active. If it prints nothing, continue with the package and configuration checks below.

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

2. Confirm the matching PHP package and version

Use your operating system’s package search to confirm that the PHP version used by the target SAPI is installed and that its sockets module is available. Package names differ by distribution, PHP release, and packaging stream, so do not copy a package name intended for another version or distribution.

If the server contains several PHP versions, check the version reported by the relevant SAPI rather than assuming the shell’s default version is the one serving the site.

3. Enable a packaged module

When the distribution package is installed but its module is disabled, Debian-family systems commonly provide the phpenmod helper:

sudo phpenmod sockets

The helper creates or enables the appropriate configuration link for the installed PHP version and SAPI. If your host has multiple versions or multiple SAPIs, make sure the command affects the one your application uses. Inspect the corresponding /etc/php/M.N/$SAPI/conf.d/ directory if the helper reports that it cannot find the module.

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

4. Restart the request-handling process

Configuration changes are read when a long-running process starts. Restart the Apache service or the PHP-FPM service that handles the application; restarting an unrelated service will not reload the PHP configuration. The unit name varies with the distribution and PHP packaging, so use the service manager’s installed unit list rather than guessing.

A CLI command does not need a “CLI restart.” Each invocation starts a new process and reads its configuration immediately. Apache workers and FPM workers, however, keep running until they are reloaded or restarted.

5. Verify the web SAPI, not just the shell

Create a temporary page in the application’s web root containing:

<?php phpinfo();

Request that page through the same hostname, virtual host, and web server path as the application. In the output, record:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Loaded Configuration File: the actual php.ini read by the web worker.
  • Additional .ini files parsed: module files loaded after the main configuration.
  • Server API: the SAPI handling the request.
  • Sockets section: its presence indicates that the extension is loaded for that request.

Remove the diagnostic page immediately after testing. A public phpinfo() page discloses paths, versions, build flags, and environment details that should not remain exposed.

Windows PHP installations

On Windows, sockets is loaded from a PHP extension DLL. The web server may not use the php.ini located beside the PHP executable, so the first task is to identify the configuration file actually read by the web process.

1. Find the active configuration file

Use a temporary phpinfo() page through the web server and read Loaded Configuration File. The PHP executable’s directory and the web server’s configuration can point to different files. If you also run php --ini in a console, treat that result as CLI-only until the web page confirms it.

2. Check the extension directory and build compatibility

PHP’s Windows guide places extension DLLs in the PHP ext directory, normally beneath the PHP installation directory. Confirm that the sockets DLL present there was built for the same:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • PHP major and minor version;
  • CPU architecture, such as 64-bit or 32-bit;
  • thread-safety mode required by the web integration; and
  • PHP API/build family.

Do not copy a DLL from a different PHP release or architecture. A matching filename is not enough: dependent runtime DLLs and the build’s thread-safety and API settings must also be compatible.

3. Edit the active php.ini

Keep extension_dir pointed at the intended ext directory. If the file already contains a sockets extension line, remove the comment marker according to the syntax used by the surrounding extension directives. If no line exists, add the extension directive using the exact filename or extension name supported by that PHP build and the DLL present in ext. Avoid guessing a name when the installed build or its example configuration provides the supported spelling.

4. Restart the web integration

Save the file, then restart Apache, IIS FastCGI, or the PHP process used by the site. A browser refresh alone does not guarantee that an existing worker has discarded the old configuration.

5. Confirm activation and inspect logs

Reload the temporary phpinfo() page and look for the sockets section. If it is absent, inspect the PHP and web-server error logs. Windows commonly reports an “Unable to load dynamic library” warning when the active configuration points to the wrong directory, the DLL has missing dependencies, or its architecture, thread-safety mode, PHP version, or API does not match the running executable.

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

PHP compiled from source

If PHP was built from source, the sockets extension is selected at compile time. Configure the build with:

--enable-sockets

The PHP source tree’s sockets configuration declares that option and uses it to build the extension. Adding an ini line to a binary compiled without sockets cannot create the missing functions.

Build and deploy the matching binary

  1. Add --enable-sockets to the configuration options used for the PHP build.
  2. Compile and install that build using the same deployment process used for the rest of the server’s PHP installation.
  3. Confirm which executable and configuration each SAPI now uses; an old binary may remain in the shell path or in a service definition.
  4. Apply any SAPI-specific module configuration required by the installation.
  5. Restart Apache, PHP-FPM, CGI, or the relevant Windows service before testing.

A source build can coexist with distribution PHP packages. That is why checking the executable path, version, loaded configuration file, and Server API is essential after installation.

Verify with a minimal function test

After the module appears in the web-SAPI diagnostic, test the function your application needs:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
var_dump(function_exists('socket_create'));

The expected result is bool(true). This test confirms that the function is available in that request, rather than merely proving that a configuration file contains an extension directive.

Run the same check from the CLI if a command-line worker also needs sockets:

php -r "var_dump(function_exists('socket_create'));"

If the CLI and web results differ, compare their PHP versions, php --ini output, loaded configuration paths, and SAPIs. Fix the environment that reports false; do not assume one SAPI’s success applies to the other.

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

Why sockets works in CLI but not through Apache or PHP-FPM

Different configuration files

The shell’s php --ini output may point to a CLI directory while the web worker reads an Apache or FPM directory. Debian’s version/SAPI layout makes this separation explicit. Use phpinfo() through the web server to identify the web file, then enable the module in that configuration scope.

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

Different PHP versions

A server can have more than one PHP stream installed. The command found by command -v php may be newer or older than the binary configured in an Apache module or FPM pool. Compare the version shown by CLI diagnostics with the version shown by web phpinfo().

The worker was not restarted

FPM and Apache processes retain the old module list until they reload. Restart the service that owns the request-handling workers after every configuration change, then repeat the web test.

The request reaches a different host or pool

Virtual hosts, reverse proxies, and multiple FPM pools can send apparently identical URLs to different PHP processes. Test through the same hostname and route used by the failing application, and read the Server API and loaded configuration from that response.

Troubleshooting by symptom

Symptom Likely cause What to check
Call to undefined function socket_create() Sockets is not loaded in the SAPI making the call. Check function_exists('socket_create'), then inspect that SAPI’s module list and loaded configuration file.
php -m shows sockets, but the website fails CLI and web PHP use different versions, SAPIs, or php.ini files. Compare CLI output with a web phpinfo() page and enable sockets in the web configuration.
Debian helper cannot find sockets The matching PHP version/module package is absent, or the helper is operating on a different installed stream. Use package search for the active PHP version and inspect the corresponding /etc/php/M.N/$SAPI/conf.d/ directory.
Windows “Unable to load dynamic library” Wrong extension_dir, missing dependent DLL, incompatible architecture, thread-safety mode, PHP API, or PHP version. Read the active php.ini, verify the DLL in ext, check build compatibility, and inspect PHP error logs.
Module appears in configuration but not in phpinfo() The edited file is not the file read by the web worker, or the worker was not restarted. Use the page’s “Loaded Configuration File” value, then restart the correct Apache, FPM, or FastCGI process.
CLI test changes after switching shells The shell path resolves a different PHP executable. Run command -v php and php -v again in the affected account and compare paths.

Restart and verification rules for common deployments

  • CLI scripts: no persistent service restart is needed; start a new process after changing configuration.
  • Apache PHP integration: restart or reload the Apache service that loads PHP, then request the diagnostic page through that virtual host.
  • PHP-FPM: restart or reload the FPM pool/version serving the site, not an unused pool for another PHP release.
  • CGI or IIS FastCGI: recycle the worker process or restart the configured web service so it reads the changed DLL and php.ini.
  • Long-running application workers: restart those workers separately; they may not share the web server’s process lifecycle.

After restarting, perform both checks: the module list or sockets section must appear, and function_exists('socket_create') must return true in the failing execution context.

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

Choosing the right enablement approach

Deployment model Primary action Important qualification
Debian/Ubuntu-style package Check php -m; if the packaged module is disabled, use phpenmod sockets. Version and SAPI-specific directories can differ; package names are not universal.
Windows PHP Use the web-loaded php.ini, compatible sockets DLL, correct extension_dir, and restart the web integration. Architecture, thread-safety, PHP API, dependencies, and active configuration must all match.
Self-compiled PHP Build with --enable-sockets, deploy the resulting binary, configure each SAPI, and restart services. An ini directive cannot add sockets to a binary that was compiled without the extension.

Production checklist

  • Record the PHP version and executable for every execution context that needs sockets.
  • Identify the Server API handling the failing request.
  • Check the active configuration path rather than editing a presumed php.ini.
  • Confirm that sockets is listed for that SAPI.
  • On packaged Linux, verify the matching module package and use the distribution’s module helper when appropriate.
  • On Windows, verify the extension DLL, extension_dir, architecture, thread-safety mode, PHP API, and dependent DLLs.
  • For source builds, ensure the binary was configured with --enable-sockets.
  • Restart the long-running web or worker process after changing configuration.
  • Test function_exists('socket_create') through the same route that previously failed.
  • Delete temporary phpinfo() and function-test pages when verification is complete.

Once the extension is loaded in the correct SAPI and the process has been restarted, PHP’s socket functions become available to the application. If the result is still negative, the remaining fault is almost always an environment mismatch: wrong binary, wrong configuration file, wrong service, or an incompatible Windows DLL.

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.

Leave a Reply

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

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

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.