LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CentOS 5x - How to launch PHP script (https://www.linuxquestions.org/questions/linux-newbie-8/centos-5x-how-to-launch-php-script-940087/)

Ne0Geek 04-16-2012 01:26 PM

CentOS 5x - How to launch PHP script
 
I am running AWS image with MySQL server installed. I am trying to run a php DB backup script but have a few basic questions. I have installed php. Is there a specific dir where all php scripts must reside/ launched from?

I have searched several forums but none address such basic questions...thx for the help!

Tinkster 04-16-2012 03:18 PM

Hi, welcome to LQ!

First things first: what is this AWS you're referring to?

In general PHP scripts are "launched" (run/executed/...) in a web-environment.

If AWS (?) expects other means, try using cron, the OSes way of executing
scheduled tasks.


Cheers,
Tink



P.S.: When asking questions it's sound to assume that people know nothing about
your set-up, so providing essential information ahead of time is going to give
you a far better chance of helpful responses.
E.g.:
I'm running AWS, a <.......> product on a LAMP stack w/ apache2 2.1.14 on
moohluntu 10.10 ....

jstephens84 04-16-2012 03:21 PM

PHP (PHP hypertext Preprocessor) is mostly a web based language for creating web appliations. However it does have command line access when you install the php-cli modules. So to answer your questions you can try by typeing the following to get the include_paths which contain the default scripts used by the php language engine
Code:

php -i | grep include_path
or you can execute a script by typing
Code:

php <script name>.php

Ne0Geek 04-16-2012 04:17 PM

Thanks guys for your responses. Allow me to clarify, AWS stands for Amazon Web Services. I have a virtual machine running an image of CentOS 5x hosting MYSQL. I want to automate backups of several schema. To accomplish this I am using a php script that I run from terminal. Eventually I would like to run a cron job, but at this point I'm simply testing out the script. Since I am an absolute newbie, I was trying to rule out that I had placed the backup script in the incorrect dir to account for the errors that I am getting (e.g. :command not found, /: is a directory, and syntax error)

php -1 | grep include_path yielded this:

.:/usr/share/pear:/usr/share/php =>.:/usr/share/pear:/usr/share/php

I don't know what this means. Is this the dir I should execute .php from?

I tried to > result of script to a txt file, but is resulted in an empty file:

./php_script.php > ~/user/dir/errorlog.txt


Again, thank you very much for the help ;-)

Tinkster 04-16-2012 04:38 PM

Well.. if you're using MySQL I'd not bother trying to take back-ups from
php; unnecessary overhead.

Have a look at
Code:

man mysqldump

Unless you need to be able to do ad-hoc backups via a webinterface, that is.
But even then it's probably easiest to install myPHPadmin, and do it from
there ...



Cheers,
Tink

Ne0Geek 04-16-2012 05:13 PM

Thanks for the suggestion, Tinkster. Will mysqldump shutdown/stop mysql server while it's backup? My main object is to backup the database gracefully.

chrism01 04-16-2012 05:48 PM

mysqldump locks the DB internally to guarantee a consistent data set, which is why its recommended to use that instead of doing your own code.
https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html

For cron http://www.adminschoice.com/crontab-quick-reference.
NB: cron has a minimal env inc PATH settings, so always specify complete/absolute paths to cmds and files used by a cron job.


All times are GMT -5. The time now is 12:26 PM.