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

1 Answer 1

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();
5
  • 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 5, 2013 at 8: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 5, 2013 at 8: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_ May 6, 2013 at 14:35
  • You should read a Unix book/documentation about permissions, SetGUID... May 6, 2013 at 14:37
  • See also: serverfault.com/questions/127658/… May 6, 2013 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .