Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Crontab Outside Web Root


I am trying to get a PHP script running on the crontab where the PHP document is located outside of the web root, this presents a problem because PHP is installed as an Apache module and I dont have access to re-install on this server.

I have searched endlessly for ideas about how to get this running but all I am running into is the usual suspects: CGI Install Call Like a Command Line:

Fetch
wget
lynx

The last three all use http:// protocol as far as I have figured out. So does anyone know of any other software I can use to call from the crontab to run this script.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Document Root Not Website Root
I want to use PHP in my website; but run into a snag, the recommended
method of calling an include is:
<?php include($_SERVER["DOCUMENT_ROOT"]."/inc/css-gateway.inc"); ?>

when I try
<?php ECHO $_SERVER["DOCUMENT_ROOT"]; ?> the document root is shown as
/usr/local/apache/htdocs/

However the website root is at:
/mnt/home/www/canadian-dream.com/www

How do I redirect $_SERVER["DOCUMENT_ROOT"] to the my website root? Is
there a global variable that can be used? I do not wish to rewrite a lot
of pages if I were to change web host in the future.

from the error logs

[Sat Oct 25 06:32:51 2003] [error] PHP Warning:
main(/usr/local/apache/htdocs/inc/css-gateway.inc): failed to open stream:
No such file or directory in
/mnt/home/www/canadian-dream.com/www/de/immobilien/main.php on line 15

[Sat Oct 25 06:32:51 2003] [error] PHP Warning: main(): Failed opening
'/usr/local/apache/htdocs/inc/css-gateway.inc' for inclusion
(include_path='.:/usr/local/lib/php') in
/mnt/home/www/canadian-dream.com/www/de/immobilien/main.php on line 15

Crontab
Is there any way to call php scripts via crontab? If not is it possible to execute a php sript from inside a perl script i.e. include, require?

Crontab Problem
I have viewed the previous posts on this subject but I'm still stuck. I'm trying to run a php script on the hour which should mail out some reminders. My host has php installed as an Apache module, and I've edited my crontab as follows:

1st try: 0***** lynx http://www.(path to file)
2nd try 0***** wget http://www.(path to file)

Neither work. I have tried the script directly from a browser and it works.

PHP Add Crontab Automatically
I need to create an install file, the purpose is that user don't have to go to CPANEL and add CRON JOBS manually. I need one file, that add CRON JOBS automatically without log into CPANEL.

Here is my function :

function addLynxCron() {
$time = time();
//dump crontab list to text file
$command1 = "crontab -l > ./tempCronLynx$time.txt &";
exec($command1);
chmod ("./tempCronLynx.txt", 0777);
$forFile = "";
$url = $_SERVER['SERVER_NAME'];
$path = $_SERVER['PHP_SELF'];
$cronCommand1 = "lynx -dump */15 * * * * http://$url/cron.php";
$cronCommand2 = "lynx -dump */15 * * * * http://$url/email_cron.php";
$forFile .="$cronCommand1";
$forFile .="$cronCommand2";
$fp2=fopen("./tempCronLynx2$time.txt", "w");
fwrite($fp2, $forFile);
fclose($fp2);
//create new cron jobs
$command1 = "crontab tempCronLynx2$time.txt ";
exec($command1);
echo "crontab successfully added.";
}

The function above is not working...

when I check the file tempCronLynx2$time.txt is correctly written with the
cron jobs I want. But it failed when added the new cron jobs using that files

$command1 = "crontab tempCronLynx2$time.txt ";
exec($command1);

anyone please help with this problems...

PHP, MySQL And Crontab
I have a PHP cli script, that backups my databases, using mysqldump
via system().

When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I put it in a crontab:

00 2 * * * /home/sandman/bin/backup.php

I get a mail that says:

"mysqldump: Got error: 2002: Can't connect to local MySQL server
through socket '/var/run/mysqld/mysqld.sock' (2) when trying to
connect"

