I apologize if this has been asked before, but...

I work on a site with a friend of mine. Recently he transferred the site from being hosted on a Unix server to being hosted on his own server running Windows Advance Server 2003.

He seems to know about as much about setting up servers as I do (which isn't much!), and although he's gotten PHP running, none of my PHP scripts that write files work. I've looked up answers and he's tried different things, but so far he hasn't been able to resolve the problem. Without being able to use fwrite() I will have to update several areas of the site by hand.

Here's a sample error:

Warning: fopen(file.txt): failed to open stream: Permission denied in G:\modelsonline\tests\write.php on line 11

Warning: fwrite(): supplied argument is not a valid stream resource in G:\modelsonline\tests\write.php on line 12

Warning: fclose(): supplied argument is not a valid stream resource in G:\modelsonline\tests\write.php on line 13

Can someone give me the dummies version of how to resolve this so I can explain it to him?

    This error is not caused by running php/apache on server 2003 as one of my servers runs 2003 with php/apache using fwrite & fopen and I have no problems at all. Also, I have seen threads with identical errors on linux/unix boxes and other windows flavours.

    If this was working previously on a linux box, then the only two things that come to mind are:

    1. File permissions on file.txt (check the read-only attribute is not switched on - server 2003 is rather paranoid with files and permissions and the like)

    2. Differences between your php.ini file and the one on the linux box (compare the php build and the php settings between the two servers for differences).

    HTH

    Jonathen

      I don't believe he's running Apache. It's Windows Advance Server 2003 with IIS 6, that's all I know.

      file.txt doesn't exist, the script should create it if it's not there.

      I doubt we can get access to the php.ini from his previous host.

        I see. I run Apache on server 2003. When I got a similar problem with fopen etc not working on my server, I simply created a blank file (in your case create file.txt with nothing in it) and put it in the web directory. That way the php script could find the file and write to it. Not the best way of doing it, but a quick workaround until you find a better solution.

          7 days later

          hi im running too on win 2003 apache and php i have a question can u tell how i can fix this
          "Security Alert! The PHP CGI cannot be accessed directly.
          This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive".
          thanx in advance

            7 months later

            You need to edit the ini file to get rid of that...

            Now I have this problem:

            phpBB : Critical Error

            Could not connect to the database

              The phpBB could not connect error sounds like your phpBB is trying to connect to MySQL, and most likely, your username and password for MySQL have changed on the new box (if he's even running MySQL on Win2003Server, it is most likely Microsoft SQL, which you will not be able to simply port over to, because of comparion differences and data type differences, unless phpBB also serves up a Microsoft SQL distribution)

              The file permissions errors should not be because of the php configuration or the server, it is most definately sounding like permission errors. In the folders that you are trying to edit and create files, change the permissions on the folder for read/write access for HTTP_ANON user (this is the Windows equivalent of the httpd user on a *nix box)

              Shoot me anymore questions if you have them.

                I figured it out... I needed to install the MySql Admin Panel.. now it all works fine!

                If anyone else needs help with these problems my email is Lee@captivemoon.com

                Thanks Hearn!

                  a year later

                  I installed Apache and PHP on Windows Server 2003. IIs is not installed (I don't want to learn it right now.) Apache works fine, but PHP does not. (i.e. phpinfo does not run) What do I have to enable on Windows Server 2003 to get PHP to run? This same install worked fine on XP pro, so I am thinking my install is fine. Thanks for your help and ideas!

                    Do you have any more specifics on the problem, such as:

                    Are you getting errors in your logfiles, or errors output to the browser window. Turn on debugging errors because if you're getting a white page it is most likely set in php.ini to not display errors directly to the user and the script is dieing on load.

                    Have you properly installed php and put all .dll files in the correct place (probably windows/system32) Make sure you register all of the dlls with regsvr32 filename.dll in the current directory

                    Any other debugging information, what exactly is not working with phpinfo() and other functions.

                    I'll help as much as I can but usually people run IIS on windows with PHP instead of Apache. IIS is not very hard to learn and it is quite a bit easier to configure then Apache, especially on a windows machine. If you are gonna go the IIS way and you have any questions let me know, I'm pretty experienced in IIS.

                    Hope that helps, get back to me with as much info as you can.

                    Cheers.

                      Write a Reply...