Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I use Debian. I wanted check my php version. I typed but by mistake
php
instead of
php - v
. And then "php command line" won't take any commands anymore from me. No error no reaction.
I can stop this process using kill command, but I want to know, what is 'php' without option for. And how to stop it, without kill command.
Press Ctrl+D to send EOF (end-of-file) to PHP, which will cause it to exit. Or press Ctrl+C to kill it with a SIGINT signal.
Explanation: With no command-line arguments PHP is expecting code to be provided on standard input, which is connected to your terminal. This is standard behavior for many UNIX programs, not just PHP. You can type code manually and then press Ctrl+D when you're done and PHP will execute the code you typed.
You can see the same behavior with cat. If you don't provide a file name cat will read from stdin and copy it to stdout. Which means it will echo every line you type until you press Ctrl+D to signal EOF.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to set up my system so that php can be run without including the shebang in every file. Is there an alternative to using #!/usr/bin/php in every php file I write?
The shebang is only needed, if a PHP should be called directly by a shell/tool like any other shell script. Examples are functions system() or exec*() provided by many languages, including PHP.
If calling a command, the tools look for a shebang to decide, which interpreter is to call. This works for awk too:
#!/usr/bin/awk -f
BEGIN { print "begin" }
The general idea is, to put commands e.g. in /usr/local/bin, make chmod a+x and use them like any other command without need, to select the needed interpreter manually.
Conclusion
Shebang is not needed for web server files, that are never called as script by a shell or external tool.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a program that utilizes Python scripts that pull information from a MySQL database. The MySQL database is managed from a PHP site interface (so HTML forms and buttons and the such). I have this all set up on a raspberry pi and it works. But I want to add some more functionality.
Specifically I want to be able to execute certain python scripts from the PHP site. I want it to be as simple as a press of a button, literally.
Is this a scenario where I should use Django? I've never used it before but have read about how it connects Python with the web. I found an answer to a similar question but I'm wondering If I need to set up anything special on my apache server: https://stackoverflow.com/a/31811462/5609876
I even made a little picture for a visual representation of my program incase my explanation wasn't good enough:
No, you do not need django at all.
If all you want to do is execute a Python script from PHP - assuming you have already written the script and stored it somewhere:
First, assign execute permissions on the Python script to the user that is running the PHP code. Normally, this is the same user that is running Apache. Usually this is called www-data or apache or something similar. The user will be listed in the Apache configuration file.
Then, on your PHP side, all you really need is exec:
<?php
exec('/path/to/python /path/to/your/script.py')
?>
If the shell_exec function is allowed on your server, you can use that to run your Python script through Bash. shell_exec returns the output of the bash call. The only thing you have to make sure of is that shell_exec isn't disabled in your server's php.ini file (look for the line disable_functions shell_exec).
If your python script is called mypythonscript.py and is in the same directory as the PHP file, you can run it like this:
<? shell_exec('python mypythonscript.py'); ?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've recently been working on a web crawler with PHP and as a newish PHP coder, I'm not the most advanced. I also know a decent bit of Python and there are a few things I am able to do in Python yet not in PHP.
Is there any way for me to run a Python function with parameters inside a PHP script? Please be specific in your answers as I'm not amazing at PHP.
Run the Python script using php's shell_exec function
Think of shell_exec as basically running commands in your terminal. So if you normally run your python script from the shell like this:
/python-scripts/myscript.py "here is an argument"
You would pass the same command into shell_exec, like this:
$output = shell_exec("python-scripts/myscript.py 'here is an argument'");
Note: shell_exec will return the output of the command you run, so save it to a variable if you want to use the output from the python program in your PHP script.
Edits: fixed syntax issues, provided a more specific example
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want my web server to run a .sh script that runs a series of .jar files. I want this to happen as soon as the server is contacted without any input from the user. A PHP or JS script would be preferable. Is it even possible to do this?
Thanks in advance
You can also look at gearman.org. It is safer and more flexible than shell_exec().
It is not doable in JavaScript, but you can use PHP for it. If I understand your question well, you have some utilities written in Java and you don't care about their output. The shell script would look like as follows:
#!/bin/bash
java -jar your-jar1.jar
java -jar your-jar2.jar
...
and provided the name of the script is myScript.sh and it has the x flag set, you can run it from PHP by:
shell_exec('path-to-script/myScript.sh');
<?php
exec ("sh your_script.sh");
?>
place this in your webserver root as a php file and replace your_script.sh with the name of your script.
WARNING: if you don't protect the script with a password, using for example a .htaccess file for Apache (http://httpd.apache.org/docs/current/howto/htaccess.html), anyone can execute that script.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
UPDATE: I do not know Perl or Python as I have said. Don't give me examples because I don't understand it!
I have looked at other posts here, but do not see any real answer. I use Go Daddy and would like to backup my MySQL database every day, and if possible only allow 7 backups in the folder at once.
Folder: _db_backups
DB Name: ccadatabase
Go Daddy says:
Your Shared Hosting account supports the following languages and associated interpreter lines:
Perl: #!/usr/bin/perl
Python 2.2: #!/usr/bin/python2.2
Python 2.3: #!/usr/bin/python2.3
Python 2.4: #!/usr/bin/python2.4
Ruby: #!/usr/local/bin/ruby
Bash: #!/bin/bash
The installed versions of PHP 4 and PHP 5 do not support the interpreter specification in a PHP file. In order to run a PHP script via Cron, you must specify the interpreter manually. For example:
PHP 4: /web/cgi-bin/php "$HOME/html/test.php"
PHP 5: /web/cgi-bin/php5 "$HOME/html/test.php5"
Is there anyone who can help me write a quick script to make this process automated? That would be great! I don't know any Perl/Python, so if you could explain your code I would really appreciate it. Thank you!
here's what I use
#!/bin/bash
DATE_NOW=$(date +%Y%m%d)
BACKUP_DIR=/Users/nico/${DATE_NOW}
mkdir -p ${BACKUP_DIR}
echo "Dumping data ..."
mysqldump -ume -hlocalhost -ppass db > ${BACKUP_DIR}/${DATE_NOW}-mybackup.sql
Note: you'll have to change the mysqldump variables with user password db etc