How come? Anyone knows what the difference is between CLI and crontab
that could cause this?

Crontab Manipulation From Php
Maybe someone can give me a short help with this...

I got a server application in a LAMP environment doing batch tasks. A
cronjob serves as a regular trigger, a metronom. The trigged
processcollects a number of pending jobs to be run and typically creates a
number of additional jobs to be run in future. The type of created jobs,
their parameters and everything can be configured in the application.
Fine...
In addition I'd like to configure and control the triggering cron job itself
from within the application. Since the web server must not restart the cron
job I can't simply rewrite the crontab. The changes would only become
active after the next reboot, probably some three years in the future
(LAMP :-) ).
What has to be done is to manipulate the crontab of the web server in a way
that the crontab rereads this craontab. crontab -e does exactly this, upon
storing the file the crontab is triggered to read it. However the commmand
requires an editor as argument, this editor is used for the manipulation.
Now I don't really want to control some editor.
I guess I have to specify some process as 'editor' that has access to the
application settings and can open the file. Looks like a lynx or wget call
to a php url, the script should use fopen to open the crontab...

Crontab Entry
How can I have cron back up my database to a new file name each time Ex: db.001, db.002, db003....etc ? What would really be nice is if I could append the current date to the file ? Ex: "db.10-26-00" current crontab entry:

02*** mysqldump -u root -pZXCC helpdesk > /mnt/zip/db.backup

Update Once A Day If Not Using Crontab?
How is the best way to only run something once a day? I'd rather not run a crontab so how do I do it the least stressful way on the server?

Dynamically Creating A Crontab
Is it possibe to dynamically create a crontab. Say i have a form to enter minute, hour, day, etc... and wanted to create a cronjob that ran to those values. Has anyone done this?

Restricting Script To Run With Crontab Only
I'm creating a re-billing script to process subscription renewals for
a site. I want to use crontab to check once a day for expiring
accounts and re-bill the credit card. This script will only be run
via crontab. Is there a technique that I can apply to prevent access
to the script via HTTP and only execute it via crontab. One thought
was to put the script outside of the public root.

How To Run Crontab From Php Skript As A Different User
I want a php-script to maintain (some of) "my" cron jobs.

Therefore it has to modify some crontab.txt (no problem)
and has to execute crontab.

But since php runs as the apache-user it cannot run "my" crontab.

In general: Can a php-script run an external program under a different
user?

PHP And Crontab And Current Directory
I wrote a script and at the top it checks whether a file exists
like below

if (!file_exists("settings.ini"))
return false;

and the crontab entry:

00 08 * * 4 /usr/local/bin/php /home/user/scripts/test.php /dev/null
2>&1

however everytime it runs via cron, it can't find the file
settings.ini because it keeps looking for it in $HOME not in $HOME/
scripts/ where test.php resides

Why? And how can I re-code it to look in the current directory not in
$HOME? I tried ./settings.ini but without success

Fopen() Wont Work From Crontab
I have a script that calls an fopen() on an external URL.
I can run the script from the server as an url fine.
When however the script should be run from crontab, it does not work.
I get

Warning: fopen(): URL file-access is disabled in the server configuration
in [php-file]

