-
-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About configuring VSCode to interpret php #628
Comments
I think it is possible and some people have done it and there is a script somewhere but it would be really cool if someone can come up with a step by step guide and how to get this done with Devilbox. |
If you are talking about setting up XDebug with devilbox and VSCode: here you go |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@mrbig00 Is this the same as setting up XDebug? I don't think so. If we simply want VSCode to be able to access PHP inside the Devilbox container, what do we need to do? So regardless of project, just have VSCode "connect" to PHP inside the Devilbox container. How is that done please? |
@mozgbrasil Did you find a solution? Do you use XDebug or just have PHP be "available" inside VSCode regardless of project? |
Good Morning I installed php on the operating system And due to the operating system apache2 conflict with devilbox I'm using the practice of stopping apache sudo service apache2 stop |
I am using Devilbox and Docker to keep my OS free of Apache, NGINX, PHP, etc. @cytopia I am trying to "connect" PHP from inside the Devilbox container to VSCode on the OS. https://devilbox.readthedocs.io/en/latest/intermediate/configure-php-xdebug/linux/vscode.html#configure-php-xdebug-lin-vscode is for XDebug. But what if I just want to "connect" VSCode to PHP in the Devilbox container and not use XDebug? |
What is the reason or what is this useful for, If I might ask. |
Not sure if related but for me, running tools like phpcs (php code fixer), I have them currently pointed at the OS php install which is not really correct. It should be linked to the container in case you are using a different php version than your OS |
@cytopia What @Cipa wrote is exactly one of the reasons for example. Another reason would be to be able to use https://github.com/Automattic/VIP-Coding-Standards or https://github.com/squizlabs/PHP_CodeSniffer. In fact being able to do that would be truly awesome. On purpose I am keeping the host OS slim, fast and clean. |
@mozgbrasil @robots4life @Cipa as this is very VSCode specific and I've never used it, I am unfortunately out of any help to you guys. I would suggest to get support directly at the relevant VSCode places: |
@cytopia Ok, thank you. Can you explain, if I wanted to make PHP available outside the Devilbox container, other than through the browser, would I need to open a port or do something similar like change the .env file? Not sure if this applies but what if I wanted to check i.e. the version of PHP inside the Devilbox container but from the host OS in a console. How could I pass such a command to inside the Devilbox container? Where in the docs can I read up on the concept of making PHP available outside the Devilbox container? I guess this is more Docker specific, but if you have a topic in the docs that you think might be able to help even remotely, please let me know. Thank you. |
If you are in the Devilbox directory, you can use it as such:
|
Hi @robots4life, I am using the new VS Code Remote Development to accomplish this. Make sure you have one of the following extensions installed After installing these extensions all you need is a
This approach needs Devilbox to be up and running on forehand. When the extensions are installed AND the After reopening the project inside of the container you're also able to fire commands inside of the container straight away from VS Code's built-in terminal. For example |
@boumanb thanks for the detailed post. One more thing to sort is how to actually make the terminal start up as the |
No problem. Glad I can contribute in some way, truly a great project. Glad to see you active again. You're totally right. It's better to keep these permissions synchronized. However, I've not been able to find a solution for this. VS Code has some documentation on using a different user while developing remotely: https://code.visualstudio.com/docs/remote/containers-advanced#_adding-a-nonroot-user-to-your-dev-container Apparently when using the approach described above, we have to define the
|
Is this probably something where you could do: |
Normally, yes. But in my case Devilbox is running 24/7 in the background. The |
@boumanb Thank you! I will give all this a try and report back either way. |
Great, looking forward to your response! |
My workflow is such that I run node, npm, grunt, sass, etc. locally on the host in the project folder and like to do things like php coding standards or php code sniffer in the container. First, would you see an advantage in running everything in the container, while having HOST_PATH_HTTPD_DATADIR pointing to a local folder with all my projects? Meaning in those local folders just have the files for the project and have tools etc. in the containers. At the moment I am fine with having the tools mixed into the project folders. This means I need to have node and npm on the host what sometimes leads to minor issues when updates or different versions are required. I tried both ways and found that having things local is a bit faster. Would you see another advantage of running all the tools in the containers? Then I am not sure what package to pick from the two you mention. Like I said I do all the development locally and would only need to run the php tools in the container. What package is better suited for that? |
@CamdenGonzalez have you got a way to meet in chat, I have a feeling that could benefit both of us, the long term plan is to add documentation for how to use the available tools in a remote container in VSCode. If chat is not an option, can you elaborate on how you, if I understand you correct, got xDebug working over the browser and phpcs / php-cs-fixer working locally ? edit: Also under the #! /usr/bin/env bash
# VSCode remote container - php-cs-fixer
# 1. go to /shared/httpd/phptools
cd /shared/httpd/phptools
# 2. remove the current version and download the latest version
rm -rf php-cs-fixer
# 3. download php-cs-fixer into /shared/httpd/phptools
wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer
# 4. give executeable permission to php-cs-fixer
sudo chmod a+x php-cs-fixer
# 5. copy executeable php-cs-fixer to bin /usr/local/bin/ directory
sudo cp /shared/httpd/phptools/php-cs-fixer /usr/local/bin/php-cs-fixer
# 6. add php-cs-fixer to Devilbox's $PATH
PATH=$PATH:/usr/local/bin/php-cs-fixer
# 7. return to /shared/httpd
cd /shared/httpd
# Install PHP coding standards ..
Concerning phpcs and phpcbf I am looking at the following.
WordPress is not the focus here, though figuring out to to get rules, fixing and beautifying going with that might also help with the other standards. |
How to get SvelteKit working with Devilbox. #797 (comment) |
Thank you for all these informations! Possibly this information would also be suitable for the devilbox documentation like: II will try in any case to take up this approach in our Contao documentation or to extend it ... |
Cool. Let me know when its in and I can replicate it on the Devilbox documentation as well |
Check. |
So I don't forget: See: |
Unfortunately, I still have a question. Now I have installed the "Visual Studio Code Remote Development" pack as described here. It works so far. But:
Could anyone provide a working configuration/help for Xdebug usage in this environment? |
Addition: \devilbox\cfg\php-ini-7.4\xdebug.ini
\devilbox\data\www\demo\.vscode\launch.json
|
Now I need help with the procedure using "Visual Studio Code Remote Development" : \devilbox\data\www\demo\.devcontainer\devcontainer.json
As already mentioned it works then regarding using VSCode terminal (inside the devilbox php container with the user "devilbox") or using the "Intelephense" extension for example. The existing extension "PHP Debug" is now grayed out with the option to install it within the PHP container. Result: I then tried different entries in "xdebug.ini" and "launch.json". |
I am stuck as @fkaminski is. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Does anyone know how to install Vercel, Netlify and GitHub CLI to the Devilbox so they work from VS Code and are possibly kept installed between shut down and start (not when removing containers) ? |
In #! /usr/bin/env bash
# run this script
# chmod +x clis.sh
# ./clis.sh
npm install vercel -g
npm install netlify-cli -g Remember to Per docs, i.e. # Install grunt as devilbox user
# su -c "npm install grunt" -l devilbox asks for a password that I don't know and that is not the host password. But the CLIs are installed as the https://github.com/cli/cli/blob/trunk/docs/install_linux.md The GitHub CLI has a different approach to install and since |
Ive been using Devilbox for all of 2 hours, so Im not sure if I came up with a really simple way to solve this, or a terrible way, you be the judge, but it seems to be working for me 😂 All I did was :
This creates a symlink to the php binary, which is now also available on the host machine under your devilbox/data/www folder. I then Phenomenal project @cytopia thanks a mill, Im loving it so far. |
I subsequently found the following warning here in the documentation:
Considering Im doing the opposite, and adding the symlink inside the container, Im not sure if this warning is applicable, since my solution seems to work for me, and the PHP binary is available from my host system 🤷♂️ Im still learning docker, but it seems the most correct solution would be to create a read-only mount point to the appropriate target in the container, in the same way as the project folder is mounted. This would be to expose the PHP binaries (or any other desired binaries for that matter) more safely via a dedicated mounted directory? |
@patrict what are you trying to achieve ? Do you want VS Code to "connect" to Devilbox and work with Devilbox inside VS Code ? Happy to give you a quick "up and running" tour on how to get that working with VS Code, if that is what you want to do. |
@robots4life thanks a mill, appreciate it 😄 I have my data directory setup outside of the Devilbox directory now and can work on my projects, so that seems to be working correctly. What Im trying to achieve: |
@patrict are you on Linux or Windows? On Windows (+ WSL2) I was able to make things to work, while I have no direct experience on native Linux. |
@masiorama option C - Mac M1 😄 Just to clarify, my symlink did work, so I was just sharing my solution for comment, in case anyone had a better/alternative method |
Hi @patrict Thanks for your info you posted. It may be pointing me in the correct direction but I am wanting to take this a step further. My setup: Fedora 38 My startup script:
My default PHP is 8.2 and as you can see I am also loading PHP 7.4 and 8.1 In VSCode I want to take advantage of workspaces for each project and be able to set the interpreter for PHP to the PHP version that that workspace uses. This is something that is easy to do in vscode per workspace via the settings. Based on your symlink, would it be possible to enter into each php docker container and symlink each php docker container like this: PHP 8.2: ln -s /usr/local/bin/php php Then in vscode settings.json set: php.validate.executablePath="php" Depending on the workspace? |
Hmm, it does not seem to work for me. What I did: Using VSCode Docker extension, I attached the devilbox/php-fpm:8.1-work-0.150 container to a shell. Ran ln -s /usr/local/bin/php php81 On Fedora host machine: php81 -v does not work. Edit: I wonder if it is because I created the symlink as root? Let me try to figure out how to get vscode docker extension to attach as devilbox Attaching it as root, running su devilbox and then creating the symlink also does not work. Still says command not found. |
So I have the symlink working as long as I am inside the container:
However, outside the container it still fails:
I am guessing I am missing something though not sure how @patrict got it working unless it is something specific to MacOS. |
Hello, I'm using Google Translate, so I apologize in advance for any writing errors. To solve this problem, simply create a file called php in the root directory of your project and insert this code:
Then make it executable:
And in VSCode settings, assign this value:
|
I just recorded a video explaining how to solve this problem and I even added a bonus that helps start shell.sh automatically when opening VSCode. |
About configuring VSCode to interpret php
Hello my friend
Can you help me how to configure VSCode to interpret php
I need to point docker php to VSCode
It is possible ? Can you help me
The text was updated successfully, but these errors were encountered: