Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Fix PHP CHMOD and Other File Operations (Creating Files)
#1
PHP chmod and creating new files do not work correctly with EHCP. This is because files uploaded via FTP are owned by the vsftpd user. The Apache user is www-data. Since PHP runs as a module of Apache, the owner should be set to www-data, or PHP won't be able to modify or create new files.

The easy way to fix this:
<code>
sudo chown -R www-data:www-data /var/www/vhosts
</code>
There's a better way to handle changing the owner in realtime as new files and folders are uploaded and created through FTP by using inotify. This little program proactively monitors and immediately sets the owner on all modified (written to) or created (new files or directories) files by using inotifytools. To install inotifytools, run this command:
<code>
sudo apt-get install inotifytools
</code>
Next, you'll want to increase the number of watch counts (max number of file monitoring handles) by running this command:
<code>
sudo echo 50000 > /proc/sys/fs/inotify/max_user_watches
</code>
Now, we need to create the real-time monitoring script using the inotifytools API.
<code>
sudo touch /root/monitor_vhosts.sh
sudo nano /root/monitor_vhosts.sh
</code>
Paste and save the following into the file:

<code>
#!/bin/sh
while inotifywait -r --exclude '.*(access_|sess_).*' -e modify -e create /var/www/vhosts; do
chown -R www-data:www-data /var/www/vhosts
chmod g+s -R /var/www/vhosts
echo -e "EHCP Permissions Fixed"
done
</code>

This script runs continuously and looks for changes in files. When it finds them, it executes the changes specified (changing owner to www-data). Let's make the script automatically start on bootup under the root user by running this command:
<code>
sudo sh -c "echo '/root/monitor_vhosts.sh' >> /etc/rc.local"
</code>

Things should finally work properly on your server! Enjoy EHCP and PHP working 100% properly.

Restored from old drupal forum, for user uid:2735 username:own3mall
You may reset your password to access your new account here.
Reply
#2
Actually, this script works better and is more efficient:

<code>
#!/bin/sh
while true; do
change=$(inotifywait -r -e modify -e create /var/www/vhosts --excludei '.*(access_|sess_|cache).*')
fPath=$(echo $change | grep -o "/.*/")
file=$(echo $change | grep -o "\ [^ ]*$" | grep -o "[^\ ]*")
theFile=$fPath$file
fLength=`expr length "$file"`
if [ $fLength -gt 0 ]
then
chown -R www-data:www-data $theFile
fi
done
</code>

Restored from old drupal forum, for user uid:2735 username:own3mall
You may reset your password to access your new account here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)

Online Shopping App
Online Shopping - E-Commerce Platform
Online Shopping - E-Commerce Platform
Feinunze Schmuck Jewelery Online Shopping