I have installed xampp in my windows OS.completed the configuration settings .But i can't run a simple php script from CMD . Is there anything should i do bfore running the script .
Be sure, that php is added to your path variable, so you can run php -v in your terminal. You should get the current version of your installed php.
If php was added to your path variable, you can run a php script like php file.php
See http://php.net/manual/en/faq.installation.php#faq.installation.addtopath
First, you have to go till that file path in command prompt then use command to execute php script,
php file_name.php
Related
I've been trying to run the php script:
shell_exec("bash /etc/example.sh")
from the browser but it does not work. This bash file creates a new one on the /etc directory.
I've also tried the functions exec() && system() but they don't work either. The weird thing happens when I run other Linux commands on these php function like:
shell_exec(rm -r /etc/fake);
they work fine, I have also tested my bash file on the linux command line and it works great.
I am sure this is not a permission issue, since I previously set the 777 permission on the file i am trying to execute.
shell_exec("bash /etc/example.sh")
I am using php7.0.33 and Debian 9, so I suppose this may be an issue with this PHP version 7.0.
Thank you for the help.
hey I want to run php on command prompt with xampp server. I made 2 environmental variables C:\xampp\php and C:\xampp\mysql\bin. how to execute the php code now?
Run command from console
c:\xampp\<path to php>\php.exe <path_to_your_php_project>\your_script.php
I have installed xampp server in windows 7. I have already checked Browser its working.But I am trying to run the php -v command prompt. I receive the following error message.
´php´ is not recognized as an internal or external command,
operable program or batch file
This pops up if Windows doesnt know about php. To solve this you have to add the full path to the php.exe to your PATH-variable in windows.
After you restart the console php should be available.
Add the php folder to your path and restart cmd.
Use this command from the command line (use the path to the php.exe, it is usually under c:\xampp\php):
set PATH=%PATH%;C:\xampp\php
Add the full path to find the folder, for example:
c:\xampp\php\php.exe -v or c:\xampp\php\php.exe -version
I would like to ask if I can run a php without having installed a web server. Do I have to use the php like CGI and run my page via command line? And if so, what are the steps that I do I have to choose through the installation of php? I mean the preferences as CGI and the components after that step?
I installed the php 5.3.3 but is seems not working, I get several message that the php5ts.dll is missing and when I put that file in my ext folder other error messages appear. Are there any configuration files or steps that I have to use?
(is php 5.3.3 suitable for doing something like this?)
If I have to have a web server installed how can I run my php code through the command line?
You should normally be able to run a php file (after a successful installation) just by running this command:
$ /path/to/php myfile.php // unix way
C:\php\php.exe myfile.php // windows way
You can read more about running PHP in CLI mode here.
It's worth adding that PHP from version 5.4 onwards is able to run a web server on its own. You can do it by running this code in a folder which you want to serve the pages from:
$ php -S localhost:8000
You can read more about running a PHP in a Web Server mode here.
For windows system you should be able to run php by following below steps:
Download php version you want to use and put it in c:\php.
append ;c:\php to your system path using cmd or gui.
call $ php -S localhost:8000 command in a folder which you want to serve the pages from.
PHP is a normal sripting language similar to bash or python or perl. So a script with shebang works, at least on linux.
Example PHP file:
#!/usr/bin/env php
<?php
echo("Hello World!\n")
?>
How to run it:
$ chmod 755 hello.php # do this only once
$ ./hello.php
You can use these kind of programs to emulate an apache web server and run PHP on your computer:
http://www.wampserver.com/en/
http://www.apachefriends.org/en/xampp.html
Normally when I want to run a php script from the command line I just create a php page, add a shebang pointing to the php binary, then ./file.php to run it. Since I have php installed as an apache module, I'm not even sure what my shebang should look like. Any ideas?
The CLI version of PHP had been part of the default installation since 4.3 and has to be explicitly turned off when PHP is being built. If you have access to the command line try
$ php -v
If you don't get a command not found error then you should be ready to go.
To actually run a php file from the command line do this:
$ php -f file.php
If it's just an Apache module, I don't think you can do it… At least, not without using a script like this:
$ cat run_php_with_apache
#!/bin/sh
cp "$1" /var/www/
curl "http://localhost/`basename "$1"`"
rm "/var/www/`basename "$1"`"