1

I'm quite new to Linux so please excuse my ignorance, and accept my apology for what is likely a very lame question.

I have setup a Centos 6.4 server and also installed LAMP, phpmyadmin, mod_ssl and vim.

This server is to host a single website only, but I have set it up as a virtuial site per what appears to be a best prcatice.

This site will have its content uploaded via SFTP by a 3rd party, and this has been tested to work OK.

I have found that simple PHP seems to work OK, so as the following script (named info.php) works OK:

<?php
phpinfo();
?>

This correctly shows the PHP versioning when I browse to mysite/info.php.

However, I've created the following simple PHP (named test.php) to write a text file:

<?php 
$myFile = "test.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "TEST1\n";
fwrite($fh, $stringData);
$stringData = "TEST2\n";
fwrite($fh, $stringData);
fclose($fh);
?>

When I browse to mysite/test.php, the page displayed is the text value can't open file, which appears to come from the or die statement.

My issue is that I am unaware of why these scripts refuse to run.

Any help will be most appreciated.

Cheers,

Ben

Benny
  • 11
  • 1

1 Answers1

1

This is a permission problem. Make sure that apache can write into the current folder. To find out the current folder from php:

echo getcwd();
Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
  • Hi Mircea thanks for your response. I'm not sure how to use this command you have given me. I have added into a PHP file to execute, but it only displays the text as written. I am a real amateur at this, sorry. – Benny May 05 '13 at 08:19
  • I have worked out now how to use this command and have discovered that a simple command run with echo getcwd(); shows me the directory that the file was run from. Where would I put this command in the example file that's not running please? Also how do I add PHP permissions to my virtual directory please? – Benny May 05 '13 at 08:29
  • You need to make sure that apache process has access to write into the folder printed by `getcwd()`. You can give access to apache with: `chgrp apache _folder_name_;chmod g+rwxs _folder_name_` – Mircea Vutcovici May 06 '13 at 14:35
  • You should read a Unix book/documentation about permissions, SetGUID... – Mircea Vutcovici May 06 '13 at 14:37
  • See also: http://serverfault.com/questions/127658/how-do-i-set-permissions-structure-for-multiple-users-editing-multiple-sites-in/127686#127686 – Mircea Vutcovici May 06 '13 at 14:38