0

You are all probably familiar with the Chrome page that says

localhost refused to connect. Try:

Checking the connection
Checking the proxy and the firewall

This is what I get when I try to navigate to a url on my site. Under the Network tab of inspect element, I see Status (failed), Type document, and Initiator other. I have never worked on this page, so I hadn't needed Composer until now. I believe it's the only page that uses Composer.

To download Composer, I followed the directions here, and then ran composer install on my git terminal in VS Code. This creates a /vendor/ directory (included in the .gitignore file) as well as a composer.phar file. There is also a composer.json and composer.lock, but these I already had pulled from a repo (they aren't listed in .gitignore).

After installing, I ran the Composer Setup, running it for all users, not selecting Developer mode, and choosing a command-line PHP in the directory of MAMP (the server I use for localhost) for PHP 7.2.10. This is the same version as my environment in VS Code, and it caused different problems when spinning up MAMP until I changed my MAMP preferences from 7.1.20 to 7.2.10.

It then asks "Use a proxy server to connect to internet." I thought (think) MAMP is a proxy server, so I checked the box for yes then entered "localhost." I believe this added "localhost" as an environment variable (Control Panel->System Properties->Advanced->Environment Variables) under the list of my user variables (NOT System variables) under the variable name http_proxy. I finished up setup and it warned me about PHP versions for Windows OneDrive. To be specific, on the CLI I've similarly seen

The Windows OneDrive folder is not supported on PHP versions below 7.2.23 and 7.3.10. Upgrade your PHP (7.2.10) to use this location with Composer.

I'm assuming this isn't my problem because I'm not using OneDrive for anything.

MAMP threw a lot of errors when I tried to start it up until I changed the version preferences, as I had mentioned. After that was fixed, it wouldn't work, so I tried to uninstall and install with using http://localhost as my proxy url, but I couldn't because it was already hardcoded in my environment variables. When I eventually figured that out and tried to change it, Composer couldn't install with that proxy url. So I believe "localhost" is correct IF I were to want to include anything at all. Someone told me they didn't think I should've checked "Use a proxy server to connect to internet." So as of now, I have deleted http_proxy in my Windows environment variables and am using none when setting up Composer.

I tried composer update, composer install, and uninstalling Composer as it shows here and here, but because composer.json and composer.lock are included in the repo and the vendor file is in .gitignore, I don't think I ever completely uninstalled and deleted. The two composer commands above gave me back

Nothing to install, update or remove

I can't remember what I ran originally to get this error message, but I would see:

[Composer\Downloader\TransportException] Unable to user a proxy: malformed http_proxy url

and if I ran composer diag, I always got that message, and the same error as you can see in this image. I just ran it now to replicate that code, but I got all OKs. I recently had someone send me their zipped vendor directory and replaced mine with it. I thought with their vendor directory I still got that composer diag error, but I definitely still wasn't able to connect to the site. This is the first time I've gotten all OKs, but I still can't connect to the site. This makes me think the composer.lock from the repo possibly didn't like the composer stuff from my local install. The composer.json just has a few lines of code, so I don't think that could be it.

My composer.phar has:

<?php
if (extension_loaded('apc') && filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) && filter_var(ini_get('apc.cache_by_default'), FILTER_VALIDATE_BOOLEAN)) {
    if (version_compare(phpversion('apc'), '3.0.12', '>=')) {
        ini_set('apc.cache_by_default', 0);
    } else {
        fwrite(STDERR, 'Warning: APC <= 3.0.12 may cause fatal errors when running composer commands.'.PHP_EOL);
        fwrite(STDERR, 'Update APC, or set apc.enable_cli or apc.cache_by_default to 0 in your php.ini.'.PHP_EOL);
    }
}

Phar::mapPhar('composer.phar');
require 'phar://composer.phar/bin/composer';

__HALT_COMPILER(); ?>

and about 60 lines of code of a bunch of ? symbols and empty squares along with intermittent english like src/Composer/Autoload/AutoloadGenerator.php. This makes VS Code throw an error on the 100K+ lines of code below __HALT_COMPILER(): ?> I'm not sure if this is a problem, or if it's okay because it's just a compile problem, and the compiler is supposed to halt right before it. I'm also not sure why that function is in all caps... I tagged Visual Studio Code because I'm not sure if it is wrong to throw this error after __HALT_COMPILER(): ?>.

Besides that, it could be my Windows proxy settings, like Google Chrome suggests. This seems unlikely because the rest of my site is fine.

I'm not sure what the problem is, but now that composer diag isn't throwing any errors, it seems like the most pressing issue would be fixing my composer.phar, or at least determining if it is a problem.

Thank you everyone for your help. I desperately need it!

Joey
  • 41
  • 2
  • Please share more details - usually, your application does not "use" Composer – Nico Haase Jan 15 '21 at 09:22
  • Composer is being used to require a dependency for Azure. My composer.json has only the following:"{ "require": { "microsoft/azure-storage-blob": "*" } } and the webpage that won't load has the following: "use MicrosoftAzure\Storage\Blob\BlobRestProxy;" – Joey Jan 15 '21 at 17:21

0 Answers0