Unable to set upload_tmp_dir on IIS - php

So I'm trying to set the php upload_tmp_dir setting on an IIS machine.
I changed the setting in php.ini but phpinfo() still shows the default folder. I checked the permissions of IIS_IUSRS who have write, read, modify, etc.
I also ran this to check if the new folder was writable:
$filename = 'C:\inetpub\temp\uploads';
if (is_writable($filename)) {
echo $filename . ' is writable';
} else {
echo $filename . ' is not writable';
}
I changed the max_file_uploads value to test if the PHP config being loaded was the most up-to-date, and it was.
What am I missing?

And it turned out the php.ini config file had duplicate entries for upload_tmp_dir, the last of which was the default folderc:\windows\temp. I commented that setting out and everything is now fine.
This thread got me to check for that.

If you look towards the bottom of the file you will find this.
[WebPIChanges]
error_log=C:\Windows\temp\PHP54_errors.log
upload_tmp_dir=C:\Windows\temp
session.save_path=C:\Windows\temp
cgi.force_redirect=0
cgi.fix_pathinfo=1
fastcgi.impersonate=1
fastcgi.logging=0
max_execution_time=300
date.timezone=America/New_York
extension_dir="C:\Program Files (x86)\PHP\v5.4\ext\"
Chance the temp directory here too or comment it out.

Related

Cannot create temporary file in unknown PHP upload

I'm building a desktop app with PHP desktop, I'm using Angular on front and Laravel at back, I'm trying a series of file uploads non of which seem to work on the clients PC but work fine on mine. He gets the error in his console - cannot create temporary file in unknown on line 0. My front-end for upload is
public formdata = new FormData()
setFile(element){
let file = element.target.files[0];
let name = element.target.id;
this.formdata.append(name,file);
}
createTraining(data){
this.formdata.append("data",JSON.stringify(data))
let url = this.$api.base()+"/training/new";
this.$http.post(url,this.formdata).subscribe((rez:any)=>{
console.log(rez);
if(rez.state){
this.$modal.dismiss()
}
})
}
My back-end is
if(#$request->file("tsd_file")){
$training->tsd_file = #$request->file("tsd_file")->store("public");
}
if(#$request->file("sc_file")){
$training->sc_file = #$request->file("sc_file")->store("public");
}
if(#$request->file("ta_file")){
$training->ta_file = #$request->file("ta_file")->store("public");
}
if(#$request->file("tka_file")){
$training->tka_file = #$request->file("tka_file")->store("public");
}
if(#$request->file("dte_file")){
$training->dte_file = #$request->file("dte_file")->store("public");
}
if(#$request->file("ete_file")){
$training->ete_file = #$request->file("ete_file")->store("public");
}
Although I hardly believe the above matter. In my local system, PHP's sys_get_temp_dir() function returns "C:\Users\noble\AppData\Local\Temp".
But on the clients pc, his system tmp dir is C://windows/temp. I wonder if that could be a contributing factor, I would appreciate some help in finding ways to resolve this
my php.ini in the root of PHP desktop is
; Extensions
extension_dir = "ext/"
extension=php_curl.dll
extension=php_gd2.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
extension=php_sqlite3.dll
extension=php_com_dotnet.dll
; Date
date.timezone=Europe/Berlin
; Errors
error_reporting=E_ALL
display_errors=On
display_startup_errors=On
log_errors=Off
report_memleaks=On
report_zend_debug=On
; General
short_open_tag=On
ignore_user_abort=Off
implicit_flush=Off
output_buffering=0
default_charset = "UTF-8"
; Execution time
max_execution_time=30
extension=php_fileinfo.dll
; Memory
memory_limit=128M
; File uploads
; "post_max_size" must be equal or bigger than "upload_max_filesize"
max_file_uploads=20
upload_max_filesize=20048M
post_max_size=2049M
; Smtp server is not included with phpdesktop
SMTP=127.0.0.1
smtp_port=25
Turns out all I needed to do was have the clients enable write permission and access to the windows temp folder. All works well now

Starting web server with `php -S` not reading php.ini file

I have a local project I am working on. I have at the root of my project and index.php php.ini and local_connector.php.
When I run php -S ... from inside my project. It says that the php.ini is not loaded.
This is the code I have in my index.php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
This is what I have in my php.ini
auto_prepend_file = "./local_connector.php"
The idea is I will have multiple pages that use the local_connector but I don't want to include it in every file. Is this possible with php's local server?
I would rather not set up an entire local apache server, so if someone knows a good way of getting this to work, or a work around. That would be very helpful.

I can't see the errors on MAMP PRO [duplicate]

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?
php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"
You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site
Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.
Create a simple page and it will be listed there!
<?php
phpinfo();
?>
As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

session_start() returns "No such file or directory" directly after creating the session file

I'm trying to set the session.save_path on my IIS/PHP via fastcgi server. So I created a new folder called tmp in my php folder, gave IUSR and IIS_IUSRS full permissions to this folder, and set my session.save_path variable in php.ini to "\tmp".
Upon loading my webpage I get the error:
Warning: session_start(): open(tmp\sess_gp13t5fg969iddfq1lrt3e88o1, O_RDWR) failed: No such file or directory (2)
The weird thing is I know it can see the folder because I look in my newly created tmp folder and it actually created the sess_gp13t5fg969iddfq1lrt3e88o1 file right before throwing the error telling me it doesn't exist. So how can it create the file and then not see it? What could I be doing wrong?
Update: If I set session.save_path with an absolute path, it works. When I give it a relative path of just "\tmp" it no longer works. Every example I see uses a relative path for the save_path and I personally need to use a relative path. Why would a relative path cause this issue and how do I fix it?
I found the answer you seek:
Relative Paths in PHP
include($_SERVER["DOCUMENT_ROOT"] . "/relative path here");
Under linux the PrivateTmp config of systemd may be the problem.
The solution would be to copy the corresponding systemd unit file to /etc/systemd and remove there the privatetmp config.
In my case:
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system
systemctl daemon-reload
systemctl restart httpd.service
Change in /etc/systemd/httpd.service then
PrivateTmp=true
to
PrivateTmp=false

How can I know which 'php.ini' file is used?

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini files when executing the command find / -name php.ini. So how can I know exactly from a PHP script web page where the php.ini is located?
php --ini
For the webserver-SAPIs use phpinfo()
Here's some sample output:
bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
create info.php that contains <?php phpinfo(); in the webroot, and run it in your browser
Note that the configuration loaded for PHP when it's being used in the console is different from the configuration for the web process. Most PHP installations would come with a php.ini file for Apache and another for CLI.
To know which configuration file is used for the console commands, use
php -i | grep "Configuration File"
To know which configuration file is used for the web processes, follow these steps
Create an info file (preferably in the root folder)
The contents of this file should be <?php phpinfo(); ?>
Ctrl + F and search for "Configuration File"
You have to use the PHP method php_ini_loaded_file (only after PHP 5.2.4)
php_ini_loaded_file — Retrieve a path to the loaded php.ini file
PHP website example:
<?php
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
Source: PHP site
Just add a file like this:
<?php
phpinfo();
?>
Then look for
Loaded Configuration File
You'll see the full path for the php.ini file.
Create a simple page and it will be listed there!
<?php
phpinfo();
?>
As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for three different versions of PHP on my server and I got the fix instantly then.

Categories