I have created my own PHP extension in c++ and am using Centos7 - php 5.6 version.
I wants to write the my extension debug log into the web server logging directory.We can get this from PHP by calling phpinfo() method.
from /etc/httpd location logs directory symbolic link with /var/log/httpd/
How can we get this Apache configuration location from my PHP extension in c++?
Even if you were able to parse the web server's configuration file in PHP, you wouldn't be able to create your own log file. Worker processes in web servers usually don't have permissions to create new files in the system log directory.
If you need to print debugging messages, generate them with php_error(). They will be passed to the web server for error logging.
Related
I'm copying a file from $source to $destination.
If I execute copy($source, $destination) from PowerShell, it works.
If I call this copy($source, $destination) from Apache, it complains copy(...): failed to open stream: Permission Denied.
I am able to open up explorer and copy and paste file manually. I am using PHP 7.1, Apache 2.4 on Windows Server 2012R2.
Why is this happening? Could someone provide an insight?
If run under Windows Apache already has all the permissions it needs, as it runs under the LocalSystem account, which has extensive read/write access to local paths. This is inherited by PHP and the scripts it runs.
If there is a problem then –
The additional file permissions that have been set up afterwards are at fault (check Windows Event viewer).
The configuration has been incorrectly edited, such as the: WP upload path settings, php.ini temp folder location + upload settings, etc.
The Apache Service ‘Log On’ account has been changed from “LocalSystem” to something else (check Service’s Properties).
Possibly PHP’s open_basedir setting has been enabled in VirtualHost or .htaccess and is restricting the paths PHP can access.
Or there are internal PHP errors (check the website’s HTTP and PHP error logs).
EDIT
Since it is sugggested i add this solution possibility if you are stuck at point 3:
Create a user with extensive file permissions and change Apaches service to run under that user. I strongly suggest not to use the system admin user (or any admin user) profile for this.
How to run a php file from ubuntu platform in the localhost?
I have also installed LAMP in my system.
When I try to run the php file, in the browser, it says "The requested URL is not found-404 ERROR found".
I do not know how to proceed with this.
My php files are in the directory as shown here "/usr/var/html/a.php".
There are two options.
Access the php file through a local webserver(ie thru a local website). The web-server will deal with the requested php file. It will use either,
Inbuilt PHP module to interpret the php file, or
PHP through CGI (eg.CGI, FastCGI)
If your apache(check if apache is running using service apache2 status!!) is set to the default configuration, this could be as simple as
http://localhost/path/to/your.php
Remember by default, the base directory for apache is /var/www/html/, so you need not include this in the url.
Use the php binary directly from a terminal.
php /path/to/your/file.php
After installation of Lamp system in Ubuntu. Please follow the below two steps to run your php file.
Place your php file (.php) in /var/www/html/ (default path)
Please run url as localhost/withfilename.php
Example : I have placed welcome.php file in the /var/www/html/welcome.php
then url will be http://localhost/welcome.php
When I log messages via error_log() in my PHP web app, the messages get logged in Apache's /var/log/httpd/error_log.
When I log messages the same way in a PHP command-line app, the messages go to PHP's own php-error.log
Is there a way to log messages to PHP's error log from a PHP web app?
In your php.ini file look for this parameter
error_log =
And set it to whatever filename and location you want.
Of course if you want to seperate your web PHP error logs from your PHP CLI error logs then you need to remember that there are normally 2 php.ini files
One that is used by Apache/PHP and the other that is used by PHP CLI possibly /etc/php5/cli/php.ini
If you change the php.ini file used by the PHP CLI you can have a different file name completely used for the error logging from PHP CLI scripts
Look for
error_log =
and change to
error_log = /var/log/php_cli_errors.log
for example.
I get page not found error when I try to run my php file running on the root folder of my apache. Other php files run fine(anyway this is a magento based site). Is it because i transferred the file through FTP?
Can a server be configured not to run some specific files? How can i get round this? has is got something to do with .htacess?
Be sure you uploaded your file into the /www or /httpdocs subdirectory.
If so, check the permissions of your file.
Does the fiel have the same extension as the other php files that work.
ie. myfile.php or myfile.php4
The default config for apache specifies that php files have the extension "php4" as php version 3.0 and before are not compatible with the current versions. Usually the plain "php" extension is re-enabled but maybe not in your case.
I have a multi-server environment ( all windows 2003 ).
I manually installed php 5 on the appserver.
I also plan to install mySQL on the appserver.
on the webserver, which is DMZ'd, I added the php5isapi.dll extension under iis6 > web service extensions.
I was able to do that by giving the unc path to the isapi dll on the appserver
\\local ip address of appserver\c$\php\php5isapi.dll
when attempting to add the ".php" extension mapping on
webserver >> iis6 >> default website > properties > home directory > configuration >
add mappings
Windows says that I can't use a UNC path
\\local ip address of appserver\c$\php\php5isapi.dll
to access the .dll file which is on a different server.
so I'm confused. I thought that the I was going about this the right way - by setting up my appserver (backend) to do all the php processing and telling the webserver where to send the php jobs.
what am I missing or what should I be doing differently?
even if that worked, that wouldn't make the php run on the appserver - it would load the dll from the appserver into memory on the webserver and run the code there. you need to set up the file association only on the machine you want to execute the php on