Remembering the development environment caused by Chocolatey

Remember a development environment error caused by Chocolatey

前情

This morning When I went to work, I finished writing the code and started running the code as usual, but I kept reporting errors. Because I used redis, the error reported was still redis. The author is also very new to redis, so I thought it was because the local environment was pumped again. Go toss your own business.
The author started to write a simple CRUD case, and then found that the database connection failed. I checked whether the MySQL service is turned on, checked whether the account password is correct, and added a large piece of code to the comment, and finally output an error message: could not find driver (driver cannot be found).

Solution process

At first, the author of Caiji thought that the driver mentioned here refers to the drive letter file, because a database configuration is introduced in the database connection class written The file, he went to change the path again, but it was still wrong. I finally realized that the “driver” here should refer to the database driver, that is, the PHP database driver is not turned on.
Run echo phpinfo();, Ctrl+F to find it, and sure enough, this configuration file is not a commonly used configuration before.

The PHP version is the latest 7.3.9. It’s easy to think of an article I saw last night: “Basics of the Windows Unified Development Environment-Chocolatey”, probably I tried this package manager under Windows last night, and accidentally overwritten the original PHP environment.

After I want to understand, I start to solve it.

violent solution

At first, I thought that Chocolatey just added the newly installed PHP to the environment variable, covering the previous Yes, but when viewing the PHP version information in the terminal tool, it does not matter.

Well, after thinking about it, I’d better delete the entire folder where the newly installed PHP is located.
Unfortunately, two files php7.dll and PHP-CFG.exe are in use and cannot be deleted.

Open the resource manager, terminate a series of Nginx services, use the resource monitor to terminate the php.exe process, eh? ? ? Still can’t delete? ?

See php in “Services” again, right click decisively-stop. Go to delete the folder again and find that it can be deleted.

Delete the newly installed PHP, run the code again, and find that everything is working properly.


Thinking

After solving this problem, have time to think about a milder solution. Since this PHP environment is added by Chocolatey, there must be an uninstall method accordingly. Here is a summary of some operations on Chocolatey:

Chocolatey

  1. Installation: Run as an administrator cmdEnter the following code in the terminal tool

    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\ bin"
  2. Check if the installation is correct: the same is the cmd code

    choco -?
  3. Customize the installation location of Chocolatey (default is the default installation location of the system: C:\ProgramData\chocolatey)

    • New environment variable ChocolateyInstall, its value is a customized installation location
    • If the location does not exist, it must be created manually
    • Run the installation command. If it is already installed, you can run the installation command again and reinstall to the specified location.
  4. Use Chocolatey to install the software: Also run as an administrator cmd

    choco install phpchoco install php -ycinst phpchoco install nginx maria phpchoco install nodejs.install --version 10choco install choco. confi g
    • Adding -y after the installation command means that all options during the installation process default to OK
    • cinst is shorthand for choco install
    • install can be followed by multiple package names, indicating that multiple packages are installed at once Software package
    • install followed by .config file, indicating that the software package is installed according to the configuration file, which can unify the development environment

    .config is similar to:

      < package id="php" />    
  5. Upgrade package version: still cmd code

    choco upgrage php
  6. Uninstall the package: still the cmd code

    choco uninstall php
  7. Install the graphical interface :

    choco install chocolateygui

I haven’t really tried this tool yet. Let’s talk about it if you have the opportunity to use it.

Resources and Reference

  1. Chocolatey official website

  2. Windows unified development environment The basis of-Chocolatey

  3. The package manager Chocolatey under Windows

Leave a Comment

Your email address will not be published.