PHP Composer behind http proxy - php

I use composer on a network where the only way to access the internet is using HTTP or socks proxy. I have http_proxy and https_proxy environment variables. When compose tries to access HTTPS URLs I get this:
file could not be downloaded: failed to open stream: Cannot connect to HTTPS server through proxy
As far as I know the only way to connect to a https website is using a connect verb. How can I use composer behind this proxy?

If you are using Windows, you should set the same environment variables, but Windows style:
set http_proxy=<your_http_proxy:proxy_port>
set https_proxy=<your_https_proxy:proxy_port>
That will work for your current cmd.exe. If you want to do this more permanent, y suggest you to use environment variables on your system.

If you're on Linux or Unix (including OS X), you should put this somewhere that will affect your environment:
export HTTP_PROXY_REQUEST_FULLURI=0 # or false
export HTTPS_PROXY_REQUEST_FULLURI=0 #
You can put it in /etc/profile to globally affect all users on the machine, or your own ~/.bashrc or ~/.zshrc, depending on which shell you use.
If you're on Windows, open the Environment Variables control panel, and add either a system or user environment variables with both HTTP_PROXY_REQUEST_FULLURI and HTTPS_PROXY_REQUEST_FULLURI set to 0 or false.
For other people reading this (not you, since you said you have these set up), make sure HTTP_PROXY and HTTPS_PROXY are set to the correct proxy, using the same methods. If you're on Unix/Linux/OS X, setting both upper and lowercase versions of the variable name is the most complete approach, as some things use only the lowercase version, and IIRC some use the upper case. (I'm often using a sort of hybrid environment, Cygwin on Windows, and I know for me it was important to have both, but pure Unix/Linux environments might be able to get away with just lowercase.)
If you still can't get things working after you've done all this, and you're sure you have the correct proxy address set, then look into whether your company is using a Microsoft proxy server. If so, you probably need to install Cntlm as a child proxy to connect between Composer (etc.) and the Microsoft proxy server. Google CNTLM for more information and directions on how to set it up.

If you have to use credentials try this:
export HTTP_PROXY="http://username:password#webproxy.com:port"

Try this:
export HTTPS_PROXY_REQUEST_FULLURI=false
solved this issue for me working behind a proxy at a company few weeks ago.

This works , this is my case ...
C:\xampp\htdocs\your_dir>SET HTTP_PROXY="http://192.168.1.103:8080"
Replace with your IP and Port

on Windows insert:
set http_proxy=<proxy>
set https_proxy=<proxy>
before
php "%~dp0composer.phar" %*
or on Linux insert:
export http_proxy=<proxy>
export https_proxy=<proxy>
before
php "${dir}/composer.phar" "$#"

iconoclast's answer did not work for me.
I upgraded my php from 5.3.* (xampp 1.7.4) to 5.5.* (xampp 1.8.3) and the problem was solved.
Try iconoclast's answer first, if it doesn't work then upgrading might solve the problem.

You can use the standard HTTP_PROXY environment var. Simply set it to the URL of your proxy. Many operating systems already set this variable for you.
Just export the variable, then you don't have to type it all the time.
export HTTP_PROXY="http://johndoeproxy.cu:8080"
Then you can do composer update normally.

Operation timed out (IPv6 issues)#
You may run into errors if IPv6 is not configured correctly. A common error is:
The "https://getcomposer.org/version" file could not be downloaded: failed to
open stream: Operation timed out
We recommend you fix your IPv6 setup. If that is not possible, you can try the following workarounds:
Workaround Linux:
On linux, it seems that running this command helps to make ipv4 traffic have a higher prio than ipv6, which is a better alternative than disabling ipv6 entirely:
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"
Workaround Windows:
On windows the only way is to disable ipv6 entirely I am afraid (either in windows or in your home router).
Workaround Mac OS X:
Get name of your network device:
networksetup -listallnetworkservices
Disable IPv6 on that device (in this case "Wi-Fi"):
networksetup -setv6off Wi-Fi
Run composer ...
You can enable IPv6 again with:
networksetup -setv6automatic Wi-Fi
That said, if this fixes your problem, please talk to your ISP about it to try and resolve the routing errors. That's the best way to get things resolved for everyone.
Hoping it will help you!

according to above ideas, I created a shell script that to make a proxy environment for composer.
#!/bin/bash
export HTTP_PROXY=http://127.0.0.1:8888/
export HTTPS_PROXY=http://127.0.0.1:8888/
zsh # you can alse use bash or other shell
This piece of code is in a file named ~/bin/proxy_mode_shell and it will create a new zsh shell instance when you need proxy. After update finished, you can simply press key Ctrl+D to quit the proxy mode.
add export PATH=~/bin:$PATH to ~/.bashrc or ~/.zshrc if you cannot run proxy_mode_shell directly.

