# Windows - PowerShell PHP Install ###### tags: `PHP` `Windows` `Technology` > **Date**:2023/02/07 > **Taker**:Sin ## Reference 1. [PowerShell PHP Manager](https://github.com/mlocati/powershell-phpmanager) ## Installation 1. If PHP is already installed, please remove the PHP environment variables (EVs). 2. Check the PowerShell version. It should be greater than 5. ```bash $PSVersionTable.PSVersion.ToString() ``` 3. Install PhpManager using the following command: ```bash Install-Module -Name PhpManager -Repository PSGallery -Force ``` 4. To work with multiple PHP installations, use the following commands: ```bash Install-Php -Version 8.1 -Architecture x86 -ThreadSafe $true -Path C:\Dev\PHP8.1 -TimeZone UTC Install-Php -Version 8.2 -Architecture x86 -ThreadSafe $true -Path C:\Dev\PHP8.2 -TimeZone UTC ``` 5. Initialize the PHP Switcher, specifying the location where the current PHP version should be available: ```bash Initialize-PhpSwitcher -Alias C:\Dev\PHP -Scope CurrentUser ``` 6. Add the installed PHP versions to the PHP Switcher: ```bash Add-PhpToSwitcher -Name 8.1 -Path C:\Dev\PHP8.1 Add-PhpToSwitcher -Name 8.2 -Path C:\Dev\PHP8.2 ``` 7. After completing the above steps, you can switch the current PHP version by calling the `Switch-Php` command: ```bash Switch-Php 7.4 php -r 'echo PHP_VERSION;' ``` 8. Set the PHP environment variables (EVs) to `C:\Dev\PHP`. ## Install Composer 1. Enable the necessary PHP extensions: ```bash Enable-PhpExtension curl Enable-PhpExtension fileinfo Enable-PhpExtension pdo Enable-PhpExtension gd Enable-PhpExtension openssl Enable-PhpExtension mbstring Enable-PhpExtension exif Enable-PhpExtension zip Enable-PhpExtension opcache(Optional) ``` 2. Install the `xdebug` and `redis` PHP extensions: ```bash Install-PhpExtension xdebug Install-PhpExtension redis (Optional) Enable-PhpExtension xdebug Enable-PhpExtension redis ``` 3. Manage `HTTPS/TLS/SSL` Certification Authority certificates: ```bash Update-PhpCAInfo ``` 4. Install Composer: ```bash Install-Composer ``` 5. Remove the `composer.lock` file and the `vendor` directory in your project. 6. Run `composer install`: ```bash composer install ``` 7. Upgrading PHP ```bash! Update-Php ``` ## Troubleshooting ### Issue: `php artisan serve` fails to listen If you encounter the error `Failed to listen on 127.0.0.1:8000 (reason: ?)` when running `php artisan serve`, follow these steps: 1. Open `php.ini` and add the `variables_order` setting: ```text variables_order = "GPCS" ``` ### Issue: `php artisan migrate` could not find driver If you encounter a driver error when running `php artisan migrate`, follow these steps: 1. Open `php.ini` and add or enable the `pdo_mysql` extension: ```text ... extension=pdo_mysql ... ```