PhpStorm - WSL2 - PHPUnit - Configure CLI Interpreter - php

I upgraded to WSL2 from Windows 10.
With PhpStorm, in my project that I switched under my WSL, I try to launch PHPUnit. But I have this error :
Error in bootstrap script:
Symfony\Component\Dotenv\Exception\PathException: Unable to read the
"\WSL$\UBUNTU\home\toto\symfony\myProject/.env" environment file.
By looking in the parameters at the CLI Interpreter level, I saw that there was still my Windows config:
So, if the problem is there, I imagine that I have to make sure to take the PHP Executable from my WSL. Except that .. well impossible to find it
I have the file in usr/bin/php, or usr/bin/php7.4, but neither is accepted. And in \etc\php\7.4, I have these 3 folders:
But the same, there's nothing in it that can be accepted.

You are using a PHP interpreter of the Local type, while you need to use the WSL type. Here's what the UI looks like:
Click the + icon, choose From Docker, Vagrant, VM, WSL, Remote..., and choose WSL in there.

Related

Broken output view from WSL terminal with Docker & Laravel

when i doing commands in terminal i got outputs looking like this:
As you can see, the problem is that the terminal does not display successive lines of the result from the beginning of the line, only from the place where the previously displayed line ends.
It is very uncomfortable to use today. The problem happens on the WSL console with the php artisan commands which I have to use because I have a project created with Laravel on Windows 11 using Windows Subsystem for Linux, Ubuntu and Docker.
How i can fix this?
UPDATE
The same happens when I use WSL outside of the IDE (PHPStorm), from the Windows directly in Ubuntu.

How do I setup my host machine's PHP interpreter to point to the container's PHP interpreter

I would like to configure PHPStorm so that I can run Artisan commands directly from my IDE's terminal. For example php artisan key:generate. However, when I do, I receive the error 'php' is not recognized as an internal or external command.
Background:
running Windows 10 as host machine
using Docker to run my webserver (Nginx) and PHP interpreter (7.2-fpm).
I followed this tutorial.
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose.
One thing the tutorial didn't cover was how to set up my remote PHP CLI interpreter. For that, I followed https://www.jetbrains.com/help/phpstorm/configuring-remote-interpreters.html and can make a successful connection as it picks up the correct PHP version 7.2.21 as seen in the screenshot.
After this, I restarted my Windows 10 host machine, fired up the container, opened my IDE and tried to run php -v from the terminal but hit the error again.
I know it has something to do with my PATH environment variable being set incorrectly, or not at all but I am not sure how to point it to the container's PHP interpreter. Any help would be greatly appreciated.
EDIT
For what it is worth, I know that I can exec into the container and run PHP commands from there, but thought I might be able to do it directly from my host machine by pointing to the container's interpreter.
The terminal in PHPstorm is the same as any other terminal on your computer. It doesn't automatically connect to docker to run the php -v command. If you want to run php from PHPstorm in docker you can right click the file:
Choose run:
And select your created docker interpreter as your runtime:
If the fix button doesn't show it can be configured through:
settings > Languages & Frameworks > PHP
And then clicking on the 3 dots at the end of "CLI interpreter"

How to use Laravel Homestead for development

I know this might sound really silly, but I'm kinda stuck and need help. I'm trying to use Laravel 5.3 and use Homestead as my IDE. I have previously worked on PHP using NetBeans and XAMPP, but the installation has always been a pain. I have no formal training and have learnt and used basic PHP on my own for my webpages.
I'm running a Windows 8-32Bit OS & here's what I've done so far:
I have downloaded Laravel using Composer.
I have installed Virtual Box & Vagrant.
I have installed Git Bash and ran vagrant box add laravel/homestead (Homestead.yaml was not found in my Homestead folder after running bash init.sh command. I downloaded it from Github and added there).
Set SSH Key.
Ran vagrant up in Homestead folder (the installation was complete).
Issues:
If I just type http://localhost:8000 in my browser, nothing happens. I have to run php artisan serve in the command prompt inside laravel directory and keep the prompt window open for the default Laravel 5 page to open.
If I type http://127.0.0.1:8000 in my browser, nothing happens at all.
So how do I use Homestead then for my development everyday ?
you can try
localhost/project-name/public
if you dont want to run php artisan serve

After installing Git on windows, I cannot check version or any commands using execution of other programs. What's wrong?

I installed Git version 2.6.2.windows.1. After installing, any other programs in my PATH environment variable will display a flash console whenever I check their versions.
For example, from current pointer, I run "node -v" or "php --version" (both node & php are in PATH), the result which I got is a new console just flashes.
I think the content of any commands above are displayed in that console.
And in main console which I run command to check just like below:
This thing causes so many problems for me .
I tried to setup debug on my ide - phpstorm. But it seems not to recognize php version. Because the result is displayed in a new console and that console will be disappeared most immediately.
So could anybody help me fix this?
First, forget cygwin.
Then (for a Windows 64 bits), uncompress or install in path without spaces and in lowercase (so not the default C:\Program Files\..., but rather C:\prgs\git or C:\prgs\php for instance):
php-7.0.1-Win32-VC14-x64.zip
PortableGit-2.6.4-64-bit.7z.exe
node-v4.2.3-x64.msi (it is an installer, see "How to Install Node.jsĀ® and NPM on Windows", but use a simpler path like C:\prgs\node)
phpstorm (you already have it in your case)
In a brand new CMD session, type:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Windows\system32
set PATH=%PATH%;c:\prgs\php\bin
set PATH=%PATH%;c:\prgs\git\nodejs
cd c:\path\to\phpstorm
PhpStorm.exe
In that new PhpStorm editor, configure the path of php, and see if the issue persists.

