Jump to content


Photo

php.ini


  • Please log in to reply
3 replies to this topic

#1 mrippon

mrippon

    Newbie

  • Member
  • Pip
  • 1 posts

Posted 31 July 2006 - 11:50 AM

Hi, I'm using uniserver to develop my website on my local machine so I don't have to keep uploading files to my remote server to test everything.

I don't have access to the remote server's setup so to change some of the settings (in particular auto_prepend_file and auto_append_file) I created my own php.ini and put it in the base directory of the server where my index.php is. This works great on the remote server but on my uniserver setup, the php.ini file seems to be completely ignored no matter where I put it (I would expect it to work if it was in the www folder?)

If I modify the main php.ini and restart uniserver then it works but that isn't much help because it breaks the apanel.

I'm using the default setup of uniserver 3.3. I know I am probably missing something really obvious but any help would be appreciated as I am a bit of a novice when it comes to setting up servers.

#2 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 01 August 2006 - 11:38 AM

An alternative to using php.ini is to use .htaccess for auto_prepend_file and auto_append_file, this example explains how.

1) In your root folder (wwww) create a new folder named atest

In this folder add the following files:

test.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>This is a test file</p>
<? echo "<h2>Content TEST</h2>"?>
</body>
</html>

top.php
<h1>TOP TEST </h1>

bottom.php
<h1>BOTTOM TEST</h1>

.htaccess
<IfModule mod_php5.c>
php_value auto_prepend_file "top.php"
php_value auto_append_file "bottom.php"
</IfModule>

Top.php and bottom.php are not practical however they do demostrate the point.
View test.php in a browser and you will see the files have been appended and prepended accordingly.

2) In the folder that you created (atest) create a new folder named test2

In this folder, add the following file:

test2.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test page 2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>This is a test2 file</p>
<? echo "Content TEST2" ?>
</body>
</html>

View test2.php in a browser and you will be greeted with an error message similar to this:

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0

Warning: Unknown: Failed opening 'top.php' for inclusion (include_path='.;/usr/local/PHP/includes;/usr/local/PHP/pear') in Unknown on line 0

The reason why this does not work is because includes (note: auto_prepend and auto_append are just fancy includes) are relative to the file that initiated them in this case test2.php. The directives in .htaccess were applied to the file however the includes were not found in the current folder (test2). At this point PHP does not give up hence it looks in any include paths for the files. It still cannot find the files, gives up, and produces the error message.

I have laboured this a little to make a point in most cases the answer lies in the error message this is crying out for an include path to fix the problem. The final .htaacess file looks like this:


<IfModule mod_php5.c>
php_value include_path ".;/www/atest"
php_value auto_prepend_file "top.php"
php_value auto_append_file "bottom.php"
</IfModule>

The include path points to the folder that contains the pages to be included. Net result of adding the above line is that any php file within the folder containing .htaccess and sub-folder files will have top.php and bottom.php automatically included.

All the best :D

#3 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 05 August 2006 - 02:59 AM

I forgot to answer your original question. :lol:

I think the reason why your php.ini is not seen is because UniServer runs PHP as a module hence php.ini is only used (read) when apache is started. If PHP is running as a CGI then the php.ini file is checked per request just like your service providers installation. In terms of security, there is some debate between running php as a module or as a CGI, looks as if the UniServer team has chosen running as a module.

Could be wrong :D

#4 olajideolaolorun

olajideolaolorun

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 2,348 posts
  • Gender:Male
  • Location:Atlanta, GA
  • SourceForge IDempirex
  • Wiki ID: olajideolaolorun
  • IRC Nickname: Olajide
  • Main OS: Windows 10

Posted 11 August 2006 - 10:27 PM

You cannot put it anywhere! It is not mobile and not meant to be moved! And there are some variables that must be in the file so modification of the original is the best way to go.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users