Warning: fopen(http://[url].xml): failed to open stream: no suitable
wrapper could be found in [php-file] on line 66

I have set allow_url_fopen On, but it still wont work. Any Idea what could
cause that?

Root Access
If I want to add a column in a existing table in a php script, do I have to have root access?

Logging In As Root. Possible With Php Or Not??
I want to log as root from php. I am using Exec() function. I have tried the following code:
===========================
Passthru("whoami");
Exec("su root");
Exec("password");
Passthru("whoami");
===========================

Both the Passthru("whoami") returns apache. Where am I going wrong? Or is it not possible with php??

XML Root Elements?
I am writing some XML code in a php script PHP Code:

Document Root
I'm just having a little problem, and i'm wondering whats wrong with it. i coded an document shown below:

<? include('$DOCUMENT_ROOT/header.php'); ?>

and it leads me to this problem, i don't know why?

Warning: Failed opening '$DOCUMENT_ROOT/header.php' for inclusion (include_path='') in d:wwwdigitalricesomethingindex.php on line 2

Ask About Root Access
Can anyone tell me how to access root on localhost?

The Root Folder
I've a web site in the address http://mySite.com
in the root, I've a file index.html

I've some subfiolders insid root/sub1/sub2

I like to add an html file (or php) index.html that call the index.html of
the root (in order to protect)
Now I've created 2 different index.html because I use relative path to
design the root (../index.html and ../../index.html)

I like to have the same file in all folders,but I don't know how to call the
root folder.

How Can I Run Root Commands In Php
I need to run a command as root to create users on the system for webmail
server.

What is the best way to do this?

Site Root?
I'm a freelance web designer and I've begun to use PHP extensively for my clients' websites. A problem I run into is the consistent use of "/" for the site root. My server thinks that that refers to public_html/, meaning I can't test a site with "/" used to recognize the site root if I'm, say, one directory deep.

How can I have a specific website recognize its own base folder as the site root? I imagine that in PHP, without touching Apache config files, there's a way to set a new site root, I just don't know how.

Execute As Root
Is there a way to execute commands as root using sudo? If yes, how to use it, if no, how can I get around.

What Other Things That Should Not Be Under Document Root?
I would like to know what other things that you do not place under document roots? Besides initialization or configuration files, db name and parameters, all passwords, what else?

Access To Mp3 Files Below Web Root
I want to place some mp3 files below the web root directory to keep people from accessing these files. however i want certain php scripts to be able to use them (ie for a flash movie that plays mp3 files)whats the best way to accomplish this?

Goto Root Directory
does anyone know how to goto the root dir on a LINUX server. I mean like go to parent directory of public_html. i want store a really secure file there and then use the iinclude function to get it when i need it. is this even possible. are there limitations for using the "../" command in include functions? i've obviously tried something like
include("../../../home/mydir/my_secure_script.php"); //doesnt work

Calling Include Outside Root
so I want to keep my mySQL connection file and my constants file (variables) outside the webroot in '/inetpub/includes/' with the root being '/inetpub/wwwroot/'.

I should be able to call this with. PHP Code:

Opening Docs Outside Of The Www Root
I'm trying to find a way to make links with php that will open up files I have stored outside of my web root (i.e., when someone clicks on the link, php opens up a PDF file that is outside of the public folders).

I've been scouring the PHP manual to find a command that will do this easily but most of them are more in depth than I need.

Finding Nth Root Of X Quickly?
what is a quick way of finding the nth root of a large number? My program checks a bunch of numbers to find their square root, cube root, 4th root etc. but I think I could make it faster.

I've tried using pow($number,(1/2)); but the numbers I'm using are way to big (hundreds of digits) so I tried the same thing with bcpow() but it would only return 1 when I tried to use (1/2) as the exponent. Why is that?

Php-cli No Mysql Module For Non-root
So far I've been unable to find anything that addresses this one...

Basically, if I am logged in as root and issue a "php -m", mysql is in the
list of installed modules. If I log in or su to a normal user and do the
same then mysql is *not* in the list and I cannot use mysql_connect (or any
other mysql function)...

Any ideas on why this is or how to fix it?

Notes:

# php -v
PHP 4.3.3 (cgi-fcgi) (built: Nov 4 2003 14:05:47)
Copyright (c) 1997-2003 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies

Module list as root:
bcmath,bz2,calendar,ctype,dba,dbase,ftp,gd,gmp,ima p,mysql,openssl,overload,pcre,
posix,session,shmop,sockets,standard,sysvsem,sysvs hm,tokenizer,xml,yp,zlib

Module list as non-root:
bcmath,bz2,calendar,ctype,dba,dbase,ftp,gd,gmp,ima p,openssl,overload,pcre,posix,
session,shmop,sockets,standard,sysvsem,sysvshm,tok enizer,xml,yp,zlib

Setting Password For Root
I'm just starting PHP and MySQL - and really like the book by Welling
and Thomsom.

I've installed MySQL on my WinXP desktop, along with Apache and PHP. I
have not figured out how to set a password for the root account. I've
been able to set up a user account for myself, with a password, but not
the root account. I understand this is not ideal.

I've tried setting the password in My.ini but it doesn't seem to work.
I must be doing something wrong.

Accessing Files Outside Of The Web Root
Anyone got any pointers for a script and/or advice for accessing files that are outwith the root directory. I am using Apache on WIN2K Server (a box which is also running IIS on port 81).

I want user to be able to select a file and have a script verify their security clearance level (although I have this part worked out already) and then to supply a relative url from the web page they are on - out of the web root - to the file in question.

I have been toying with the 'realpath' function but to no avail thus far. I have tried using the path:

../../../files/{filename}
where the path to the web root (from the page in question) is
../../../

on my notebook (running WINXP Pro and same version Apache and PHP this works fine) but on the production server it cannot find the path outwith the server root.

Root Of Folder App Files
While I know putting a app into a folder was chiseled out of fine
scottish granite and carried upto the top of ben nevis by php newbies
many years ago - I dont think a folder is the best way to do it .

The fact a script is in a folder means certain instant problems if you
want to do certain things with .

Assuming a script doesnt have index.php and all the script files have a
filename prefix like phpgb_ then theres no chance of them clashing with
anything else and theres no real reason to continue using a folder for
the main script files .

While the script will have a app folder for various things - does it
make any sense not to use the root because of a single solitary file
called index.php .

phpgb_index.php is what I use and the method hasnt brought up a single
problem of any shape or description .

Gas lighting was once what everybody thought was the best way of doing
it until that darn new fangled electricity came along .

Creating Directories After Root
i want to create directories using vaiables my mkdir line is as follows PHP Code:

Smarty Installation In Root
I would like to install Smarty in a directory placed in my root. Could you please give me intructions of how I am going to do it?

Locating Root Directory
I posted earlier about finding a directory path from another directory. I tried to find the root directory of the site using the following variable:

$_SERVER['DOCUMENT_ROOT'];

Which I was then going to search to find the appropriate directory. However doc root is not defined on the server i'm using. So my question is this, is there another way to find the root directory and if not how can I set the document root variable? what do I need to change in the server configuration?

PHP Files Only Run In Root Directory?
I've installed a php forum script under a directory named 'forum', the script ran with no problems untill about a week ago, but now I get the following error: 'You don't have permission to access /forum/index.php on this server.'

Its has nothing to do with CMOD, I've tried that. Worst still it's not just the forum it's any PHP file thats under a directory. The thing is, I can run a PHP file from the root directory, but for some reason can't run the same file under another directory.

eg www.mywebsite/testfile.php --- will work fine www.mywebsite/newdirectory/testfile.php --- causes permission error

Could it be a .htaccess problem? Heres my error log report: Options ExecCGI is off in this directory: /home/mywebsite/public_html/forum/index.php P.S The forum script dosn't use CGI?

PHP Works Only In Document Root
All php files in document root work fine. While php
files in sub-directories of document root shows the
php source like a text file.

I have looked for help and also FAQ. Did I miss anything
during the installation. I have installed both apache and
php on Linux many times before actually figuring out that
all my php files generate html only in document root.

Read A File Below Root
How can I include a file from below the Root dir, other than using:
include "../../filename.inc.php";

Php Initializes Extensions As Root
I'm having a problem, i've designed an php extension, that uses shared
memory iteraction.

Altought, Php is initializing the extension as root, leaving the shared
memory with wrong permissions, as is created as root process.

Is there any way to initialize extensions, not as root?

Running Exec As Root?
exec('/sbin/ifdown eth0');

does not work, due to needing to be run as root.
I need to have this work on a closed network environment.

Site Root Directory?
I've posted this onto alt.php earlier and stumped all involved.
I didn't cross post for the usual reasons Anyone here got any ideas?
--------------------------------------

I am simply attempting to find my sites root directory so I can then step up
into a folder
in which I will have my INCLUDE code. This will allow me to easily refer to
my
INCLUDE code without messing about.

Now, This code...

It simply attempts to put a file into the root of my server space, and
recall it. It doesn't work.

The file write doesn't error and the file read fails without error.
Most importantly the file is nowhere to be seen!

<Added when sent to the domain provider>
--------------------------------------
I am worried the file is dropping into a space not allocated to my account
and that
this could cause you/I some problems if it were to overwrite an important
file.

Running System() As Root User
Is there a way that I can run the system() command as a root user. Need to
restart network services on a server via php.

Define Root Directory For Images
I want to have a root directory from which the images on different pages shall be displayed. I define it here:

define('image_root', '/web/d2/w/mydomain/mydomain.com/images/');
Then I try to pass this path to the image:
$imageurl = image_root . $myrow['image'];
echo "<div id=left><img src='$imageurl' border=1></div>";But it doesn't work...
Any ideas?

Requiring File From Root While In Sub-domain
I'm trying to include a file from my root directory but I can't figure out how to. The file that is requiring is in sub.domain.com and the file to be required is in domain.com.

How would I go about including it?

Display Image Above Root Directory
Is it possible to display an image that is above the root directory using php?

for example if i have an image in /home/user/uploads/test.jpg and lets say my root directory for my site is /home/user/public_html/

is it possible to display test.jpg on /home/user/public_html/index.html ?

i am trying to create a secure file upload script and i think not having the file be directly accessed by the public is one of the main steps.

Document Root/include Path Problem
My site is/will be housed on a 3rd party host. I do not have control of the server variables.

Neither $DOCUMENT_ROOT or include_path are pointed anyplace I can use

Does anyone know what I can do do get the server path to my main directory(short of hard coding it).

.tmp Files Being Placed In The Root Directory By The 100's, Want It To Stop
Hi folks, I have a bit of a problem, perhaps one of you knows what is going on.

According to the sys admin at my ISP, something from my site (which is entirely php) is saving 100's of tiny files with the extension .tmp into the root directory on the server where my site is located.

He doesn't know very much about PHP and neither do I (this is the first site I've ever produced using it) so neither of us knows what could be causing it, there is one other site hosted on that server that is running PHP and it is doing the same thing, although the lion's share of temporary files are coming from my site.

