How do you make a Symfony command run globally - php

We say that I have built a really awesome Symfony console application called HelloWorld. I now want it to be available everywhere on my computer, so I can run "helloworld" and it will output "HELLO WORLD". How would one accomplish such a thing? I've thought about adding it to my aliases file but I feel like there's a better way than that.

First this has nothing to do with php, symphony2 or console. This is about OS.
You need to put that application on a folder that is in PATH or add that folder to the PATH environment variable. This is OS dependent.
For Ubuntu:
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-my-path
For Windows:
"Register" an .exe so you can run it from any command line in Windows

If you're using Linux, just add an alias to it in your .bashrc file:
alias mycommand='/usr/bin/php /path/to/myapp/app/console my:command'

Related

PHP and composer command don't work without admin CMD

I have problem with my PHP and composer. I have set environment variables:
But whenever I call php or composer I get an error:
It's weird, because when I start cmd as an admin it works. But I want it to work always, because its much easier to write cmd to navigation path which opens the command line in exact path I use and don't need to write cd commands every time I need something.
Have you tried installing composer with the Windows GUI? If I remember correctly, it sets up your path variables itself.
https://getcomposer.org/doc/00-intro.md#installation-windows
You could try adding the same path to your user path variables too, in the first box. I guess you're restarting your CMD window?

Path is not available in PHP exec or shell_exec

I've been trying and searching about a small issue I have in our php application. We use a which to find the full path of a program, however it returns with
which: no bla in ((null))
on Centos, on our own debian boxes it works just fine. I've figured out since then that (obviously) the PATH is not available in the shell from PHP. But what I can't find out is why that is the case. I've replaced the command with all sorts of commands to find out what the environment is in which I run in.
If I run an echo $PATH I actually see the directories I've set in the .bash_profile. If I run echo $SHELL I know I am using bash, if I run whoami I found out I am not the apache user but a different user, whom I changed the .bash_profile for. As I've read there's a difference between shells, so I thought it might not load the .bash_profile so I've also added the export PATH to the .bashrc.
I can get it to work with a change in the code, I could replace the which, but I am just genuinely interested in why this is not working on this centos configuration. I've now added an export PATH in the exec function before the which and it works, and should also work on other systems, but still I think it shouldn't be necessary.
Anyone know what could cause this behaviour?

'mysqldump' is not recognized as an internal or external command

currently im trying to make backup and restore mysql database in my laravel project. I am using this laravel package https://github.com/backup-manager/laravel for backup package. i already follow the intructions, but when i am trying to backup my local database through command line (php artisan db:backup) in the last question, i got this message.
Dumping database and uploading...
[BackupManager\ShellProcessing\ShellProcessFailed]
'mysqldump' is not recognized as an internal or external command,
operable program or batch file.
I already googling it, and already put C:\xampp\mysql\bin to my windows env variables paths, but i still having this issue. if anybody know how to fix this, please tell me, i really appreciate it.
Laravel 5.1.x
It is because mysqldump.exe is not found in that location, the right path is given bellow
Open Command Prompt and type this
cd C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin
Press Enter
then type
mysqldump.exe
or,
Directly open this directory "C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin" and Press LEFT SHIFT KEY from keyboard and RIGHT CLICK on the Directory Window.
then type
mysqldump.exe
It will work 100% correctly
If you are using Xamp then:
Open your Xamp folder
Go to \mysql\bin find the mysqldump.exe
Go to your environment variables under System variable click on 'New'.
As 'variable name' put 'mysqldump'(without the quotes) and as 'variable value' put the path to your xamp\mysql\bin\mysqldump.exe this will make 'mysqldump' available as a global system alias.
Reminder: Make sure to restart your command-line interface.
It happened with me and I solved it by adding the following line at the top of the .bat file.
cd "C:\xampp\mysql\bin"
Please add C:\xampp\mysql\bin to this path at your user variables and system variables. If you are using a wamp server, add C:\wamp64\bin\mysql\mysql8.0.27\bin this path at your user and system variables.
Note: MySQL version path will change as per your installation.
On my side, I was using PowerShell and I had the same error message.
I had to go inside the directory of MySql. Mine was located in:
C:\Program Files\MySQL\MySQL Server 5.7\bin
Then I had to make sure that I had mysqldump.exe in the bin folder.
And then run this command:
./mysqldump.exe -u root -p yordbName > C:\MySqlDump\sakila.sql
It is late, but I will answer to this question for other people who have the same issue.
You need to add the mysqldump.exe runtime file path to your Windows environment variable. I am using Wamp, the path look like this "C:\wamp64\bin\mysql\mysqlx.x.xx\bin"
Close your command-line interface and try again, It should work.
I am using Xamp and the following step is working:
Copy the path "C:\xampp\mysql\bin"
Go to your environment variables under System variable click on 'Path' and add "New".
Put the path there then click ok.
Restart your command-line interface.

Can EasyPHP take command line arguments?

I want to write a PHP program that takes an argument from the command line but am not sure how it's done. I use EasyPHP for development, do I need something different?
In the user notes it says you can
$ php -f somefile.php a=1 b[]=2 b[]=3
But when I try something like this (even php -i) it says php is not a recognized program. What do I need to do?
I'm not familiar with easyphp, but it sounds like you need to find php.exe (probably in the folder where you installed easyphp) and add it to your Path settings in windows.

How to tell Git I'm upgrading php?

I've just upgraded PHP to the latest version. When I get back to Git, to my command shell, if I execute any PHP function, then I get this error :
sh.exe": php: command not found
I know I have to tell git bash where my new PHP path is, but I don't know how to do so and I can't find anything on Google about that.
EDIT :
I made a confusion you're right : I meant Git BASH by git. Thanks :)
SO here is the function I tried to call when I was dealing with symfony in the root foler of my app :
php app/console dump-sql
then Git BASH sent me the error above.
If you are windows, then following up on halfer's comment, it is required that you add the new
/bin/ directory of the php folder to your PATH.
To do this:
1. Open start menu
2. Right click my computer->properties
3. Click advanced tab -> Environment variables
4. Scroll down in the second listbox for a entry called PATH
5. add this to the end ;C:/%PHP_LOCATION%/bin
where %PHP_LOCATION% is the place that you installed PHP to.
I think you have git and bash confused.
Git is a program that would be running under bash, and isn't directly related to git unless you've gone out of your way to entangle them.
Most likely, the incantation you need is
export PATH=/path/where/php/is:$PATH
And then everything will be working. Note that needs to be the path to the directory, not the binary.
the $PATH at the end is to make sure that you don't clobber your old path.
I had the same error. I found that I needed the environment variable path in this format:
/c/wamp/bin/php/php5.3.13 (instead of C:\wamp\bin\php\php5.3.13)
Using Windows 7 & Git 1.7.10.

Categories