简体   繁体   中英

How can I repair my wamp server after install composer in windows 10?

Mainly after to install composer for windows 10 my wamp didn't work anymore.

I explain that I tried in order to workaround this issue:

  1. Delete another versions: I read this question , My wampserver has assigned the correct version, and I don't want to delete my another versions.
  2. Install Composer manually: I tried to install the composer manually but the problem persist, I don't know if there is something pending to do wamp server side.

@echo OFF
:: in case DelayedExpansion is on and a path contains ! 
setlocal DISABLEDELAYEDEXPANSION
@C:\wamp\bin\php\php5.6.38\php.exe "%~dp0composer.phar" %*

There is an error.

There is Wampserver path (c:/wamp)
into Windows PATH environnement variable: (C:\wamp\bin\php\php5.6.38)

It seems that a PHP installation is declared in the environment variable PATH C:\wamp\bin\php\php5.6.38

Wampserver does not use, modify or require the PATH environment variable.
Using a PATH on Wampserver or PHP version
is detrimental to the proper functioning of Wampserver.

I add the image that I can see on wamp server icon: Message of wampserver

I'll republish my solution here, because I think it solves your problem perfectly and it is not so adequate to the question where it was posted . I hope it will help other people


TL; DR

  • In Windows 10, you can have Composer without producing an error in Wampserver if you install it on the Windows Subsystem for Linux (WSL) environment.
  • Install PHP on WSL
  • Then install Composer on WSL

Additional note : Please, keep in mind that if your project needs an additional PHP extension , you will have to install it in the WSL side.

Then, enable the extension in the php.ini file located in the folder /etc/php/YOUR_PHP_VERSION with the command:

sudo nano /etc/php/YOUR_PHP_VERSION/php.ini

The problem

In Windows, Composer requires to set the system variable PATH to work properly during the installation; it doesn't matter if it is installed globally using the Windows Installer or locally, following this procedure

However, inserting the executable PHP file location in PATH causes an error in Wampserver, the ERROR C:/wamp64 or PHP in path . You can see the error message if you left-click on the Wampserver icon in the notifications area of the task bar.

Although Wampserver may work as usual, it could eventually fail according to the answer to this question on the official Wampserver forum :

Wampserver does not create paths in PATH system environment variable.

Wampserver does not use PATH system environment variable.

Some content - paths to PHP or mysql versions - of the PATH system environment variable can create Wampserver malfunctions because PHP configuration files (php.ini) or MySQL (my.ini) are searched first in the paths indicated by the contents of the PATH environment variables before being searched in the Apache, PHP or MySQL folders .

That is why, with version 3.1.3, the content of the PATH environment variable is checked and you are notified if there is a problem.

If your Wamperserver installation suffers already of this error, then

  • follow the advice from the Wampserver forum ,

  • back up the content of your www folder,

  • uninstall Wampserver,

  • reinstall Wampserver.

If you have Windows 10 and followed the previous steps, then you are ready to implement the solution I propose.


The solution

The only solution I found in my research was explained in this tutorial by Jeff Geerling . My answer follows this tutorial in a somewhat loose way.

My starting point

These were the settings of my PC when I began this procedure:

Although Visual Studio with the WSL integrated terminal is not strictly necessary, I had it set because I intended to install and use Composer with it.

1 - Install PHP on WSL

To work correctly, Composer needs PHP but WSL does not come installed with it. So it is necessary to install PHP in this enviroment. According to this answer in AskUbuntu.com , the easiest way to install PHP on WSL is adding Ondřej Surý's PPA . In the Visual Studio Code WSL integrated terminal, type:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Test that PHP was installed correctly typing php --version . If PHP was installed correctly, the terminal will return a message like:

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

2 - Install Composer on WSL

There are two ways to do it:

The easier one: just type on the integrated terminal sudo apt-get install composer and that will be it.

The second one, and a better approach in my opinion: go to the Composer download page and get the installation code:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Warning: Do NOT copy/paste the code provided in this tutorial to install Composer . According to the Composer download page , the installation code

will change with every version of the installer.

The best practice here is to get the installation code directly from the download page.

I think this method is a better approach because, with the given code, it is possible to verify the SHA384 of the file and make sure it has not been tampered with.

If you installed Composer through the installation code from the developer website, in order to put that file into the global path on WSL, move the composer.phar file into the /user/bin/local folder with the bash command:

sudo mv composer.phar /user/bin/local/composer

If you installed Composer with the first command, this last step won't be necessary.

To check that the software was installed correctly, type composer on the integrated terminal. You should view a list of composer calling options and available commands.

Keep in mind that, to use Composer, you will need to type the commands in the WSL terminal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM