Blank PHP page on windows server 2012 - php

My PHP page is showing blank page when I try and run it on the server by calling the IP to the windows server and the directory to it, when I try and run HTML on the same server it works.
When I run it on Apache localhost it works perfectly as well!
Can someone tell me whats the problem?

yeah, check the apache logs! probably your error reporting is off, it might be setting in your php.ini file (you can run php --ini to see files being used if you have shell access to server), just remember, there might a separate php.ini file used for running php shell from with command and separate for when it's run through web, just remember, get the right php.ini - this will show you errors :) and then you can see whats wrong with your app... on a linux server logs should be in /var/logs/httpd(or apache2 depending on your version)
btw. check this one http://php.net/manual/en/function.error-reporting.php

Related

PDFLib installed but not available in code or visible through phpinfo()

I think I did quite a good job on installing PDFlib on a system (Ubuntu 18.04) but something's not totally right yet. What I did so far:
Followed the instructions here: https://www.pdflib.com/fileadmin/pdflib/pdf/support/PDFlib-in-PHP-HowTo.pdf
Downloaded the correct php_pdflib.so file and placed it in the extension directory I got through phpinfo()
Added extension=php_pdflib.so in my php.ini
Ran a sudo systemctl restart apache2 to restart Apache and reload extensions
Checked with php -i | grep PDF whether the binary was loaded or not, result seems positive
PDFlib
PDFlib Support => enabled
PDFlib GmbH Binary-Version => 9.2.0
Now, when I run phpinfo(); from the web side through a file, there is no mention of PDFlib at all. When I run it through CLI, everything seems to be okay.
I also tried creating a new PDFlib() instance through CLI and web. CLI works, web doesn't.
Did I miss something in the install process?
I also tried creating a new PDFlib() instance through CLI and web. CLI works, web doesn't.
this is a typical situation. The PHP CLI and the PHP within the web server could have different configuration. So please check the extension_dir as well which the php.ini which was loaded in your web server phpinfo() output. Then you have do the the same configuration. Please check as well the PHP/Webserver log file for any error messages. Maybe it might be NTS/TS (threading) issue as well, but this will be mentioned in the error message.
Being not a good engineer today, I did several things at once, so I can't tell what exactly worked out in the end. Will write down my steps nevertheless, as it works now.
I double checked the configuration file paths and files through php -i and a phpinfo(); to see the differences between CLI and web frontend.
I removed the extension=php_pdflib from both php.ini files
I moved the php_pdflib.so from the extension directory one level up, it now lives in /usr/lib/php directly
I also renamed it to phplib.so (but that was more to break things on purpose and see what happens
I created a 30-pdflib.ini file in /etc/php/7.3/fpm/conf.d and wrote only extension=/usr/lib/php/pdflib.so in it
Added that line to /etc/php/7.3/cli/php.ini to see if there's a difference
I tried restarting Apache2 several times, but phpinfo() did not show any changes for the loaded configuration files or modules
I did a sudo reboot
Checked again and now PDFlib is loaded for CLI as well as for web
So, not sure if a hard reboot really fixed this, but it seems to me like that. Maybe this helps someone else.

Apache2 server on raspberry pi will not run any php scripts

I have set up an apache2 server on the pi, but when trying to run any php file (placed in /var/www/html) the web page just responds with HTTP error 500. I have ran the index.html file and it works fine its only when php scripts are run that it gives me an error. I have also made sure that the php5 module is enabled in the apache configuration settings. Any advice on what to test from here would greatly help.
Update: Seems there was a problem with the permissions of the file. By giving read and write privileges by all users to the file it worked.

PhP Cake app in Apache2 in Ubunutu not working but working find in window's wamp

I have a web application that is writen in php using cake framework. In windows environment i use wamp and it works find if i enbale apache read_write. Then I shift to use Linux environment Ubuntu 15. I have installed apache2 already and php too. it is all work. But when I put my app in /var/www in ubuntu and open the web page it said that the require_once function cannot file the location of the file.
I already change the owner of the www/* to www-data already, but it is still not work. mod_readwrite of apache is also enabled. So I want to know how could I enable read_write in Lamp like in wamp that I did on window? I met the same error in window if I don't enable it. So think it is the problem. Can anyone help me to solve this problem?
One thing you will want to check for is that you're using the proper directory separator in any paths you're using for your require statements (this can be done by using the DIRECTORY_SEPARATOR constant in place of hard coded slashes in your paths)
Another thing you will want to do is look at the apache configuration for each environment and ensure that they are the same. In particular check to ensure that your virtual hosts are defined correctly.

Why is PHP not recognizing a program in the Windows System PATH when I use it with Apache?

In my local development environment, I have Apache and PHP installed on Windows 7. I'm calling 7-Zip from my PHP program with exec. I tried at first with
exec('7z a example.zip example.pdf');
but it didn't create the zip file. After checking the Apache error log, I found
'7z' is not recognized as an internal or external command, operable program or batch file.
After changing the exec to include the full path to 7-Zip.exe, it worked.
exec('"C:\\Program Files\\7-Zip\\7z" a example.zip example.pdf');
But C:\Program Files\7-Zip is included in my Windows system PATH. The same PHP code works from the command line without using the full path.
php -r "exec('7z a example.zip example.pdf');"
Why is it requiring the full path when I use it with Apache?
An important point which I neglected to include when I originally posted this question is that I am already able to use exec() to call other programs included in the Windows System PATH without referring to them by their full paths.
Another point which I did not mention originally because I did not realize its relevance was that 7-Zip had been added to the PATH only recently, and I had restarted the Apache service after adding it.
I've WAMP installed on windows 8 and after reading your question I decided to test a couple of things.
Running echo exec('whoami'); echoed:
nt authority\system
This confirms what #Barmar said, Apache isn't running under the same user as you, so, the PATH is different.
I decided to stop Apache and start it manually under the Administrator account.
Then I tried:
echo exec('whoami');
Which outputted:
computername\administrator
I assumed that now the exec would work with PATH and tried:
echo exec('adb'); //android adb tool is on my PATH
Surprisingly, despite the fact Apache was running with the same user as me, the PATH still didn't work. I've no idea why this is happening and if someone has a clue please comment below.
I managed to use the PATH (using the Administrator account) with the following code:
https://stackoverflow.com/users/171318/hek2mgl
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C 7z a example.zip example.pdf", 0); // 0 invisible / 1 visible
I didn't test the code below, but you can try setting the PATH under the Apache Service account (nt authority\system), and then use the command, i.e.:
echo exec('set PATH=%PATH%;C:/path/to/7z');
echo exec('7z a example.zip example.pdf');
I believe the path will still be valid between restarts.
Update:
this answer, may help you setting the PATH for the account nt authority\system.
The Local System user's personal environment variables are specified
at "HKEY_USERS.DEFAULT\Environment". The machine-wide environment
variables are specified at
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment". The former isn't really easily accessible from
anywhere except the registry, but the latter is accessible from the
"Environment Variables" dialog on the "Advanced" tab of the "System
Properties".
For future users, the correct way to set the Apache PATH is:
You can use setEnv in .htaccess or putenv in PHP code to set
$PATH
Credit goes to hek2mgl
I just figured out what was causing this problem. It was actually unrelated to my original assumption.
I remembered seeing PATH information in phpinfo(), so I looked at that. In the "Apache Environment" section it did show all of the PATH except the path to 7-Zip, which I had just added to the system PATH recently. So apparently it DOES seem to have access to that path, but it wasn't using the current version of it. Why not?
Normally I would think I had just forgotten to restart Apache after updating the path, but I'd restarted it repeatedly while trying to figure this out. But apparently restarting Apache does not refresh this value. I had to stop it and then start it. Then the 7-Zip path showed up in PATH in phpinfo, and I was able to change my program back to using plain 7z.

error when restarting Apache webserver

I installed Apache web server successfully.When I type the local host in browser it shows that it works. And then I save the php file to server httpdocs and restart it shows the the following alert.
Apache monitor is Already Started.
Please let me know where I am going wrong ?
You don't need to restart Apache every time you save a php file in httpdocs. just refresh you browser.

Categories