I've been following the steps at this link: https://github.com/opentok/learning-opentok-php, and I can't get past the first step because I don't understand what I have to do on this part:
The run-demo file starts the PHP CLI development server (requires PHP >= 5.4) on port 8080. If you want to run your server on another port, edit the file. Finally, start the server using the run-demo script.
And then when i actually run the run-demo script and follow the link: http://localhost:8080/session i get this message on screen "You must run composer install in the sample app directory", and if i try to run the composer it doesent run.
Related
I have an issue updating SVN from within PHP. It was working fine then suddenly stopped working a few days ago.
I am running PHP-FPM 5.5 through Nginx. SVN version is 1.8.8.
The code:
exec("svn cleanup $path");
exec("svn revert $path -R");
exec("svn update $path --accept theirs-full --non-interactive", $output, $return);
echo "Return: $return\nOutput: ".print_r($output, true)
Output:
Return: 1
Output: Array
(
)
When I run this in terminal (under the same user as PHP-FPM and Nginx), I get the expected output:
Updating '/path/to/app':
At revision 100
PHP CLI also works with the correct output (under same user as PHP-FPM and Nginx):
php5 /path/to/app/svnupdate.php
Based on this it seems to be specifically an issue with PHP5-FPM exec on svn. But how can I debug this and figure out what is wrong?
Thanks.
Updates from comments to keep everything together:
Tried the proc_open approach, running only "svn cleanup $path" via that failed and caused all files to lock. running same command under same user in terminal worked fine and unlocked all files again.
Tried full path to svn bin, no difference
Running "svn info $path" seems to work fine, no files were locked.
The following commands all fail in php exec/proc_open (without any error message or output) and lock the app files:
svn cleanup $path
svn revert $path -R
"svn update $path" returns "Updating '$path'" but stops there, previously the current build number would be returned on a second line.
I have a 2nd setup with a different app and svn server but running the same version OS and all software, this one is working fine. I think that rules out software.
i tried rolling the issue server back to a version from 2 months ago when it was working, the server automatically updates software and app on launch but should not have touched config files or cache. After it was available it was still showing the same issue. Fairly sure that rules out software config files/cache.
Which leaves only app codebase and svn server as a possible cause. I'll try resetting the svn server next and redoing the svn project.
Update 2:
Recreated the project on the SVN server, remove application from app server and all svn config directories, checked out the new project from SVN server (build 1). Still the same error. !_!
Update 3:
After doing all of the above i concluded that left only the file base that could be causing the issue. And it was, there was a "Can't convert string from native encoding to 'UTF-8':" error being thrown by SVN because of a few files with special characters in the filename. Interestingly the error only stopped the process when running from php-fpm and not in terminal. NO IDEA WHY. I added export LC_CTYPE=en_US.UTF-8; to the exec command and now it is working fine.
exec("export LC_CTYPE=en_US.UTF-8; svn update $path",$output);
The exit status (1) indicates that the command fails for some reason. To find out the reason, you need to capture the standard error with the help of proc_open function as shown in this answer. The exec function captures only the standard output.
There was a "Can't convert string from native encoding to 'UTF-8':" error being thrown by SVN because of a few files with special characters in the filename. Interestingly the error only stopped the process when running from php-fpm and not in terminal. NO IDEA WHY. I added export LC_CTYPE=en_US.UTF-8; to the exec command and now it is working fine.
exec("export LC_CTYPE=en_US.UTF-8; svn update $path",$output);
I used this code to actually discover the error in php:
$proc = proc_open('svn update', $desc, $pipes);
echo 'PIPE 1: '.stream_get_contents($pipes[1]); fclose($pipes[1]);
echo 'PIPE 2: '.stream_get_contents($pipes[2]); fclose($pipes[1]);
echo 'STATUS: '.proc_close($proc);
In my situation, I fixed the problem by following steps:
check which user php-fpm runs, in my case, it is nginx
cat /etc/passwd to check 'nginx' user, its home directory is '/var/cache/nginx'
cp /root/.subversion to /var/cache/nginx
reconfig /var/cache/nginx/.subversion/servers if you need
then is works well
Maybe the debug process is helpful:
I guess it is because of the permission problem
I change nginx from /sbin/nologin to /bin/bash
I run runuser -l nginx -c 'php myphpscript_which_exec_svn_command.php'
It will output some information you need
So I get the solution, for security reason, change nginx user property back(/bin/bash to /sbin/nologin)
I'm trying to make a hook on bitbucket, that executes a php file, and this file executes the pull command:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The pull command works fine on the SSH console, but the PHP returns the error:
Permission denied (publickey). fatal: Could not read from remote
repository.
Please make sure you have the correct access rights and the repository
exists.
The command --version shows the path to git is right, whoiami returns the same user on both, so I don't know if it is a permission issue.
What can be going wrong?
Edit: An additional issue: the alias I added for git don't work on PHP, only the full path as above. Via terminal it works just fine. Maybe it's the same reason why the key don't work in php.
Edit 2: $PATH is different on both.
When you run this command within a PHP script you are not running the command as yourself:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The reason it works from the terminal console is you run the command as yourself from the console. But on a web server, you are not the user running the command. Remember: When you run PHP on a web server, it is a an Apache module. Meaning the web server user—which could be www-data, root or even apache on some systems—is running the PHP script which then runs the shell_exec command.
So it would never work as you have it setup. Perhaps you can kludge something together that would allow a key-pair to be used by the web server for these purposes, but that seems like a security risk waiting to happen.
I assume I'm making some simple mistake, but I just can't get the Google App Engine PHP SDK (GAE) "helloworld" example to work.
When I attempt to run the example on a Windows XP command line, I get no errors. The dev appserver is ever started on port 8080. I followed the GAE PHP SDK "Getting Started" page to the letter. If I mistype the path name, I get an error on that, but that’s it.
I have installed Python 2.7, PHP 5.4 and the GAE PHP SDK 1.8.3. All seem to work independently without error. Testing such…phpinfo() works, the Python interpreter works as well.
I’ve read all of the other questions/answers on this subject on the Stack(here) but nothing has helped. Here's some details:
My "helloworld" dir (the app.yawl file is there too):
C:\helloworld\helloworld.php
My Google GAE dir:
C:\google_appengine
My PHP dir:
C:\PHP
My Python dir:
C:\Python27
Here's the dev appserver startup command line I'm using in a Windows XP CMD window:
python C:\google_appengine\dev_appserver.py --php_executable_path=C:\PHP\php-cgi.exe C:\helloworld\helloworld
The dev web server does not start, can't see the listener on default port 8080 in netstat.
You said that the app.yawl file is present in the helloworld directory.
Its actually app.yaml . You may have saved that with incorrect extension. Check it.
The other thing I noticed is in the last command you are pointing to the .php file as C:\helloworld\helloworld.
You should actually point to the APPLICATION_DIRECTORY, which in your case is just C:/helloworld/
I've installed Apache 2.4 with PHP 5.4 on Windows Server 2008 following instructions from this manual:
Apache installing manual.
Apache runs as a service now.
My application requires a php websocket script to run in the background. I'm running it manually with:
php myscript.php
The question is: Is there a way to start a background script automatically on system(apache) restart?
I found the following topic, but I didn't know where I could find an apache startup script for Windows.
Any help will be much appriciated.
I come up with a solution :)
Create an environment variable pointing to your Apache directory
APACHE_HOME = C:/PATH/TO_APACHE
Rename %APACHE_HOME%\bin\httpd.exe to %APACHE_HOME%\bin\httpdVendor.exe
Create a batch file and put the following code :
php myscript.php
%APACHE_HOME%\bin\httpdVendor.exe -k runservice
exit 0
Download/Install the free software BatToExeConverter (next, next, ...)
Open the installed converter and open your freshly created batch file
Click on the button Build EXE (let the default configuration)
Save the file : %APACHE_HOME%\bin\httpd.exe
Start your Apache Server
Tested on : Windows 7, Apache 2.4, Advanced Bat to Exe Converter 2.92
Use built in Windows Task Scheduler which triggers .bat script, which calls curl with defined url.
Download curl from http://curl.haxx.se/download.html and extract curl.exe on any directory, but we will use c:\backgroundtasks
Adjust script below to your needs:
cd c:\
cd c:\backgroundtasks
curl http://localhost/path/to/script.php
exit
Configure Task Scheduler to run as basic task:
General tab - as system account (to run when you are not logged in server)
Triggers tab - adjust frequency
Settings tab - at bottom set If the task is already running... to Stop the existing instance
The best method here would be to use Windows services dependencies.
Make a php-websocket-server.cmd file with any necessary environment settings (e.g. changing to a directory, setting PATH, etc...) with the last line:
php myscript.php
Install the Windows Server Resource Kit Tools, to get srvany and instsrv to create a user defined service. Note the install path as you'll need it in the next step.
Open a cmd shell and run:
<path_to_resource_kit>\instsrv PHPWebSocketServer <path_to_resource_kit>\srvany.exe
Next, create a file php-websocket-server.reg containing the following (update for your environment):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PHPWebSocketServer\Parameters]
"Application"="c:\\path\\to\\php-websocket-server.cmd"
Import it by double-clicking or regedit /s php-websocket-server.reg
Back in your cmd shell:
sc config Apache2.4 depend= PHPWebSocketServer
to make the Apache2.4* service depend on your php service. Now, when Apache is started, the php service will be brought up first. And likewise, if you stop the php service Apache will stop along with it.
*the howto indicates that the service is named "Apache2.4" but you may want to verify in your installation.
When running as service, you won't have the startup script.
Execute some service implementation that allows running other programs as services, and then make the new service (which is running your script) a dependency of the Apache service. However, this will not restart the script when apache restarts.
One possible solution using SrvStart, and another using ServiceEx.
Perhaps don't install Apache as a service, and then edit the startup/restart script, and use the above method to run Apache as service (instead of using Apache's own installer).
Create bat file,e eg 'myphp.bat' containing path/php myscript.php. Include the correct path to php if it's not path'd.
create a bat file, eg runmyphp.bat containing
AT 00:00 /every:M,T,W,Th,F "cmd /c /path/myphp.bat", again including the correct path.
Then use explorer to drag runmyphp into the startup folder, so it will always run on system startup.
Google 'windows at command' or 'windows cron' to get all the correct syntax for the 'at' command, but you can currently find a detailed explanation here.
I found another answer C:\wamp\scripts\wampserver.lib.php this file is run every time when your wamp starts
include your file path include_once("file_path"); to this file and its done . this is perfect solution which you want
Enjoy!!!!!!!!!
Although the solution of Halayem Anis is very creative, I think its important to note that you can never be sure that a PHP script keeps running in the background. So if you choose to start your script on "Apache start", then you probably end op resetting Apache quite often, simple to reboot your script.
I assume that's even how you came to this question, as on a normal server you never have to touch the Apache reset button. It starts on system start and then it just runs. If that was the case, you could simple run your php myscript.php command on start up.
Considering there is no way to make sure the script keeps running, I would use a different approach, where I check if it is running and if not, restart it.
So the first step is to make it possible to track if the script is running. I would go for the simple approach where your myscript.php writes a single byte to a file every 5seconds or so. This way I can use the last modified time on the file to see if it is still running, because last modified time + 5 seconds < now == not running.
You could also store the last access time in a database every 5 seconds or so. Might be slightly faster then accessing files if you have a lot of traffic.
The second part is to have each request check if the script is running. For this two work I would use the PHP.ini to prepend a php script on every request. You can do it with the auto_append_file option.
This prepend script would work like this:
<?php
$filename = 'checkonline.txt';
$cmd = "php myscript.php";
if (filemtime($filename)+5<time()) {
//run in background without freezing php
//based on code posted on PHP exec manual, linked below
if (substr(php_uname(), 0, 7) == "Windows"){
pclose(popen("start /B ". $cmd, "r"));
}
else {
exec($cmd . " > /dev/null &");
}
}
?>
Make sure to check how filemtime and exec work and what you need to keep in mind. They work slightly different on Windows/*nix.
Wrap-up all your required processes in a batch file and use RunAsService
With some tweaking, you can ensure that your service starts before Apache.
I'm having a look at some PayPal scripts/code examples and a lot of them need a php script running via the command line.
I've never had to run anything from a command line in PHP before so don't know where to start at all. I don't know if I'm using the correct search terms as Google hasn't helped me answer.
Do I need to use a different application or is there something in cPanel I can use?
I get this error:
INSTALLATION ERROR: Please cd to the /home/site_name/public_html/site and run install.php
Use SSH to access the server via the terminal:
http://docs.cpanel.net/twiki/bin/view/11_30/CpanelDocs/ShellAccess
There's instructions on how to connect via PuTTY, then you can go to the directory where the PHP script is run it like:
php myPHPScript.php
If your cPanel has the option to turn on SSH, do it. Then SSH into the server and run the commands -
cd /home/site_name/public_html/site
php install.php