I have a copy of the php.ini file that he emailed to me this morning, if it would help to post it please let me know and I will do so. We are not sure what is going on, but we would like to know if there is some way to make it stop (or at the very least, to get these files to destroy themselves once they're no longer usefull)

Also: I would like to thank SilkySmooth for his mail script, I used it awhile back and it got the job done. Thanks so much!

Access Denied For User: 'root@localhost'
Warning: MySQL Connection Failed: Access denied for user: 'root@localhost' (Using password: NO) in /www/apache/domains/www

usually this error occurs when i've wrong password, i'm sure i haven't.

other strange thing is that it says root@localhost... should it? this crap happened after my webhost company upgraded their servers... the code must be fine!!! i think so at least... before it worked... i checked the password, host, and username are fine...

Problem With Locating Image Directory From Root
All i want to do is change my following method that works fine, so that it checks from the root directory.

This is what i originally have and works fine:

$file_name = 'products/'.$pId.'s.jpg'
if (file_exists($file_name))
$test = true;
else
$file_name = 'template/noimage.gif'

I tried changing the following line but it does not locate the image:
$file_name = '../products/'.$pId.'s.jpg'

The folder 'products' and 'template' are in the root directory.
ie. root/products...


Copyright © 2005-08 www.BigResource.com, All rights reserved