How to set PHP path in VSCode using WSL-Remote ddev container? - ddev

I'm using ddev in WSL2 & trying to use https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs that asks for php.validate.executablePath.
I don't want to install PHP locally on WSL as that won't be a packaged solution. I hope there's a way to access PHP from my local ddev's docker container.
This answer resolves the issue https://stackoverflow.com/a/66376387, but I'm unable to understand the laravel thing there & my goal is to make it ddev generic so that I can use it in multiple projects.

Thank you, #rfay, for providing such a valuable tip. This is how I followed your instructions:
Created a file named 'php' at /usr/local/bin using sudo touch /usr/local/bin/php
Made it executable: sudo chmod +x /usr/local/bin/php
Edited the file (with sudo) using sudo vim /usr/local/bin/php
Added the following code:
path=$(printf '%s\n' "${PWD##*/}")
command="ddev php "$#""
$command
I did all the above operations to the WSL2 Ubuntu container.

Related

Laravel Sail is not working properly in Ubuntu 20.04 LTS

Hi i tried to install fresh Laravel project using
Laravel Sail
docker environment. First it was showing me "Docker is not running" error. Then i found out, i needed to start docker as rootless. I solved it, reading this url: [https://docs.docker.com/engine/install/linux-postinstall/].
After that, I successfully installed Laravel using Laravel Sail. Then I ran
./vendor/bin/sail up -d
I was able to view Laravel project in my browser. But when i ran any other artisan commands such as ./vendor/bin/sail artisan route:list or sail commands as sail shell, all the docker containers were forced closed automatically. It shows me this error.
Sail is not running.
You may Sail using the following commands: './sail up' or './sail up
-d'
Any suggestions? I am getting this issue on Ubuntu 20.04 LTS version.
If you are on Windows and using WSL, make sure the WSL Integration is properly set:
Settings->Ressources->WSL Integration + Toggle Linux version
I was using Laradock before installing Laravel Sail. Maybe there were some conflicts. So I backed up all my databases, then I removed all containers using this code. sudo docker rmi -f $(docker images -a -q). Then installed fresh Laravel project and it worked.
Please read my below comment as it is was a better solution for me.
very easy, maybe you don't have permission to run docker.
in Linux first use sudo -s and after user ./vendor/bin/sail up -d
Sail first checks to see if any current docker-compose processes have a status of Exit. If any of them have, then it will forcefully bring down all other services. Which is what you were are seeing whenever you type any sail sub-command. You can see the code here: https://github.com/laravel/sail/blob/87c63c2956749f66e43467d4a730b917ef7428b7/bin/sail#L44-L49
Run sail up to start the processes and then use docker-compose ps to check all services are running and none have an Exit status.
I had the same issue and when reviewing the code and checking my services I noticed the database had exited soon after I brought them up.

Can't execute composer.phar in shared hosting

I've installed Composer on a shared-host (hostgator) following this guide:
https://laravel.io/forum/02-13-2014-how-to-install-laravel-on-a-hostgator-shared-server
It was installed using this command:
curl -sS https://getcomposer.org/installer | php
When I try to run composer I get the message "/home2/georger/composer.phar: no such file or directory" although the file does exist, I can open it. Other questions that deal with this suggest moving it to /usr/local/bin but that's not an option for me.
As outlined in the installation instructions, you will need to pass it to the php interpreter:
$ php composer.phar
Alternatively, you might want to reconsider whether you really want to execute composer in a production environment or rather execute it during the deployment and then deploy the artifacts. In other words, you probably want to run composer install on the machine from which you want to deploy to the production system, and then synchronize files from there to the production system, for example, using rsync.
For reference, see https://getcomposer.org/doc/00-intro.md.

Can't find /root/.composer/vendor/bin/laravel: No such file or directory

I have installed composer on Centos 7 virtualbox with PHP 5.6.27. I will show the commands that I have used and the issues that I am now having. I should first say that all of these commands have worked on previous installations.
Okay so for starters here is what I used to install composer.
curl -sS https://getcomposer.org/installer | php
Followed by
mv composer.phar /usr/local/bin/composer
Now I am trying to install laravel via the commands listed below.
composer global require "acacha/adminlte-laravel-installer=~3.0"
Up to this point all of the commands listed above have successfully worked.
Now here is the current problem. When I try to run the following command I get an error.
laravel new laravel-with-admin-lte
-bash: /root/.composer/vendor/bin/laravel: No such file or directory.
I have tried a whole set of remedies for this message but it cannot find the .composer directory. Can anyone tell me where the correct .composer directory is and how I can modify it so that it looks to the proper location to finalize this installation?
I appreciate any solutions that you can provide me. I have struggled with this for two days straight and have googled everything under the sun. Hopefully, someone on here has had a similar solution with a valid resolution.
Put an alias to the freshly installed Laravel installer in your user configuration .bashrc:
nano ~/.bashrc
And place this inside the file:
alias laravel='~/.config/composer/vendor/bin/laravel'
And run the following to make sure your bashrc profile is reloaded:
source ~/.bashrc
laravel new project
download as superuser
download installer
sudo composer global require "laravel/installer=~1.1"
setting up path
export PATH="~/.composer/vendor/bin:$PATH"
check laravel command
laravel
I had the same problem, so I changed the directory.
This is the directory where your bash was created: /root/.config/composer
enter image description here
but when excute the laravel command, the system search en the directory : bash: /root/.composer/vendor/bin/laravel:
enter image description here
So, just you need to change the address /root/.config/composer/vendor to /root/.composer/vendor.
PD. sorry I am learning english, so it is a little bad.

Where can i find a hyperlink to symfony 2.7

I can't download the zip file symfony2.7. The link on the website doesn't work. Does anyone know why? Where can i find the symfony 2.7-zip file? I found an older version somewhere on the internet but i would really like the latest stable version.
if you really MUST have a zip : https://github.com/symfony/symfony-standard/archive/2.7.zip
also, a simple search would have revealed this
Wich is where i got this answer form .. so yea, use search next time ...
use the symfony installer, as documented on their website here
snip
Linux and Mac OS X Systems:
Open your command console and execute the
following commands:
sudo curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony
This will create a global symfony command in your system.
Windows Systems:
Open your command console and execute the following
command:
c:\> php -r "readfile('http://symfony.com/installer');" > symfony
Then, move the downloaded symfony file to your project's directory and
execute it as follows:
c:\> move symfony c:\projects c:\projects\> php symfony
snip
You can then use it to install a specifi version using
symfony new my_project_name 2.x.x
I always used to install it through or via the create-project command:
composer create-project symfony/framework-standard-edition project_name
If you want a 2.7 version
composer create-project symfony/framework-standard-edition project_name '2.7.*'
if there is no 2.7 stable version at the time of this writing, you need to lower the stability to dev:
composer create-project symfony/framework-standard-edition project_name '2.7.*' -s dev
-s (--stability.)

what is phpmd and how to use it?

I have Ubuntu 14.04 + Sublime text 3 and installed phpcs packages
additionalty I have installed phpcs and php-cs-fixer on my system
From this blog
I have found that phpmd (PHP Mess Detector) is also a required library, so installed phpmd as per given instructions on official php md page using alternative method From the github repository everything was finished.
:~/phpmd$ curl -s http://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
Composer successfully installed to: /home/keshav/phpmd/composer.phar
Use it: php composer.phar
but now when I write on terminal
phpmd /opt/lampp/htdocs/myproject, myfile.php
phpmd: command not found
There is phpmd folder on Home directory and everything without any error.
I have local project on core PHP create composer.json in project folder as per suggested on github .
Please tell me what means by
Then install Composer in your project (or download the composer.phar directly):
I think the problem is you've installed phpmd in a local directory, but you're trying to use it as if it was installed globally.
Installation instruction on the referenced sites can't really be made any clearer. Since you've already installed phpcs and php-cs-fixer, and those work for you, just follow similar instructions for phpmd. These are all PHP projects and are installed in a similar way.
Anyway, to use phpmd as a global command you have several options.
Github
Clone the github repository just like you did and add the phpmd bin directory to your PATH variable.
Global composer installation
Use the composer global command to install phpmd globally. You will also need to make sure that composer's bin directory is in the PATH. By default it's ~/.composer/vendor/bin.
composer global require phpmd/phpmd
This command will install phpmd globally, and as soon as ~/.composer/vendor/bin is in your PATH you'll be able to call it by simply invoking phpmd.
It's very well explained in composer's documentation: https://getcomposer.org/doc/03-cli.md#global
Download the phar archive
This is the simplest thing you can do. Simply go the phpmd releases, choose the latest and download the phar archive.
Put the phar file to whatever place you'd like. Just remember that it needs to be in your PATH. You can also rename it, to skip the .phar extension.
For example:
wget http://static.phpmd.org/php/2.1.3/phpmd.phar
sudo mv phpmd.phar /usr/bin/phpmd
sudo chmod +x /usr/bin/phpmd
Docker container
First, fetch the docker image with static analysis tools for PHP:
docker pull jakzal/phpqa
One of the tools provided by the image is phpmd. The command below will run phpmd in a docker container and mount the current working directory as a /project.
docker run -it --rm -v $(pwd):/project -w /project jakzal/phpqa \
phpmd src text cleancode,codesize,controversial,design,naming,unusedcode
When you use the composer-based install, it gets installed into the ./bin directory within the ./vendors directory. So for me, relative to my project's root directory, it was here:
./vendor/bin/phpmd
And I was able to run it from my project's root by running ./vendor/bin/phpmd . text codesize. (I'm not getting any useful output yet, but another issue)

Resources