Related

How can I use PHP's built-in webserver with Symfony on Windows, with a specified hostname and nonstandard port?

EDIT: Sorry everyone, this isn't something you could have fixed! The AppKernel class had been modified to change the cache directory, as below:
public function getCacheDir()
{
if(isset($_SERVER['HTTP_HOST']))
{
return $this->rootDir.'/cache/'.$this->environment.'/'.$_SERVER['HTTP_HOST'];
}
else{
return $this->rootDir.'/cache/'.$this->environment.'/default';
}
}
So not down to Symfony, or PHP, but a previous developer (presumably not on Windows!). Thanks for all your help, +1s all round.
I'm hoping there's a simple answer to this, but right now I can't see it!
Windows 10
Symfony 2.8.11
PHP 5.5.9
For convenience, I'd like to use PHP's built-in webserver (via the Symfony Console) to run a Symfony (2.8) application, on a port other than 80. I have a colleague successfully doing this, but he's using Linux, and I'm on Windows 10. The issue is that, on anything other than the standard port 80, when Symfony builds its cache the port is appended to one of the directory names, with a colon, which is illegal in Windows filenames (although not elsewhere). The cache build process fails, and the app doesn't run.
I'm starting the PHP server via Symfony's Console, like so:
php app/console server:run appname.local
The directory it's trying to build is:
C:\git\appname\app/cache/dev/appname.local:8000
And so I get the error:
RuntimeException in bootstrap.php.cache line 2763:
Unable to create the cache directory C:\git\appname\app/cache/dev/appname.local:8000)
I'd just use the standard port (this does work), but in fact I want to run several things at once, and they can't all be on 80.
Is there any way I can run a Symfony site on PHP's webserver, on Windows, on a non-standard port, in such a way that Symfony doesn't choke at the point of building the cache? For clarity, I could change webserver, and I could change OS, but for the purposes of this question assume that those are fixed. I'd prefer not to switch off the cache (it's slow enough as it is!) but that's an option if it would help.
EDIT: it seems like this works for at least some people, so there must be something different about my config. Best bet is probably the PHP version, which is quite old (not for any particular reason, just laziness).
Symfony has a command to run a webserver (which uses the php built-in PHP server)
php bin/console server:start
This command will start the server on port 8000 (default config)
Have a look here for more information about available options : https://symfony.com/doc/current/setup/built_in_web_server.html
to start the server on a particular port specify the port after the IP address from the command line. Using the IP address is useful too, because you can access from a different host.
For example, let's say you run ipconfig /all and you see your IPv$ address is 192.168.1.100. Then you can run:
php bin/console server:start 192.168.1.100:8888
This starts Symfony's built-in web server on port 8888 on IP address 192.168.1.100. So in a browser you can enter: http://192.168.1.100:8888/ where / is the route you want to access.
To stop the built-in server enter:
php bin console server:stop 192.168.1.100:8888
You'll see messages on the command line showing the stopping/starting of the built-in web server.
As in my question edit, this was down to developer action rather than a Symfony or PHP issue to be solved by the community.
public function getCacheDir()
{
if(isset($_SERVER['HTTP_HOST']))
{
return $this->rootDir.'/cache/'.$this->environment.'/'.$_SERVER['HTTP_HOST']; //KABOOM
}
else{
return $this->rootDir.'/cache/'.$this->environment.'/default';
}
}
Thanks for all your efforts!
public function getCacheDir()
{
if(isset($_SERVER['HTTP_HOST']))
{
return str$this->rootDir.'/cache/'.$this->environment.'/'.str_replace(':','_', $_SERVER['HTTP_HOST']);
}
else{
return $this->rootDir.'/cache/'.$this->environment.'/default';
}
}
a colon isnt a valid character for filesystem filename, so replace it with underscore.

Use Lampp mysqldump as default in php call

