I am trying to use composer with my WampServer.
My path for all the files is C:\wamp64\www, but when I run composer it will install the vendor file and other stuff somewhere else.
I don't even know where and I can't change the path of where is my project.
I tried everything already and it still dose not seem to install the vendor file in my project folder.
Although it is an old post, it maybe useful as far as Wampserver exists, so the easiest fix is this:
Go to the "bin/php" folder inside you wampserver, usually at C:\wampXX\bin\php, and look for the php version used in your wampserver. You can navigate to http://localhost to find that, or click in the Wampserver icon on Windows taskbar (If yours doesn't have the version number aside, click on PHP -> Version and you'll see the checked one):
In the "bin/php" folder open the corresponding folder to your PHP
version, in my case "7.0.33" and copy this path:
Go to Windows Environment Variables, and in System Variables add that PHP's folder path you copied to Path variable (You can search on Google how to change a Path variable on your Windows version).
P.S.: In case you switch PHP version it won't work anymore, and you'll have to do that again. But now, changing for the correct PHP version folder.
After doing that, go to composer site download the windows installer.
CD into your projects root directory and run (which must contain a composer.json file):
composer install
That's it. Maybe a lot of work, but at the end it's all quite simple.
I don't use this hack any more. I think there are better tools to solve this problem, such as Laragon, LocalWP (if you develop Wordpress plugins/themes) or Devilbox (you need to install Docker to use Devilbox).
I don't know if the poster will read and vote this answer. I had this problem and solved it, and I want to share my research with 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
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:
Windows 10 Home Edition 64-bit
WampServer Version 3.1.3 64bit, reinstalled and with no errors
Windows Subsystem for Linux (WSL) Ubuntu installed
Visual Studio Code as text editor, with WSL bash as default integrated terminal
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.
Just run composer on your project folder.
Say your project path is on C:\wamp64\www\project0. So, just run composer install inside project0 folder. Composer will create vendor folder inside this project0 folder. This folder contain some folders of installed libraries.
Composer also generate a file composer.lock. This file contain information of installed libraries.
Then, when you want to use the libraries, please add this code inside your php file.
require_once "vendor/autoload.php";
This will call autoloader, so you don't need to use require_once anymore to load PHP Classess. Just call the Class using use keyword.
use Library0/Class0;
use Library1/Class1;
use Library2/Class2;
I used a different approach. I admit that it is dirty, and every time I switch PHP versions, I need to remember to update what I did, but well... it works :)
Go to C:\ProgramData\ComposerSetup\bin. There is a file there: composer.bat. This is executed every time you enter a composer install or a composer update command. Edit it with a notepad or any other text editor. You should see something like this:
#ECHO OFF
php "%~dp0composer.phar" %*
What we want to do is to give a direct path to php.exe, so let's comment out the current command and write our own:
#ECHO OFF
REM php "%~dp0composer.phar" %*
C:\wamp64\bin\php\php5.6.40\php.exe "%~dp0composer.phar" %*
Now everything works. But once you switch to another PHP version in Wampserver, you should update this file too.
By the way: a similar change can be done to make PHP sniffer or PHPUnit work too. Their bat files are in C:\Users\[your windows user]\AppData\Roaming\Composer\vendor\bin folder.
That answer is pretty bad. I have figured it out already on my own. I had to use cd commned in commend lines to get in this folder.
So after CMD i would type cd C:\wamp64\www\project0 thats proper answer to my problem.
Related
I am trying to get MAMP runing with PHP 8.1 but what I see as latest version for MacOS is 8.0.8, is there a way to run 8.1 ?
I have gone thru many tutorials in which they explain on how to switch from one of the installed versions but I can't seem to find a way to install additional PHP versions.
following up relating to #Quink's answer
8.1.0 is available in the dropdown (not in the picture because I already downloaded it)
then quit and restart mamp
then you can find the folder by opening phpinfo page and seeing the path
not sure if this is needed, but at this point I copied the folder and pasted it in the main MAMP/conf directory where all the other PHP versions are
I was looking for this myself. I found out that the easiest way to do this is to start your trial version of the pro. There you have the option to download/ install the php8.1 version. After this I switched back to the basic MAMP and everything is working properly
Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
get latest php version i.e. 8.1 for now
brew install php
Verify php
which php
php -version
now go to to /usr/loca/Cellar/php, copy php version folder you want i.e. 8.1 for now
go to Application/MAMP/bin/php and paste this folder
rename your folder like others i.e. "8.1.10_1" to "php8.1.10" in my case
at this point you can quite the mamp and reopen it and you will see php8.1 version in your mamp php version's dropdown
now go to your terminal and
/Applications/MAMP/Library/bin/apachectl start
and you will see an error i.e. Syntax error on line 160 of /Applications/MAMP/conf/apache/httpd.conf... in my case
to resolve this go to /usr/local/lib/httpd/ and copy the "modules" folder
now past it in /Applications/MAMP/bin/php/php8.1.10/
YOUR MAMP IS ALL SET BUT if you try to reach phpadmin you will see an error, for that
go to /Applications/MAMP/bin/phpMyAdmin5 and edit config.inc.php.
Locate this text: $cfg['Servers'][$i]['host'] = 'localhost' and change it to ``$cfg['Servers'][$i]['host'] = '127.0.0.1'`
Restart your server.
HOPE THIS HELP YOU
This YouTube Video answers this perfectly, and then follow this SO answer
You might also want to change your local connection host from localhost to 127.0.0.1
PS: Copy /usr/local/Cellar/php/8.<version_number>/lib/httpd/modules/libphp.so to /Applications/MAMP/bin/php/php8.<version_number>/modules/libphp.so
I did a fresh install of Ubuntu 20.04 LTS (Focal Fossa), installed Apache, PHP, MySQL and PHP Composer seemingly without issue. However, I still cannot get laravel -V to give me a version number.
I have looked at a multitude of YouTube videos and tried my interpretation of the recommendations found here on Stack Overflow. How can I fix it?
Here's the output on my shell $PATH.
You must add PHP Composer binaries folder to your $PATH if you'd like to call the binaries globally.
A) Make sure you have the latest Laravel installer:
composer global require laravel/installer
B) Add composer bin folder to your $PATH:
Edit your .bashrc file: gedit $HOME/.bashrc
Add the following line: export PATH="$PATH:$HOME/.config/composer/vendor/bin"
C) Use the source command to force Ubuntu to reload your .bashrc file:
source $HOME/.bashrc
D) Try to output Laravel installer's version:
laravel -V
Additional explanations as requested:
To execute a command from the Linux terminal, you need to tell Linux where the program is located.
For example, you could have launched Laravel installer using the full path: $HOME/.config/composer/vendor/bin/laravel -V
But instead, you wanted to be able to call the laravel -V command directly because you don't want to type the full path every time.
Since you are on Ubuntu, the default shell program is Bash. You need to tell Bash where to look when you type a command. In this case, you want Bash to look in the $HOME/.config/composer/vendor/bin/ folder.
The configuration file for Bash is a hidden file called .bashrc located in the user home folder. Bash stores the list of special folders in a variable called $PATH. To add a new folder, we simply added it to the $PATH variable.
If you type echo $PATH in your terminal, Bash will output the content of the $PATH variable and you will see a list of folders.
Now you may ask: "Why did I have to do this? I usually don't have to mess with my Bash configuration". Yes, this is because you usually install Ubuntu packages and they are configured to work out of the box. In this case, you installed a composer package in your home directory and it's therefore up to you to configure it the way you want.
You may need to do source $HOME/.bashrc every time you open u a new terminal windows and then do laravel -v
From the cmd line:
C:\Users\Lemur>pear install --onlyreqdeps Mail
Did not download optional dependencies: pear/Net_SMTP, use --alldeps to download automatically
pear/Mail can optionally use package "pear/Net_SMTP" (version >= 1.4.1)
downloading Mail-1.3.0.tgz ...
Starting to download Mail-1.3.0.tgz (23,110 bytes)
........done: 23,110 bytes
ERROR: failed to mkdir C:\php\pear\tests\Mail\tests
I see a newly created Mail folder in xampp\php\pear\Mail, which is correct, but the folder has no contents.
Also, the Error shows that install is attempting to put something at C:\php\pear\tests\Mail\tests. There is no such directory C:\php\pear...
What is wrong? Include_path in php.ini is correct (C:\xampp\php\pear).
Thanks in advance.
Found the answer here: http://davehiren.blogspot.com/2011/04/how-to-install-or-uninstall-pear.html. I'm using XAMPP and didn't realize all the path variables that needed to be changed. Once I altered all the path variables, the Mail package installed just fine.
For working with PEAR using XAMPP in Windows, it's important to avoid the command line in Windows and instead use the XAMPP Shell. Simply open the XAMPP Control Panel and click on XAMPP Shell on the right:
In the XAMPP Shell, you can enter your PEAR package installation command as you normally would and the packages will get installed in their proper place within XAMPP's PHP directory:
pear install --onlyreqdeps Mail
I am working on Mac El Capitan. I have MAMP Pro installed. I am attempting to install composer. Part of the process is making it accessible globally. I have gone in and done vim ~/.bash_profile and added: export PATH=/Applications/MAMP/bin/php/php7.0.0/bin:$PATH
I am using PHP 7.0.0. However when I save and exit (escape :wq) and then run which PHP it is still pointing to the original folder. I have exited out of the terminal window and come back in. I have also run source ~/.bash_profile. Still the which php version points to /usr/bin/php
Any suggestions for what to try next?
This solution worked for me except I ended up putting composer in an apps folder rather than in my usr/bin.
telliott.io/node/969
I have uninstalled Composer using the Windows uninstaller (I'm on Windows 8) and now when I run the Composer installer I get:
Composer is already installed in the following directory:
C:\wamp\bin\php\php5.5.12
You must remove it first, if you want to continue this installation.
Since obviously Windows did not completely remove it can anybody with more skills than me give me a tip on how to fix?
Remove the path C:\wamp\bin\php\php5.5.12 from your Environment variable, named Path in the System properties.