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
Related
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
I've installed git-ftp onto my CentOS Server so that I can do deployments from an activeCollab installation running the ac_gitolite module.
Everything installed fine and the app lives at
/usr/local/bin/git-ftp
When I log into the server via ssh I can run git-ftp commands without the full path, but when attempting to use PHP to run commands with exec ie:
exec ("git-ftp --version 2>&1", $output);
I receive the following error:
sh: git-ftp: command not found
Is there an environment path I need to specify somewhere specifically for PHP, or what am I doing wrong?
The two options discussed in "command not found - error in exec() command" are:
One easy solution would be to put the full path of the git-ftp executable.
The other is to add git-ftp to the php server user's PATH.
How can I run a PHP script from the command line using the PHP interpreter which is used to parse web scripts?
I have a phpinfo.php file which is accessed from the web shows that German is installed. However, if I run the phpinfo.php from the command line using - php phpinfo.php and grep for German, I don't find it. So both PHP files are different. I need to run a script which the php on which German is installed.
How can I do this?
You should check your server configuration files. Look for lines that start with LoadModule php...
There probably are configuration files/directories named mods or something like that. Start from there.
You could also check output from php -r 'phpinfo();' | grep php and compare lines to phpinfo(); from web server.
To run php interactively:
(So you can paste/write code in the console.)
php -a
To make it parse a file and output to the console:
php -f file.php
Parse a file and output to another file:
php -f file.php > results.html
Do you need something else?
To run only a small part, one line or like, you can use:
php -r '$x = "Hello World"; echo "$x\n";'
If you are running Linux then do man php at the console.
If you need/want to run PHP through fpm (FastCGI Process Manager), use cli fcgi:
SCRIPT_NAME="file.php" SCRIP_FILENAME="file.php" REQUEST_METHOD="GET" cgi-fcgi -bind -connect "/var/run/php-fpm/php-fpm.sock"
Where /var/run/php-fpm/php-fpm.sock is your php-fpm socket file.
On SUSE Linux, there are two different configuration files for PHP: one for Apache, and one for CLI (command line interface). In the /etc/php5/ directory, you will find an "apache2" directory and a "cli" directory. Each has a "php.ini" file. The files are for the same purpose (PHP configuration), but apply to the two different ways of running PHP. These files, among other things, load the modules PHP uses.
If your OS is similar, then these two files are probably not the same. Your Apache php.ini is probably loading the German module, while the the CLI php.ini isn't. When the module was installed (auto or manual), it probably only updated the Apache php.ini file.
You could simply copy the Apache php.ini file over into the cli directory to make the CLI environment exactly like the Apache environment.
Or, you could find the line that loads the German module in the Apache file and copy/paste just it to the CLI file.
I was looking for a resolution to this issue in Windows, and it seems to be that if you don't have the environment variables ok, you need to put the complete directory. For example, with a file in the same directory as PHP:
F:\myfolder\php\php.exe -f F:\myfolder\php\script.php
On MAC OS X Lion - Running MAMP
I'm trying to execute the following yiic command (from Yii framework);
./yiic message ./app/messages/config.php
I'm getting this message:
env: php\r: No such file or directory
I've looked into yiic file and I see:
#!/usr/bin/env php
<?php
require_once(dirname(__FILE__).'/yiic.php');
I've looked into /usr/bin/env
and I see, nothing related to php (I believe):
Should I have there something related with php ?
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/qq/4k5m37mn16bgfpp6yt8ggljc0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-L43tVY/Render
TERM_PROGRAM_VERSION=299
TERM_SESSION_ID=1999B4D4-939B-4065-B71C-D9B0563A9EC6
USER=mem
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-FBmmga/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin
PWD=/usr/bin
SHLVL=1
HOME=/Users/mem
LOGNAME=mem
LC_CTYPE=UTF-8
DISPLAY=/tmp/launch-oXxXFl/org.x:0
_=/usr/bin/env
OLDPWD=/usr
As anyone add this error before?
Is this something to do with the fact that php is not on that env think perhaps?
Please advice
It looks you're just experiencing an encoding issue with your yiic file. The shell is trying to use php\r interpreter to open yiic, instead of php.
Run the following command to replace all CARRIAGE_RETURN characters by LINE_FEED :
perl -pi -e 's/\r/\n/g' yiic.php
Worked pretty well in my case.
I just read this blog: could be the very same problem you are experiencing?
The next step is to tell the yiic application, found in the framework folder, to create a new site. The syntax is
yiic webapp path/to/directory
But before you even begin to use this command, let me explain it a bit, as it’s very important and can be complicated. The yiic file is an executable that runs using the computer’s command-line PHP and that really just invokes the yiic.php script. You may be able to call it using just yiic or using ./yiic (i.e., run the yiic command found in the current directory). Or you can more explicitly call either script using php yiic or php yiic.php. Or you may need to indicate the PHP executable to be used: C:\php\php.exe yiic. You should try the variations on this command, as applicable to your computer, just to make sure you can invoke yiic, prior to trying to create the Web application.
In my case that worked for using xampp:
Creating new project:
X:\xampp\php>php.exe X:/xampp/htdocs/yii/framework/yiic webapp X:/xampp/htdocs/YOUR_PROJECT
yiic shell:
X:\xampp\php>php.exe X:/xampp/htdocs/YOUR_PROJECT/protected/yiic shell X:/xampp/htdocs/YOUR_PROJECT/index.php
Just I changed php version of my system form 4 to 7.
I run this command to salve this issue-
source ~/.bash_profile
This solved my issue.
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"`"