I would like to create a Symfony project. I have the same issue as many people concerning php version: Symfony uses the wrong one.
λ php -version
PHP 7.4.1 (cli) (built: Dec 17 2019 19:24:02) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
λ symfony -V
Symfony CLI version v4.12.4 (Tue Jan 14 13:09:08 UTC 2020)
λ symfony check:requirements
Symfony Requirements Checker
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> PHP is using the following php.ini file:
C:\xampp\php\php.ini
> Checking Symfony requirements:
..............WWW......W..
[OK]
Your system is ready to run Symfony projects
I have Xampp installed but I use Laragon with 7.4.1 on Windows 10 and wish to use that one, but Symfony tells me this:
λ symfony local:php:list
┌─────────┬─────────────────────────────────────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼─────────────────────────────────────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.3.10 │ C:\xampp\php │ php.exe │ │ php-cgi.exe │ PHP CGI │ * │
│ 7.4.1 │ C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64 │ php.exe │ │ php-cgi.exe │ PHP CGI │ │
└─────────┴─────────────────────────────────────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘
The current PHP version is selected from default version in $PATH
Even though there is no trace of Xampp or php 7.3.1 in my $PATH.
λ echo %path:;=&echo.%
C:\Program Files\cmder_mini\bin
C:\Program Files\cmder_mini\vendor\bin
C:\Program Files\cmder_mini\vendor\conemu-maximus5\ConEmu\Scripts
C:\Program Files\cmder_mini\vendor\conemu-maximus5
C:\Program Files\cmder_mini\vendor\conemu-maximus5\ConEmu
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Windows\System32\OpenSSH\
C:\Program Files\nodejs\
C:\Program Files\Git\cmd
C:\ProgramData\ComposerSetup\bin
C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64\php.exe
C:\Program Files\Symfony
C:\laragon\bin
C:\laragon\bin\apache\httpd-2.4.35-win64-VC15\bin
C:\laragon\bin\composer
C:\laragon\bin\laragon\utils
C:\laragon\bin\mysql\mysql-5.7.24-winx64\bin
C:\laragon\bin\nginx\nginx-1.16.0
C:\laragon\bin\ngrok
C:\laragon\bin\notepad++
C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64
C:\laragon\bin\putty
C:\laragon\bin\redis\redis-x64-3.2.100
C:\laragon\bin\telnet
C:\laragon\usr\bin
C:\Program Files\Sublime Text 3\
C:\Users\User\AppData\Local\Yarn\config\global\node_modules\.bin
C:\Users\User\AppData\Roaming\Composer\vendor\bin
C:\Users\User\AppData\Roaming\npm
C:\Ruby26-x64\bin
C:\Users\User\AppData\Local\Microsoft\WindowsApps
C:\Program Files\JetBrains\PhpStorm 2019.2.3\bin
C:\Program Files\JetBrains\DataGrip 2019.2.5\bin
C:\Program Files\Git\cmd
C:\Program Files\Git\mingw64\bin
C:\Program Files\Git\usr\bin
C:\Program Files\cmder_mini
(I checked user & system $PATH)
I tried to force Symfony into using 7.4.1 by running in a project directory:
λ echo "7.4.1" > .phpversion
When I run
λ symfony local:php:refresh
λ symfony local:php:list
I get:
λ WARNING the current dir requires PHP "7.4.1" (.php-version from current dir: C:\laragon\www\CMS_test\.php-version), but this version is not available
I also tried renaming the Xampp directory name, and as a matter of fact, that "works".
C:\
λ symfony check:requirements
php does not seem to be available under C:\xampp\php
C:\
λ symfony local:php:list
┌─────────┬─────────────────────────────────────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼─────────────────────────────────────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.4.1 │ C:\laragon\bin\php\php-7.4.1-Win32-vc15-x64 │ php.exe │ │ php-cgi.exe │ PHP CGI │ * │
└─────────┴─────────────────────────────────────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘
The current PHP version is selected from default version in $PATH
But that solution isn't really satisfying to me.
I've search StackOverflow for several hours, tried to re-install Symfony, restart the computer, ask friends etc no one seem to have another solution.
So, why does Symfony search for php in a Xampp directory ? Is it possible to choose another default one like Laragon's ? Any idea ?
I just had this problem on my Windows environment. For some reason, symfony is not reading .php-version correctly when I create it using echo "7.2" > .php-version.
The problem was gone once I deleted and created a new text file from my IDE. Probably creating it using vscode code .php-version or using the File Explorer would work too (I didn't try it, yet).
Edit: I just tried creating the file with VS Code and Notepad - Both worked. But I still don't know why it doesn't work when creating with echo...
Edit2: I think I got it. Looks like PowerShell's echo "" > file will create the file with UTF-16 encoding. After converting the file to UTF-8 it worked as expected.
Just delete your .php-version file and create in manually from your ide! With the from encoding (using echo from terminal) the error message was
the current dir requires PHP ��7.4.10
you can see the encoding is wrong by the question marks.
Creating the file from the ide fixed my problem!
Related
I am trying to move few of my Symfony projects into one monorepo. This is my structure.
packages/
├─ symfony-project-1/
│ ├─ public/
│ │ ├─ index.php
│ ├─ composer.json
├─ symfony-project-2/
│ ├─ public/
│ │ ├─ index.php
│ ├─ composer.json
vendor/
composer.json
I use package symplify/monorepo-builder to merge all of my project's composer.json file into the root one. Then I split my packages to READ-ONLY repositories.
To production, I would like to deploy the READ-ONLY repository. So for example, only the content of the directory symfony-project-1 would be transferred to the production server and the vendor folder would be installed directly to the same directory. Here comes the problem.
How can I make the front-controller index.php load ./../../../vendor in development and ./../vendor in production?
The index.php looks normally like this:
<?php
// public/index.php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
I tried this:
...
if (is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
$autoloadPath = dirname(__DIR__).'/vendor/autoload_runtime.php';
} else {
$autoloadPath = dirname(__DIR__).'/../../vendor/autoload_runtime.php';
}
require_once $autoloadPath;
...
But then Symfony tries to read .env file from the root of the monorepo not the project root (I get this: Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "/Users/xxx/work/monorepo/.env" environment file.).
How to solve this in monorepo?
Hi I have a project that uses composer to handle mongo libraries, if I debug with a "test cli application" as console application it works fine, as soon as I try to run it as "run on server" it "looses" autoload.php. The server is a native eclipse's php server
my project directory tree is:
D:\EclipseWorkspace-GIT\mongowithcomposer
├───src
│ ├───MongoHandler
│ ├───WebContent
│ │ ├───js
│ │ ├───resources
│ │ │ └───images
│ │ ├───DEFINITIONS.PHP
│ │ ├───HOME.PHP
│ │ └───style
│ └───XML-Handler
├ COMPOSER.JSON
├ COMPOSER.LOCK
└───vendor
├───composer
├─── AUTOLOAD.PHP
└───mongodb
└───mongodb
├───.github
│ └───ISSUE_TEMPLATE
├───.phpcs
├───.travis
├───docs
│ ├───.static
│ ├───includes
│ ├───reference
.......
this is the error I got:
Warning: require_once(D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer\autoload.php): failed to open stream: No such file or directory in D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer\definitions.php on line 10
NOTE: In the tree output the files are higlighted by being UPPERCASE
EDIT:
this is the server automatic path mapping:
<Server>
<Port name="HTTP/1.1" protocol="HTTP">8181</Port>
<PathMapping local="/mongowithcomposer/vendor/composer" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
<PathMapping local="/mongowithcomposer/src" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
<PathMapping local="/mongowithcomposer/vendor/mongodb/mongodb/src" module="mongowithcomposer" remote="D:\Eclipse-Workspace-GIT\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\htdocs\mongowithcomposer"/>
</Server>
This is PDT bug. In current implementation rather than just run php -S it copy .buildpath dirs into separate dir, and then run server.
I have a plan to fix this for in Eclipse 2020-09 and already prepared issue for this: https://github.com/eclipse/pdt/issues/68
today I wanted to learn something about symfony and start with basic project setup but it seems like it doesnt work. Here's my steps:
I have created new project by writing:
composer create-project symfony/skeleton my_project '4.4.*'
it went well.
I started local server with:
symfony start:server
server started without any problems.
My routing looks like this:
index:
path: /
controller: App\Controller\DefaultController::index
myController:
public function index() {
return new Response('IT WORKS!');
}
But instead of my response im getting
unable to fetch the response from the backend: malformed MIME header
line: [info] Matched route "index".
Why is this happening? I couldn't find anything.
It seems like this issue is not happening if you create project based on symfony 4.3.. as I did. I have no idea why it didn't work on 4.4. thou.
I got the same problem. I think it is a recent bug of Symfony https://github.com/symfony/cli/issues/274.
My temporary solution is to remove PHP CGI, so Symfony CLI is force to use PHP CLI.
When you run symfony local:php:list, if you saw PHP CGI in the table:
┌─────────┬────────────┬─────────┬─────────┬─────────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼────────────┼─────────┼─────────┼─────────────┼─────────┼─────────┤
│ 7.4.6 │ /usr/local │ bin/php │ │ bin/php-cgi │ PHP CGI │ * │
└─────────┴────────────┴─────────┴─────────┴─────────────┴─────────┴─────────┘
Try to remove it by running apt remove php-cgi, or if you are in a Docker image, add this line instead RUN rm /usr/local/bin/php-cgi:
┌─────────┬────────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Version │ Directory │ PHP CLI │ PHP FPM │ PHP CGI │ Server │ System? │
├─────────┼────────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ 7.4.6 │ /usr/local │ bin/php │ │ │ PHP CLI │ * │
└─────────┴────────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
I am trying to implement PSR-4 autoloading in my project. It is an existing application I have inherited that doesn't currently use OOP (it's all scripted), but I am hoping to refactor over time to use OOP, and PSR-4 is crucial for me as it will end up being a large project.
At this present time we do not rely on any external libraries (old application entirely written in-house), so composer is ONLY being used for autoloading at this moment in time, but will use third-party packages eventually such as phpunit.
My app structure on my server looks like this:
/var/www/appurl/
│ composer.json
│
├───htdocs
│ ├───AppName
│ │ ├───admin
│ │ │ authenticated.php
│ │ │ init.php
│ │ │ login.php
│ │ │
│ │ └───php
│ │ └───search.php
│ └───Framework
│ ├───Helpers
│ │ └───OSHelpers.php
└───vendor
│ autoload.php
│
└───composer
autoload_classmap.php
autoload_namespaces.php
autoload_psr4.php
autoload_real.php
ClassLoader.php
composer.json:
{
"autoload": {
"psr-4": {
"Framework\\": "htdocs/Framework"
}
}
}
login.php calls authenticated.php when a user successfully logs in, and authenticated calls my init.php script which contains:
<?php
require_once('../../../vendor/autoload.php');
?>
it is search.php that has the error. The user is redirected to search.php when they are authenticated.
search.php has the lines:
use Framework\Helpers\OSHelpers;
$current_os = OSHelpers::GetConciseOSFromUserAgent($user_agent);
OSHelpers.php is namedspaced as: namespace Framework\Helpers;
the static call to OSHelpers works fine if require_once is used, but the 2nd line where I define $current_os is where it appears to be failing.
The error I receive is:
Fatal error: Class 'Framework\Helpers\OSHelpers' not found in /var/www/appurl/htdocs/AppName/php/search.php on line 829
I'm at a bit of a loss about why it does this? When I follow the example in this video (https://www.youtube.com/watch?v=VGSerlMoIrY) my example app works fine, but trying to replicate this in a slightly more complicated structure is giving me problems.
I have done composer dump-autoload -o, and looking within the vendor directory shows that my classes are defined correctly. From vendor/composer/autoload_classmap.php:
'Framework\\Helpers\\OSHelpers' => $baseDir . '/htdocs/Framework/Helpers/OSHelpers.php',
I've been banging my head on this for weeks now. I've found many people with similar issues, and have gotten a little farther towards solving my issue, but not all the way.
WAMPserver 2.5 (PHP 5.5.12)
I originally installed Pear, but something was messed up (paths in config were crazy?), so I tried installing again, and then things got really messed up, so I removed everything Pear-related (except the pear subdir because Windows complained that a file in it was in use, even though it was empty), and gave Pyrus a shot. Now things seem to be working better at least as package management.
I believe I have my include_path(s) set correctly because now my script can at least find the Mail.php script.
include_path = ".;C:\wamp\bin\php\php5.5.12\pear\php"
my call, working:
include_once("Mail.php");
However, Mail.php is now complaining that it can't find Pear.php:
Failed opening required 'PEAR.php' (include_path='.;C:\wamp\bin\php\php5.5.12\pear\php') in C:\wamp\bin\php\php5.5.12\pear\php\Mail.php on line 46
There is no Pear.php file anywhere under \php5.5.12.
Is this happening because I'm using Pyrus, and Mail is set up to work in a Pear environment? (Even though Pyrus claims to be "Using PEAR installation found at C:\wamp\bin\php\php5.5.12\pear", see below.) Do I have to install both Pear and Pyrus? Should I use pyrus.phar to install Pear? As noted above, previous attempts to install Pear were less than successful. The documentation for both Pear and Pyrus could be improved by having a graphic depicting how a standard install ought to look like in terms of subdirs, etc. This is how my include_path branch looks like now:
c:\wamp\bin\php\php5.5.12\pear\php>tree /f
Folder PATH listing for volume OS
Volume serial number is A4D7-1271
C:.
│ Mail.php
│
├───Auth
│ │ SASL.php
│ │
│ └───SASL
│ Anonymous.php
│ Common.php
│ CramMD5.php
│ DigestMD5.php
│ External.php
│ Login.php
│ Plain.php
│ SCRAM.php
│
├───Mail
│ mail.php
│ mock.php
│ null.php
│ RFC822.php
│ sendmail.php
│ smtp.php
│ smtpmx.php
│
└───Net
SMTP.php
Socket.php
Here's my Pyrus config:
c:\wamp\bin\php\php5.5.12>php pyrus.phar get
Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52
Using PEAR installation found at C:\wamp\bin\php\php5.5.12\pear
System paths:
php_dir => C:\wamp\bin\php\php5.5.12\pear\php
ext_dir => c:\wamp\bin\php\php5.5.12\ext\
cfg_dir => C:\wamp\bin\php\php5.5.12\pear\cfg
doc_dir => C:\wamp\bin\php\php5.5.12\pear\docs
bin_dir => C:\wamp\bin\php\php5.5.12
data_dir => C:\wamp\bin\php\php5.5.12\pear\data
www_dir => C:\wamp\bin\php\php5.5.12\pear\www
test_dir => C:\wamp\bin\php\php5.5.12\pear\tests
src_dir => C:\wamp\bin\php\php5.5.12\pear\src
php_bin => C:\wamp\bin\php\php5.5.12\php.exe
php_ini => C:\wamp\bin\php\php5.5.12\php.ini
php_prefix =>
php_suffix =>
Custom System paths:
User config (from C:\Users\mrz\pear\pearconfig.xml):
default_channel => pear2.php.net
auto_discover => 0
http_proxy =>
cache_dir => C:\wamp\bin\php\php5.5.12\pear\cache
temp_dir => C:\wamp\bin\php\php5.5.12\pear\temp
verbose => 1
preferred_state => stable
umask => 0022
cache_ttl => 3600
my_pear_path => C:\wamp\bin\php\php5.5.12\pear
plugins_dir => C:\Users\mrz\pear
(variables specific to pear2.php.net):
username =>
password =>
preferred_mirror => pear2.php.net
download_dir => C:\wamp\bin\php\php5.5.12\pear\downloads
openssl_cert =>
handle =>
paranoia => 2
Custom User config (from C:\Users\mrz\pear\pearconfig.xml):
(variables specific to pear2.php.net):
Any help will be greatly appreciated.
Update: I tried
php pyrus.phar install pear/PEAR
as shown on https://pear.php.net/package/PEAR/.
I get:
c:\wamp\bin\php\php5.5.12>php pyrus.phar install pear/PEAR
Pyrus version 2.0.0a4 SHA-1: 72271D92C3AA1FA96DF9606CD538868544609A52
Using PEAR installation found at C:\wamp\bin\php\php5.5.12\pear
Downloading pear.php.net/PEAR
Mime-type: application/octet-stream
Downloading pear.php.net/Archive_Tar=================================================================>] 100% (284/284 kb)
Mime-type: application/octet-stream
Downloading pear.php.net/Structures_Graph============================================================>] 100% (19/19 kb)
Mime-type: application/octet-stream
Downloading pear.php.net/Console_Getopt==============================================================>] 100% (12/12 kb)
Mime-type: application/octet-stream
Downloading pear.php.net/XML_Util====================================================================>] 100% ( 5/ 5 kb)
Mime-type: application/octet-stream
[====================================================================================================>] 100% (16/16 kb)
Warning: rename(C:\wamp\bin\php\php5.5.12,C:\wamp\bin\php\.old-php5.5.12): The process cannot access the file because it is bein
g used by another process. (code: 32) in phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0a4/php/Pyrus/AtomicFileTransacti
on/Transaction/TwoStage.php on line 82
Call Stack:
0.0350 1218224 1. {main}() C:\wamp\bin\php\php5.5.12\pyrus.phar:0
0.0580 2198784 2. Pyrus\ScriptFrontend\Commands->run() C:\wamp\bin\php\php5.5.12\pyrus.phar:69
0.0970 3600832 3. Pyrus\ScriptFrontend\Commands->install() phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0a4/ph
p/Pyrus/ScriptFrontend/Commands.php:309
0.1110 4364600 4. Pyrus\Installer::commit() phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0a4/php/Pyrus/ScriptF
rontend/Commands.php:559
8.9739 11845424 5. Pyrus\AtomicFileTransaction::commit() phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0a4/php/P
yrus/Installer.php:344
8.9739 11845496 6. Pyrus\AtomicFileTransaction\Manager->commit() phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0
a4/php/Pyrus/AtomicFileTransaction.php:90
8.9919 11845456 7. Pyrus\AtomicFileTransaction\Transaction\TwoStage->commit() phar://C:/wamp/bin/php/php5.5.12/pyrus.pha
r/Pyrus-2.0.0a4/php/Pyrus/AtomicFileTransaction/Manager.php:165
8.9919 11845488 8. rename() phar://C:/wamp/bin/php/php5.5.12/pyrus.phar/Pyrus-2.0.0a4/php/Pyrus/AtomicFileTransaction/Tr
ansaction/TwoStage.php:82
Pyrus\Installer\Exception: Installation failed
Pyrus\AtomicFileTransaction\MultiException: ERROR: commit failed
Pyrus\IOException: CRITICAL - unable to complete transaction, rename of actual to backup path failed
Pyrus\AtomicFileTransaction\RuntimeException: Cannot rollback - not in a transaction
Why is it trying to rename my entire php5.5.12 directory? Or is it? FTW?
Update: OK, I manually installed Pear. Changed include_path to
include_path = ".;C:\wamp\bin\php\php5.5.12\pear"
and my call to
include_once("php\Mail.php");
And I've gotten past the "missing" Pear.php error. But now, Mail can't find Net_SMTP, etc.
Gack. Do I have to specify a separate include_path entry for each extension? Or, should I get rid of \php and move its contents into \pear, with associated code and config changes? Or just dump all the extension files (without dir tree) into the same www dir as my script?
Easiest to do, without moving files, would be this:
include_path = ".;C:\wamp\bin\php\php5.5.12\pear;C:\wamp\bin\php\php5.5.12\pear\php"
But there really shouldn't be a subdirectory. Mail.php should be in the same directory as Pear.php.
(I use this stuff on Linux though, so I don't know how this particular distribution normally sets things up.)