Hello everyone I would like to launch a local php server ( php -S localhost:8888 public -t ) from a batch file but it doesn't work .... Do you have an idea how to do that ? Also there are other commands before and after but while debugging I noticed that the problem came from there
you need to add your PHP in your environment path to access it from your cmd
this is how you add a path to your environment path in windows
Related
Iam working on my own php MVC. And now, I wanted to create a cli tool for starting a live server which can be used for development purposes. I'm using laravel-zero for building my cli. All the commands are working fine except the command that is supposed to start a server. To start my server, first I need to change my current working directory to public and then start a php server using 'php -S localhost:9000'
I have tried the below code, but it doesn't work:
shell_exec("cd public");
shell_exec("php -S localhost:9000");
I have also tried this, but this too doesn't work:
shell_exec("cd public ; php -S localhost:9000");
Finally after lots of google searches, I tried this, but the same result:
chdir("public");
shell_exec("php -S localhost:9000");
All It shows is just 'The system cannot find the path specified.'
If your current directory when running shell_exec() is your installation root directory, you can just add the path after php
shell_exec("php -S localhost:9000 -t public/");
But since you are using laravel, why dont you just run php artisan serve
I'm using youtube-dl.exe on my Windows WAMP server and shell_exec() is working great on Windows, I get the right info from youtube-dl (returns a string).
Once the same PHP script is uploaded on my real Linux server it just stops working, even though I upload the Linux version of youtube-dl.
for the Linux version file that I've obtained from a sudo curl command on a Linux machine on VirtualBox, I'm trying to do this:
$var = shell_exec("youtube-dl -g https://www.youtube.com/watch?v=97Eagwlt-ZA");
And for the same version I've got on my WAMP server (exe):
$var = shell_exec("youtube-dl.exe -g https://www.youtube.com/watch?v=97Eagwlt-ZA");
Both of the commands returns absolutely nothing, the two different version of files are in the same root (/) folder and
$var = exec("youtube-dl -g https://www.youtube.com/watch?v=97Eagwlt-ZA", $errors);
$errors returns an empty Array()
But
$var = shell_exec("echo test > test.txt");
Works like a charm (creates the test file with "test" inside of it).
The PHP & youtube-dl files' CHMOD is set to 755. PHP Version 5.6.
I'm really stuck here.. Any ideas?
A few things to check:
Check to make sure youtube-dl has execute permissions for the webserver user. On Linux systems scripts have to be flagged executable in order to be run directly. Setting 755 permissions should do the trick.
Either add ./ to the path (e.g. ./youtube-dl) or make sure youtube-dl is on the web server's $PATH. Unlike Windows the current directory isn't automatically included on the path.
If your Linux server is running SELinux or AppArmor these applications may be preventing your web server from running commands. You can generally find out about items getting blocked in your syslog.
I have meshlab installed in my machine running Ubuntu 14.04 OS. I can access it from command line using meshlabserver command. But problem arises whenever I try to call it from a php script using the command
<?php
system('meshlabserver 2>&1');
?>
It shows the error meshlabserver: cannot connect to X server. After going through a few websites I did the following things:
I moved the meshlabserver executable from /usr/bin to /usr/local/bin and gave it executable permissions using
sudo chmod a+x meshlabserver
But when I ran the whoami command from my php script (calling the meshlabserver), it showed www-data. So I gave executable permissions for all users to the meshlabserver using
sudo chmod 777 /usr/local/bin/meshlabserver
But still it is showing the same meshlabserver: cannot connect to X server error. meshlabserver comamnd is working fine when ran from the command line.
I really need to call meshlab from the php script for my website. Thus any help would be highly appreciated. Thanks in advance.
It seems the php script can't access your display variable. If you logged in via ssh remember to tunnel your X-server via 'ssh -X ...' Your second option is to create a virtual frame buffer using Xvfb and redirect the display variable to it:
export DISPLAY=:100.0
Xvfb :100 &
Note the ampersand for the second command as Xvfb needs to be running in the background.
a combo of prior answers works for me:
ssh -X, as well as export DISPLAY=:0.0 (on remote)
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
I have been struggling to get my CakePHP site working on a Godaddy "grid hosting" account. My cake app is setup is hosted from a subdirectory on the account, and can be accessed via a subdomain. I had to adjust my .htaccess files to get this working, and now I need to get the CakePHP console working in this environment.
I have the same cake application setup on an Ubuntu server which is hosted on Amazon's EC2 service. Basically a plain out of the box Ubuntu LAMP setup. The CakePHP console works as expected in this environment.
When I try to run the console on Godaddy I get the following message:
CakePHP Console: This file has been loaded incorrectly and cannot
continue.Please make sure that /cake/console is in your system
path,and check the manual for the correct usage of this
command.(http://manual.cakephp.org/)
I've started to add in some debugging code in cake/console/cake.php to find out what's going on. On the godaddy site, when I echo out print_r($this->args) at line 183 I find the array is empty. When I do this on my Ubuntu EC2 instance I get this:
Array
(
[0] => /var/www/www.directory.sdcweb.org/htdocs/cake/console/cake.php
)
It looks like godaddy's command-line PHP isn't passing through the bash shell command line arguments. Does anybody have some advice as to how I might get the CakePHP console working on Godaddy?
The bash script which invokes the Cake shell contains the following
LIB=${0/%cake/}
APP=`pwd`
exec php -q ${LIB}cake.php -working "${APP}" "$#"
exit;
I am thinking that modifying this script may solve the problem.
in the cake shell script (cake/console/cake) change
exec php -q ${LIB}cake.php -working "${APP}" "$#"
to
exec php -q -d register_argc_argv=1 ${LIB}cake.php -working "${APP}" "$#"
after this I found out that calling php like this happened to run the PHP 4 CLI. to fix this here is the final bash script that I am using to invoke PHP 5 on my shared Godaddy hosting
exec /web/cgi-bin/php5 -q -d register_argc_argv=1 ${LIB}cake.php -working "${APP}" "$#"
if you setup a php-based cron job through their hosting control panel, you will find the php command invoked is actually to this php5 executable.
"Please make sure that /cake/console is in your system path."
This is grid hosting so I'm assuming you have a .bashrc file which you can edit. First you need to know the absolute path to your cake sub-directory then use vim or nano to edit your .bashrc
PATH=$PATH:/absolute/path/to/cake/console
Then you can log out and log back in and you should be able to type cake bake from anywhere and it should fix the error your getting (run it from your app directory so it can find your database.php).
Failing a .bashrc file you can export the variable temporarily but you will have to type it every time you log in.
I don't think editing anything in the lib/cake is okay, since it will be gone with your first cake update.
Rather, I changed the register_argc_argv setting from the php.ini by adding the line:
register_argc_argv=On
All seems to work now with me.