<?php
echo file_put_contents("/tmp/log.txt", "Hello world everyone.");
The code is very simple, and it shows success when running on the browser and command line, as: 21
. But after the browser is run, /tmp/log.txt does not exist. Under the command line, /tmp/log.txt was created successfully (no problem for root and apache user testing). Very confused. . . . . . .
uname -r
: 3.10.0-514.2.2.el7.x86_64
They are all installed through yum install, yum install httpd php5
The /tmp directory should have the maximum permissions. Is there no permission problem? Open the error message and see the error message
First, confirm the folder permissions to allow writing and then
User questions? It is estimated that you are the root user under the command line, so the execution can be successful. Check to see if your web directory belongs to another user group, and this user group does not have read and write permissions on the temp directory.
Do you have permission? ! !
It should be a permissions issue. It is also unsafe for PHP to operate the tmp directory, so it is definitely not allowed by default.
Why is it said to be unsafe? Because if you can write, you must be able to read (for PHP, it is basically impossible to only write but not read without setting permissions)... In this case, hackers can read a lot of information
Simple and crude test: chmod -R 777 /tmp
Then see if it can be written.
Browser running / refers to the website root directory. Command line / refers to the server root directory. Please check whether there is a /tmp/log.txt file in the website root directory