I've just uploaded a simple symfony2 app on a production server, and I get this configuration error:
2 MAJOR PROBLEMS
Change the permissions of the "app/cache/" directory so that the web server can write into it.
Change the permissions of the "app/logs/" directory so that the web server can write into it.
editing "app/console", "web/app.php" and "web/app_dev.php" with: umask(0000) doesn't work, and if I right click on that folders with FileZIlla, their permissions are already 777. And so?
thanks...
You need to recursively set the permissions, most likely. I'm guessing FileZilla has that option, if not, ssh into the box, and run (replacing /path/to with the actual path)
sudo chmod 777 -R /path/to/app/cache
sudo chmod 777 -R /path/to/app/logs
Sidenote: setting the permissions to 777 is usually a really bad idea.
umask(0000) doesn't actually increase the permissions available to the script. It just ensures that files & directories created by those scripts are accessible from both the command line and the web server. If you're not using the command line, you probably don't need it at all.
Related
I have made a lot of Symfony apps that work in production, but recently tried deploying one to Ubuntu 16 for the first time. var/logs/prod.log shows errors about not being able to find classes, so of course the app won't run.
I can "fix" this with chmod 777 /var/www/ -R, and everything starts working. Surely that's not safe... How can I fix this the right way?
Note: I am currently not logged in as a user but as root.
*EDIT
The app will not run after chmod 777 /var/www/var -R to change permissions for chache and logs, but only if I change the permissions for all the folders of the entire app.
You might try locating folders/files which are the problem and change ownership to www-data which is actually used by Apache.
For a whole directory with files recursively:
chown -R www-data:www-data [folder_path_and_name]
For a specific file:
chown www-data:www-data [file_path_and_name]
Symfony has a section in the documentation for file permissions
Mainly you need to adjust the apache user permissions for logging, and as root you can easily do that.
Just remember to ignore the logs + cache if you're using source control such as Github.
I recently set up my first VPS, and fully self configured PHP, Apache and all that good stuff, but when I tried importing one of my projects that deals with fwrite in it, when I try to do an fwrite, it will not throw an error, but it does not write. The only things I have tried so far was to chmod 777 the folder main folder of the project. This did not fix the issue. Is there anything in the php.ini default set to disallow fwrite? I am able to fopen and fread perfectly fine.
Try putting this at the top of your PHP page.
error_reporting(E_ALL);
ini_set('display_errors', '1');
More than likely you'll find that you have a permission denied message. If not, post the message here (If OP is still around).
A quick fix, perhaps not the most secure option, could be to log in via SSH as super user, run chmod -R 0777 [home directory]
For [home directory] just put the base folder that your files are being served from (www, home, public_html, etc...).
If you find that this works, I'd strongly recommend that you narrow the permissions; at least down to 0755.
The reason why this may work when your previous chmod did not, is that you're trying from SU vs regular user. On my install logging in as root did not grant me the permissions necessary to execute chmod correctly, but did after doing a sudo su. Go figure...
Forgive me for my simple question but how do you make it writable?
I read it it needs to be change to for example: for timthumbs or http://shiftingpixel.com/2008/03/03/smart-image-resizer/
"Make your imagecache directory is writable by the web server (usually chmod 775)"
So I just call the function or what?
Usually, it's a bad idea to chmod 755 directories without some serious forethought. On your webserver, there will be a user that the web server software runs as, usually something like www-data or apache. You can chown -R apache /path/to/your/cache/dir and that way PHP can write to that directory.
EDIT: To clarify, these are commands you would run from a shell on your webserver, such as via SSH. They are not PHP functions. Your web host should have more information about how you can get shell access.
chmod is a command line unix/linux command. You'd access it via an SSH console or you should be able to modify with whatever mechanism you're using to upload the files with (SSH, SFTP, FTP, etc)
Use the chmod command to change folder permissions
chmod 775 foldername
or if you are using FTP, you can use filezilla (right click on folder, and type 775 in the permissions)
I just setup a LAMP development server and am still trouble-shooting some things. The server is installed on one computer and I use a Windows laptop to write my code and test the site via the web browser.
My file uploading script works in that JPEG image files are successfully uploaded to the server, but when I try to view the images in the web browser, permission is denied.
I check the permissions on the file via the server and they are 600. I can fix the issue by chmod 777 theimage.jpg, but this doesn't seem like a good solution at all.
Does the solution have something to do with Apache configuration? Or is there something else I should be doing.
Thank-you,
Mike
Update
To clarify, I am able to upload a JPEG file to /var/www/test/images, but am unable to view the image in the web browser after it has been uploaded. My script works on the production server (I am using Dreamhost). This leads me to believe that the issue is with the development server that I have just setup. Any feedback is greatly appreciated, even if it is just resources that I should read for better understanding the server setup.
You need to change the permissions on the folder containing the file, not just the file itself. Use sudo chmod and sudo chown on the directory that contains the file you want to access, then check to make sure the permissions where changed with the ls -rl command. The permissions used with chmod should be r and w and the directory should read -rw-r--r-- when the ls -rl command is used if the permissions have been changed correctly. Also, if you are still unclear about the specifics of how chmod and chown work check out this link and this link.
EDIT:
Type this:
sudo chmod -R 666 /var/www/test/images
Or this:
sudo chmod a=rw /var/www/test/images
... to do what you want to do. For more explanation see my latest comment entry below.
I'd say you probably are running PHP under a different uid than Apache.
You can:
Configure apache/PHP so that they run under the same uid
Upon file upload, use PHP tochange the permissions with the chmod function or change the umask associated with the PHP process so that the file gets the correct permissions in the first place
Access the images through PHP (readfile) -- not recommended for performance issues
How should I handle image uploading using PHP?
How should I handle the chmod settings?
Example;
I have a dir called /image/ where i want to upload all my images.
Should I set this dir to chmod 777 and leave it like that? Or should i change chmod on that folder via PHP each time I need to upload a image. Is this correct, or should I be doing something else?
As thephpdeveloper mentioned, setting chmod once is enough. All subsequent writes into that directory will not change the directory permissions unless you explicitly chmod it to another permissions somewhere else.
The recommended permissions for directories on a *nix server is 755.
Setting permissions to 777 is not recommended. As mentioned by wic, it gives full permissions to everyone that have access to your server. Which makes it vulnerable if you are on shared hosting or sharing the server with other users.
Also to note is how PHP is run on your server. In fact, if you are running PHP as cgi, example suphp, permissions of 777 for directories are not allowed. Having 777 permissions on the directories your scripts reside in will not run and will instead cause a "500 internal server error" when attempting to execute them.
I recomend chmoding to 755
Only the user running the web server dameon needs permissions to the directory for writing. And you certainly don't want execute permissions on a directory users are uploading to.
Usually, folder settings are set once and that's it. It's rather pointless to keep setting the folder permissions to 777 via PHP, when you have already set it to 777.
No, you dont have to change the permissions on the directory each time. Once set, they are set so to speak.
Using 777 is overkill since it gives full permissions to everyone. Remove the 'x' bit and let apache (or whoever) own the directory. This makes it impossible to list files.