{"id":13405494,"url":"https://github.com/mlocati/powershell-phpmanager","last_synced_at":"2025-04-12T23:40:48.163Z","repository":{"id":38793278,"uuid":"130501331","full_name":"mlocati/powershell-phpmanager","owner":"mlocati","description":" A PowerShell module to install/update PHP, PHP extensions and Composer on Windows","archived":false,"fork":false,"pushed_at":"2025-03-03T14:12:49.000Z","size":1570,"stargazers_count":222,"open_issues_count":3,"forks_count":19,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-04T03:08:10.324Z","etag":null,"topics":["dll","extensions","php","powershell","win32","windows"],"latest_commit_sha":null,"homepage":"https://www.powershellgallery.com/packages/PhpManager","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlocati.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mlocati","custom":"https://paypal.me/mlocati"}},"created_at":"2018-04-21T18:27:46.000Z","updated_at":"2025-03-27T08:55:17.000Z","dependencies_parsed_at":"2024-06-03T09:05:14.488Z","dependency_job_id":"c00f1dd9-73f1-4355-a4d1-0bfbbef6848c","html_url":"https://github.com/mlocati/powershell-phpmanager","commit_stats":{"total_commits":272,"total_committers":7,"mean_commits":"38.857142857142854","dds":0.03676470588235292,"last_synced_commit":"8c0deb5077a849ed19a78f5fa06dd90f93560923"},"previous_names":[],"tags_count":86,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlocati%2Fpowershell-phpmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlocati%2Fpowershell-phpmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlocati%2Fpowershell-phpmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlocati%2Fpowershell-phpmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlocati","download_url":"https://codeload.github.com/mlocati/powershell-phpmanager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647253,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dll","extensions","php","powershell","win32","windows"],"created_at":"2024-07-30T19:02:03.794Z","updated_at":"2025-04-12T23:40:48.143Z","avatar_url":"https://github.com/mlocati.png","language":"PowerShell","readme":"[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/mlocati/powershell-phpmanager?branch=master\u0026svg=true)](https://ci.appveyor.com/project/mlocati/powershell-phpmanager)\n[![GitHub Actions Test Status](https://github.com/mlocati/powershell-phpmanager/actions/workflows/test.yml/badge.svg)](https://github.com/mlocati/powershell-phpmanager/actions?query=workflow:Test)\n[![PowerShell Gallery Download Count](https://img.shields.io/powershellgallery/dt/PhpManager?label=downloads%20from%20PSGallery)](https://www.powershellgallery.com/packages/PhpManager)\n[![Github Releases Download Count](https://img.shields.io/github/downloads/mlocati/powershell-phpmanager/total?label=downloads%20from%20GitHub)](https://github.com/mlocati/powershell-phpmanager/releases)\n\n## Introduction\n\nThis repository contains a PowerShell module that implements functions to install, update and configure PHP on Windows.\n\n\n## Installation\n\nYou'll need at least PowerShell version 5: in order to determine which version you have, open PowerShell and type:\n\n```powershell\n$PSVersionTable.PSVersion.ToString()\n```\n\nIf you have an older version, you can upgrade it [following these instructions](https://docs.microsoft.com/en-us/powershell/wmf/setup/install-configure).\n\nTo install this module for any user of your PC, open an elevated PowerShell session (for example with `Start-Process powershell -Verb runAs`) and run this command:\n\n```powershell\nInstall-Module -Name PhpManager -Repository PSGallery -Force\n```\n\nTo install this module for the current user only:\n\n```powershell\nInstall-Module -Name PhpManager -Repository PSGallery -Force -Scope CurrentUser\n```\n\nIf you won't be able to execute the module functions, you may need to tell PowerShell to enable their execution:\n\n```powershell\nSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force\n```\n\n\n## Available Features\n\nHere you can find a short description of the available commands: in order to get more details, type `Get-Help \u003cCommandName\u003e` (or `Get-Help -Detailed \u003cCommandName\u003e` or `Get-Help -Full \u003cCommandName\u003e`).\n\n### Installing PHP\n\nUse the `Install-Php` command to install PHP.\n- you can specify a generic version (eg `7`) or a more refined version (eg `7.2` or `7.2.1`). You can also ask to install release candidate versions (eg `7.2.5RC`), as well as development versions (eg `7.4snapshot` or `master`)\n- you can specify to install a 32-bit or a 64-bit version\n- you can specify to install a Thread-Safe or Non-Thread-Safe version\n- you can specify the default time zone\n- you can ask to add the PHP installation path to the system or to the user PATH variable (so that you'll be able to use `php.exe` without specifying its path)\n\n```powershell\nInstall-Php -Version 7.2 -Architecture x64 -ThreadSafe 0 -Path C:\\PHP -TimeZone UTC -AddToPath User\n```\n\n### Upgrading PHP\n\nUse the `Update-Php` command to upgrade PHP.\nThe command will automatically check if there's a newer version available: if so, the PHP installation will be upgraded.\nPlease note that stable versions will be upgraded to stable, and non-stable (alpha/beta/release candidate) versions will be upgraded to stable or non-stable versions.\nAlso the 32/64 bit and the thread safety will be the same.\n\n```powershell\nUpdate-Php C:\\PHP\n```\n\n### Updating PHP to a specified version\n\nUse the `Install-Php` command to update PHP (for example existing version 7.2.10 to 7.2.15). \nIf you don't specify the ```InitialPhpIni``` parameter all  settings are retained.\n**Also the parameter `Force` is required**\n\n```powershell\nInstall-Php -Version 7.2.15 -Architecture x64 -ThreadSafe $true -Path C:\\PHP -Force\n```\n\n### Uninstalling PHP\n\nUse the `Uninstall-Php` command to uninstall PHP.\nThis command will remove the PHP installation folder, and its path will be removed from the PATH environment variables.\n\n```powershell\nUninstall-Php C:\\PHP\n```\n\n### Working with multiple PHP installations\n\nIt's often handy to be able to use different PHP versions for different projects.  \nFor instance, sometimes you may want that `php.exe` is PHP 5.6, sometimes you may want that `php.exe` is PHP 7.2.  \nThis module let's you easily switch the *current* PHP version (that is, the one accessible without specifying the `php.exe` path) with the concept of **PHP Switcher**.  \nFirst, you install the PHP versions you need:\n\n```powershell\nInstall-Php -Version 5.6 -Architecture x86 -ThreadSafe $true -Path C:\\Dev\\PHP5.6 -TimeZone UTC\nInstall-Php -Version 7.2 -Architecture x86 -ThreadSafe $true -Path C:\\Dev\\PHP7.2 -TimeZone UTC\n```\n\nThen you initialize the PHP Switcher, specifying where the *current* PHP version should be available:\n\n```powershell\nInitialize-PhpSwitcher -Alias C:\\Dev\\PHP -Scope CurrentUser\n```\n\nThen, you can add to the PHP Switcher the PHP versions you installed:\n```powershell\nAdd-PhpToSwitcher -Name 5.6 -Path C:\\Dev\\PHP5.6\nAdd-PhpToSwitcher -Name 7.2 -Path C:\\Dev\\PHP7.2\n```\n\nYou can get the details about the PHP Switcher configuration with the `Get-PhpSwitcher` command:\n\n```powershell\nGet-PhpSwitcher\n(Get-PhpSwitcher).Targets\n```\n\nOnce you have done that, you can switch the current PHP version as easily as calling the `Switch-Php` command.  \nHere's a sample session:\n\n```powershell\nPS C:\\\u003e Switch-Php 5.6\nPS C:\\\u003e php -r 'echo PHP_VERSION;'\n5.6.36\nPS C:\\\u003e (Get-Command php).Path\nC:\\Dev\\PHP\\php.exe\nPS C:\\\u003e Switch-Php 7.2\nPS C:\\\u003e php -r 'echo PHP_VERSION;'\n7.2.5\nPS C:\\\u003e (Get-Command php).Path\nC:\\Dev\\PHP\\php.exe\nPS C:\\\u003e\n```\n\nYou can use the `Remove-PhpFromSwitcher` to remove a PHP installation from the PHP Switcher, `Move-PhpSwitcher` to change the directory where `php.exe` will be visible in (`C:\\Dev\\PHP` in the example above), and `Remove-PhpSwitcher` to remove the PHP Switcher.\n\nYou can do many fancy stuff with PHP Switcher. For example, to download and enable the `redis` PHP extension for all the PHP versions, you can write something like this:\n\n```powershell\n$phpSwitcher = Get-PhpSwitcher\n$phpSwitcher.Targets.Keys | ForEach-Object {\n    Write-Host -Object \"Installing for $_... \" -NoNewline\n    try {\n        Install-PhpExtension -Path $phpSwitcher.Targets[$_] redis\n        Write-Host -Object 'done.' -ForegroundColor Green\n    } catch {\n        Write-Host -Object $_ -ForegroundColor Red\n    }\n}\n```\n\nIf you want to let **Apache** work with PHP, you have to add the `LoadModule` directive to the Apache configuration file, which should point to the appropriate DLL.\nFor instance, with PHP 5.6 it is  \n\n```\nLoadModule php5_module \"C:\\Dev\\PHP5.6\\php5apache2_4.dll\"\n```\n\nAnd for PHP 7.2 it is  \n\n```\nLoadModule php7_module \"C:\\Dev\\PHP7.2\\php7apache2_4.dll\"\n```\n\nIn order to simplify switching the PHP version used by Apache, the `Install-Php` command creates a file called `Apache.conf` in the PHP installation directory, containing the right `LoadModule` definition.\nSo, in your Apache configuration file, instead of writing the `LoadModule` directive, you can simply write:\n\n```\nInclude \"C:\\Dev\\PHP\\Apache.conf\"\n```\n\nThat's all: to switch the PHP version used by Apache simply call `Switch-Php` and restart Apache.\n\n### Getting details about installed PHPs\n\nUse the `Get-Php` command to list the PHP installations found in the current PATH environment variable.\nYou can also specify a directory: the command will display the details of the PHP installed there.\n\n```powershell\nGet-Php C:\\PHP\n```\n\nSample Output:\n\n```\nFolder             : C:\\PHP\nExecutablePath     : C:\\PHP\\php.exe\nExtensionsPath     : C:\\PHP\\ext\nMajorMinorVersion  : 7.4\nVersion            : 7.4.0\nFullVersion        : 7.4.0RC6\nUnstabilityLevel   : RC\nUnstabilityVersion : 6\nDisplayName        : PHP 7.4.0RC6 x86 (32-bit) Thread-Safe\nArchitecture       : x86\nThreadSafe         : True\nVCVersion          : 15\n```\n\n### Getting `php.ini` configuration keys\n\nUse the `Get-PhpIniKey` command to retrieve the value of a configuration in the `php.ini` file used by a PHP installation.\n\n```powershell\nGet-PhpIniKey default_charset C:\\PHP\n```\n\n### Setting and removing `php.ini` configuration keys\n\nUse the `Set-PhpIniKey` command to add or change configuration keys in the `php.ini` file used by a PHP installation.\nYou can also delete, comment or uncomment configuration keys with this command.\n\n```powershell\nSet-PhpIniKey default_charset UTF-8 C:\\PHP\n```\n\n### Getting the list of PHP extensions\n\nYou can use the `Get-PhpExtension` command to get the PHP extensions currently available (enabled or disabled) in the PHP installation.\n\n```powershell\n# List the builtin extensions\nGet-PhpExtension C:\\PHP | Where { $_.Type -eq 'Builtin' }\n# List the enabled extensions\nGet-PhpExtension C:\\PHP | Where { $_.State -eq 'Enabled' }\n# List the Zend extensions (xdebug, opcache, ...)\nGet-PhpExtension C:\\PHP | Where { $_.Type -eq 'Zend' }\n```\n\nThe `Type` property of the extension objects can be:\n\n- `Builtin` for extensions bundled in PHP (for example: `reflection`, `spl`, `tokenizer`)\n- `Php` for regular PHP extensions\n- `Zend` for Zend extensions (for example: `xdebug` or `opcache`)\n\nThe `State` property of the extension objects can be:\n\n- `Builtin` for extensions bundled in PHP (for example: `reflection`, `spl`, `tokenizer`) (those extensions are always enabled)\n- `Enabled` for enabled non-builtin extensions \n- `Disabled` for disabled non-builtin extensions \n- `Unknown` if you pass `Get-PhpExtension` the path to a DLL extension file (see [here](#inspecting-a-php-extension-dll-file))\n\n### Enabling and disabling PHP extensions\n\nYou can use the `Enable-PhpExtension`/`Disable-PhpExtension` command to enable or disable PHP extensions.\nPlease remark that the `Enable-PhpExtension` command requires that the extension is already present in your PHP installation; if you don't have the installation DLL file, you can use the `Install-PhpExtension` command.\n\n```powershell\nEnable-PhpExtension opcache C:\\PHP\nDisable-PhpExtension mbstring C:\\PHP\n```\n\n### Adding new extensions (from [PECL](https://pecl.php.net/))\n\nThe `Enable-PhpExtension` command can only enable extensions that are already present in the PHP installation.\nIn order to add new extensions (like `xdebug` or `imagick` - `imagemagick`) you can use the `Install-PhpExtension` command.\nThis command will download the DLLs of the extensions from the [PECL](https://pecl.php.net/) archive.\nYou can specify a version of the extension (generic, like `1`, or specific, like `1.2`), and the minimum stability:\n\n```powershell\nInstall-PhpExtension xdebug -Version 2.6\nInstall-PhpExtension imagick -MinimumStability snapshot\n```\n\nSome extensions require additional dependencies (for example `imagick`).\nBy default, `Install-PhpExtension` automatically installs these dependencies in the directory where PHP is installed.\nIf you want to install them in another directory, you have to call the `Install-PhpExtensionPrerequisite` command, and specify the `-NoDependencies` option for `Install-PhpExtension`.\n\nPS: `Install-PhpExtension` can also be used to upgrade (or downgrade) a PHP extension to the most recent version available online.\n\n### Getting the list of PHP versions available online\n\nUse the `Get-PhpAvailableVersion` command to list the PHP versions available online.\nYou can specify to list the `Release` versions (that is, the ones currently supported), as well as the `Archive` versions (the ones at end-of-life) and the `QA` versions (that is, the release candidates).\n\nFor instance, to list all the 64-bit thread-safe releases you can use this command:\n\n```powershell\nGet-PhpAvailableVersion Release | Where { $_.Architecture -eq 'x64' -and $_.ThreadSafe -eq $true }\n```\n\n### Managing HTTPS/TLS/SSL Certification Authority certificates\n\nWhen connecting (with cURL, openssl, ...) to a remote resource via a secure protocol (for instance `https:`), PHP checks if the certificate has been issued by a valid Certification Authority (CA).  \nOn Linux and Mac systems, the list of valid CAs is managed by the system.  \nOn Windows there isn't a similar feature: we have to manually retrieve the list of reliable CAs and tell PHP where they are.  \nThe `Update-PhpCAInfo` does all that for you: a simple call to this command will fetch the valid CA list and configure PHP.  \nSince the list of valid CA certificates changes over time, you should execute `Update-PhpCAInfo` on a regular basis.  \nIn addition, `Update-PhpCAInfo` can optionally add your custom CA certificates to the list of official CA certificates.\n\n### Installing Composer\n\nYou can install [Composer](https://getcomposer.org/) with the command `Install-Composer`.\n`Install-Composer` is able to add `composer` to the path, so that you can execute it from any location.\nType `Get-Help -Detailed Install-Composer` for more details.\n\n### Configuring OpenSSL\n\nIf you need to use the OpenSSL PHP extension for key generation or certificate signing functions, [you will need a valid `openssl.cnf` file](https://www.php.net/manual/en/openssl.installation.php).\n`Set-OpenSSLConf` will set the `OPENSSL_CONF` environment variable (for the current process, and optionally for the current user or local machine).\n`Set-OpenSSLConf` will look for `openssl.cnf` in some common places, but you can also provide the path to that file.\n\n### Inspecting a PHP extension DLL file\n\n`Get-PhpExtension` is able to inspect a DLL file of a PHP extension:\n\n```powershell\nPS C:\\\u003e Invoke-WebRequest -Uri https://xdebug.org/files/php_xdebug-2.6.1-7.0-vc14-nts-x86_64.dll -OutFile test.dll\nPS C:\\\u003e Get-PhpExtension test.dll\nType         : Zend\nState        : Unknown\nName         : Xdebug\nHandle       : xdebug\nVersion      : 2.6.1\nPhpVersion   : 7.0\nArchitecture : x64\nThreadSafe   : False\nFilename     : test.dll\n```\n\n### Caching downloads\n\nThis module downloads PHP and PHP extensions from internet.  \nIn order to avoid downloading the same files multiple times you can use `Set-PhpDownloadCache` to specify the path of a local folder where the downloads will be cached (to get the configured value you can use `Get-PhpDownloadCache`).\n\nBy default `Set-PhpDownloadCache` does not persist the configured value: you can use the `-Persist` option to store if for the current user only, or for any user.\n\nTo retrieve the currently configured value you can use `Get-PhpDownloadCache`.\n\nTo disable the cache, run `Set-PhpDownloadCache` without arguments (to make this setting persistent, use `Set-PhpDownloadCache -Persist CurrentUser` or `Set-PhpDownloadCache -Persist AllUsers`).\n\n\n## Supported platforms\n\nThis module is fully tested on Windows 10, Windows Server 2016, Windows Server Core, Windows Nano Server.\n\n\n## Test\n\nTests require some module (PSScriptAnalyzer, Pester, ...).  \nYou can run the `test\\setup.ps1` PowerShell script to install them.  \nThe `test\\pester.ps1` script executes all the tests, which are located in the `test\\tests` directory.\nYou can test a specific case by specifying its name:\n\n```powershell\n.\\test\\pester.ps1 Edit-FolderInPath\n```\n\nSome tests may require to run commands with elevated privileges. These tests are disabled by default: you can enable them by setting the `PHPMANAGER_TEST_RUNAS` environment variable to a non empty value:\n\n```powershell\n$Env:PHPMANAGER_TEST_RUNAS=1\n.\\test\\pester.ps1 Edit-FolderInPath\n```\n\nSome other tests require that [Node.js](https://nodejs.org) is installed and available in the PATH environment variable.\n\n\n## Do you want to really say thank you?\n\nYou can offer me a [monthly coffee](https://github.com/sponsors/mlocati) or a [one-time coffee](https://paypal.me/mlocati) :wink:\n\n\n## FAQ\n\n\n### What are [those executable](https://github.com/mlocati/powershell-phpmanager/tree/master/PhpManager/private/bin) in the archive?\n\nIn order to retrieve the name and the version of the locally available extensions, as well as to determine if they are normal PHP extensions (to be added to `php.ini` with `extension=...`) or Zend extensions (to be added to `php.ini` with `zend_extension=...`), we need to inspect the extension DLL files.\nThis is done with [this C code](https://github.com/mlocati/powershell-phpmanager/blob/master/src/Inspect-PhpExtension.c).\n\nYou could think that this code could be written in C# and included in the PowerShell scripts with the [`Add-Type -Language CSharp`](http://go.microsoft.com/fwlink/?LinkId=821749) cmdlet.\nSadly, we have to inspect DLLs that are compiled both for 32 and for 64 bits architectures, and the code would only be able to inspect DLLs with the same architecture used by PowerShell.\nSo if PowerShell is running in 64-bit mode we won't be able to inspect 32-bit DLLs (and vice versa).\nThat's why we need these executables: they will be started in 32-bit (`Inspect-PhpExtension-x86.exe`) or in 64-bit (`Inspect-PhpExtension-x64.exe`) mode.\n\nOf course you don't have to trust them: you can compile them on your own (it will require [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)) by calling the [`compile.bat`](https://github.com/mlocati/powershell-phpmanager/blob/master/src/compile.bat) script.\n\nThe folder also contains a couple of [7-Zip](https://www.7-zip.org/) executables (one for 32-bit systems and one for 64-bit systems): they are used by PhpManager to unzip the downloaded archives.  \nSure, we could use the standard [`Expand-Archive`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.archive/expand-archive) cmdlet, but these 7-Zip tools are about one order of magnitute faster than it.\n","funding_links":["https://github.com/sponsors/mlocati","https://paypal.me/mlocati"],"categories":["PowerShell","Development"],"sub_categories":["Programming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlocati%2Fpowershell-phpmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlocati%2Fpowershell-phpmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlocati%2Fpowershell-phpmanager/lists"}