tricky question and I don't know if SO is the good space (maybe AskUbuntu ? or SuperUser ?)
I've set my Lampp on my ubuntu in /opt/lampp/
Problem, when I need to call direct bin as mysqldump, I end up calling the default installed one on my ubuntu, not the one linked to my lampp :
$ mysqldump --user=root test
mysqldump: Got error: 2002: Can't connect
to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
when trying to connect
As you can see, it check for /var/run.
If I want to use the good one, I should specify the path :
$ /opt/lampp/bin/mysqldump --user=root test
-- MySQL dump 10.13 Distrib 5.6.21, for Linux (x86_64)
I could use the full path in my PHP call, but my PHP prod server will then not work.
How can I set the Lampp bin as default to be used by php with exec('mysqldump')?
You really have several choices to do what you want.
You could create a configuration file that depends on your environement (local, dev, preprod, prod ...). This file may declare an array of configurations, one of which is the path of the executable you need. Your php code will know the environment by checking a global variable, for instance $_SERVER, which can be set in your web server's vhost file. I think that's the clean way of doing.
You could hardcode a path for you executable (let's say /home/www/mysqldump) and create a symbolic link with ln -s (if I remember right, or check the man page) between your environment's executable /opt/lampp/bin/mysqldump and /home/www/mysqldump. You have to prepare all your environments that way. I think it's a bit ugly but it's quick.
I am sure there are tons of other solutions.

PHP CURL is using a environment variable that I didn't set

I'm using WAMP. In the past weeks I struggled a lot to make php and curl work behind a corporate proxy, finally I did it: Apache behind corporate proxy
The problem is that now I can't make them work at home! (of course initially they were working at home without proxy). When I run a CURL command from php I get the following error: Curl error: Failed to connect to localhost port 3128
I removed all the environment variable https_proxy and http_proxy, on apache I removed the "proxy_module", on IE I removed the proxy, now when I run the following command there are no results:
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" | find /i "proxyserver"
It seems that CURL is taking the proxy configuration from somewhere in the environment variable, in fact if I add the applicative code:
curl_setopt($ch,CURLOPT_PROXY, '');
then everything is working fine (but I don't want to change the applicative code). Where else can I look for the proxy confing?
Thanks very much

Command executed in PHP with Centos7 and Apache isn't able to connect to network?

I'm debugging my PHP app on CentOS7 using Apache.
My application is a Web GUI to manage the Torque batch system and I used the qmgr, which is a command line tool provided by Torque to do the management work.
Because only the root user can execute the qmgr and the Apache server cannot be running as root user, I have written a C program as a wrapper for anyone to execute commands as root user.
But the PHP application always give the following output:
socket_connect_unix failed: 15137
qmgr: cannot connect to server (errno=15137) could not connect to trqauthd
This means the PHP app cannot raise a socket connection to connect the Torque server.
Here is some additional information:
The command called by the PHP application can be executed correctly in the shell
The same PHP app can be executed correctly on a CentOS6 server with Apache
SELinux and the firewall are disabled
I have tried the two versions (5.1 and 4.10) of Torque, the result is the same
Apache and PHP are used with the default RPM's of CentOS7.
I thought there are some new security limits that maybe influence Apache on the CentOS7 server.
Please give me some suggestions, thank you!
I had the exact same problem.
The cause is that newer Apache.httpd versions default to having the systemd property PrivateTmp set to true. This causes the httpd service to see a private /tmp directory that is actually mapped to some other location in the file system, instead of the real /tmp directory. PHP, running in the Apache process, has the same /tmp directory as the Apache service, and so do any processes forked from PHP (e.g. using exec or system etc). So when PHP calls qsub (etc), that too will see the private /tmp directory.
This causes the error you mentioned because qsub internally uses the unix socket /tmp/trqauthd-unix to communicate with trqauthd. But qsub sees the "fake"/private /tmp directory instead of the real one, so it doesn't find the socket.
This explains why the command works when you run it manually in a console--in that case, qsub sees the real /tmp directory, as opposed to the private one it sees when forked from PHP (running the Apache service).
One solution is to simply change the PrivateTmp property in the file httpd.service from true to false. You can find this file under the /etc/systemd directory. The subfolder it is in probably depends on the linux distribution, so use the find command to locate it:
find /etc/systemd -name httpd.service
This really helped me!
I have been struggling a lot having a php script using exec()-command. For some reason I got permission denied. Having tried vary many things, including running my scripts in shell as the www-data user, but with no success, this was finally the solution to my problem.
BTW, for Ubuntu the apache service config file is located at cat /etc/systemd/system/multi-user.target.wants/apache2.service

ViewSVN fails to run saying unsupported URL

I'm trying to setup ViewSVN for viewing our subversion repository.
My SVN repository uses https for access. However, irrespective of supplying svn://, svn+ssh:// or https:// in the viewsvn configuration for my svn repository, I always get this in my apache log:
svn: URL protocol is not supported 'https://my.repository.com'
Everything of course works perfectly when running from the commandline.
my localconfig.php file defines the svn root server as
$config['svnroot']='https://my.repository.com';
One other thing- I am using JavaSVN.
Do you happen to have multiple versions of SVN installed, e.g. ViewSVN using /usr/bin/svn whereas you are using /usr/local/bin/svn or something like that?
[EDIT]
I don't know JavaSVN but maybe it behaves differently when run by different users. Maybe it doesn't load additional plugins you need to handle different protocols. Do you have superuser access to your machine? Try to run the checkout from the command line as the web server user:
su nobody
svn checkout https://...
I have the "port number" and the "root folder" added in svnroot, like the follwoing
$config['svnroot']='https://my.repository.com:8088/svn';
I use TortoiseSVN and it shows my svnroot, I think JAVASVN has the same feature.

Categories