Weird PHP Parse/Syntax errors with VMWare 6.5 + PHP 5.3.3 + Symfony 1.4

While following the "Practical Symfony" course, I have run in a strange error.
I have installed a Debian Squeeze in a VMWare 6.5.5 machine. It comes with PHP 5.3.3 and I am using Symfony 1.4. The source files are on the host, I am accessing them using the shared folder feature (vmhgfs mount).
Now, when I try the following commands, I get an error:
php symfony doctrine:build --model
php symfony doctrine:build --sql
Error:
PHP Parse error: syntax error, unexpected ')' in /var/www/appli/lib/model/doctrine/base/BaseJobeetJob.class.php on line 144
What is funny is that when I :
- do the same thing without the shared folders (e.g. on a ext3 partition), it works,
- convert the VM to VirtualBox and do the same thing on a shared folder, it works,
- downgrade the PHP to 5.2.6 (from lenny), it works.
I remember having the same kind of issue some time ago with the PHP code generated by Smarty. As it was automatically generated PHP and could be regenerated at will, I had it generated in a local direcorty. But I do not think this is applicable to Doctrine generated files.
Does anyone have any clue of what is happening and how I could fix it ?
EDIT: here is the code around line 144:
public function setUp()
{
parent::setUp();
$this->hasOne('JobeetCategory', array(
'local' => 'category_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
$timestampable0 = new Doctrine_Template_Timestampable();
$this->actAs($timestampable0);
}
} // Line 144 here.
It is actually the end of the file...
EDIT #2: to make it clear I have tested the following combinations in order to narrow down the issue:
VM software : VMWare Workstation
6.5.5 / VirtualBox 4.0.8
PHP version: 5.3.3 / 5.2.6,
Mount type : vmhgfs (or vboxsf with VirtualBox) / ext4 (local)
/ cifs (aka Windows share).
In every case I am using the very same source files (but for ext4 because I had no other choice than to copy them). I have a failure when combining the bold items. If I change any one of them, everything goes fine. I also tried to use the open-vm-modules in place of the provided vmware tools and to build a Debian installation from scratch instead of using my own automated script but neither has changed anything.
This seems to be a bug in vmhgfs - I have the same issue working with Drupal PHP code. It also seems to only happen when the files are added to the host from the guest, for example using git to clone a repository in the Linux VM.
There are three workarounds:
Copy the files into their desired location, then disable shared folders in VMWare settings for the virtual machine, refresh the web page so you get 'Not found', then re-enable shared folders.
On the host machine, run the following command which updates the file access / modified timestamps for every file, thus causing the VMWare driver to reload the file, fixing the issue:
find . -exec touch {} \;
Open the affected file from the host machine, modify it, and save it back. This may be useful if you're on a Windows machine.
The errors range from PHP Parse errors to others, normally flagging the last line of the file.
I have the same problem on OpenSUSE 11.4 with PHP 5.3.5 using vmhgfs (on a Mac). I am also using doctrine, however I am using it without the full symfony project.
Initially vmhgfs didn't work at all, so I downloaded the open-vm-tools and compiled/installed that. That solved my problem for a few weeks, but it came back today.
The issue appears to be php reading past the end of the file. If I read the file with cat, less, or tail, then the end of the file looks fine.
But if I do php -s bad_file.php > bad_file.php.html and look at the html output, I can see at the end of the file there is some extra garbage that I don't see with with cat, less, or vim.
You can see that php sees "array (" at the end of the file, while other tools do not see that.
The only solution I've found is to manually add a new, blank line at the end of each problematic file. For some reason it only affects 1-2 files out of about 40.
Same problem here. I confirm that it is a vmhgfs problem.
A workaround is to use a NFS share instead of vmware shared folders:
Linux env
apt-get install portmap nfs-common nfs-kernel-server
mkdir /nfs-share1
echo "/nfs-share1 192.168.2.1(rw,sync)" >> /etc/exports
/etc/init.d/portmap start
/etc/init.d/nfs-kernel-server start
/etc/init.d/nfs-common start
usermod -u 501 paolo
find / -user paolo -exec chown paolo {} \;
OS X env
showmount -e 192.168.2.129
mkdir /Users/paolo/netshare1
mount -t nfs -o resvport,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp 192.168.2.129:/nfs-share1 /Users/paolo/netshare1/
Ugh! Finally I figured it out. I'm using VMware Fusion (4.0.2) on Mac OS X Lion (10.7.2) and I've been pulling my hair out trying to figure this out.
Upgrade your VMware Tools!
So far, so good: Haven't encountered the problem again. The latest release at this time is VMware Tools 8.0.0.
Well, this might be off topic, but I hope it helps:
I am working on the same book, and I have done this (I think you'd better do something like me):
Installed Ubuntu Server inside VirtualBox
Installed LAMP Server on Ubuntu
Installed vsftpd, for ftp access on Ubuntu
Installed SSH server on Ubuntu.
Now, if I am on Linux host, I use Aptana Studio with ftp access for editing files and SSH to run commands, and if I am on Windows, I use Aptana Studio and Putty for SSH access.
If you do something similar, you will probably have no trouble.
Hope it helps.
I am also experiencing this problem in regards to Wordpress and Laravel. To fix the problem, I have to remount the mounted folder from the guest.
For instance, all my source files are located on the host (OSX) and shared to Ubuntu (guest) with vmhgfs. The mount point is /mnt/hgfs/www. To remount:
sudo mount /mnt/hgfs/www

Categories