How to make cache directory writable - php

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)

Related

Permission in linux using xampp and wordpress

I'm trying to move more and more to linux, and i have some problem with the developement of my website locally with wordpress.
Everything went fine with installing wordpress and xampp. But now, if i want to install new themes or upload picture to my website, not using nemo in sudo mode (i'm using linux mint) the website is not allowed to write anything (the website is in /opt/xampps (something like that) ). I know that it's linux permission restriction.
Is there a way to allow writting permanently in a folder or something like that in linux ?
Thank you in advance
Try this command on your terminal with root user,
chmod -R 0777 /opt/xampps/mydirectory
sudo chown -R daemon wordpress-folder
// or use htdocs folder
the xampp apache server uses a user named daemon to access the folders inside htdocs, this will fix all the permission problems.
/u/Prabu 's answer has the right idea, but there is no reason to use 0777. It opens your directory up to attacks unnecessarily. Use 0755 instead.
chmod -R 0755 [your xampp directory]
0777 gives read, write and execute access to the directory to everyone who can get to it.
0755 gives read, write and execute access to only the folder owner (you!) and read/execute access to whatever group owns and the rest of the world. The important point is that it denies the world at large the ability to save files into your directory.
Here's a good summary of file permssions. It isn't super complicated, so you may as well take a few minutes to familiarize yourself with it since you're a Linux user: http://www.csit.parkland.edu/~smauney/csc128/permissions_and_links.html

How do I change file/folder ownership on a remote server without access to the commandline?

I've only got access to the directadmin panel (and ftp access as well), and for my mediawiki install I need to change the ownership of a particular folder (so chown). More specifically, I need to do this:
sudo chown -R www-data:www-data images/
Is there a way to do this without the commandline? With directadmin or via ftp?
CHOWN doesn't work over FTP and SFTP, the FTP protocol doesn't support it. You'll either need direct access or
a full blown SSH2 remote shell.
In DirectAdmin you can only 'reset' ownership through "File Manager".
filezilla and other well known ftp client supports to change permission of file and folder on server. Also you can use umask for changing permissions using php. Then there is not any need for command line access.

PHP / Apache File Write Permissions without 777

I'm trying to avoid 777 permissions for a directory that handles file uploads on a Linux server. PHP/Apache must be able to write to this particular directory, but I don't want to make it world-writable.
What're the best-practices for this?
I am not too familiar with the CLI, so my attempts to solve this using chgrp and chown have not yielded any results.
Thanks!
ACLs if supported. You could do something as simple as setfacl -R -m u:www-data:rwx,d:u:www-data:rwx /path/to/directory to allow apache to write to that specific directory (and all later created directories as well)

symfony2 cache/log permission issues

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.

function.fopen: failed to open stream: Permission denied in PHP

I'm trying to create XML sitemaps for my website from my PHP application. The idea is to either create a new file or overwrite an existing file. When I call fopen, I get the following error:
[function.fopen]: failed to open stream: Permission denied
I'm trying to write to the webroot and its permissions are: 755. This means that the owner has write permission, right? What do I need to do to make my script be able to write to this folder? 777 would be a bad thing, right? Can I run my script as owner somehow?
Thanks.
Yep, as you've said, using 777 could be huge mistake. The webserver doesn't run with the same user as you use to create files and folders.
You have some options:
Run the sitemap creation as a cronjob, using an user with rights to write there, other than the apache user.
Put the sitemap in another directory, and the set up a 302 Redirect or a symlink. In this case, if you have a security issue that let's someone to write your sitemap.xml, at least they'll not be able to create another file with a more dangerous extensions (like PHP, which may result in a site intrusion).
Make a rewrite rule to redirect any hit to sitemap.xml, to a php script that outputs the appropriate XML.
Good luck!
I'm a beginner and I had this problem as well. I am using Ubuntu linux w/ php and apache
Write a php script w/ the following: <?php exec('whoami'); ?> and run it on your server. This tells you who the current user of the script is
SSH to your server.
Make a group that has read and write access to the files you need.
Make group have read, write, and execute on folders you need.
Make the current user you found in the first step, part of the group that has access to the files you need.
Restart Apache: sudo apachectl restart
main commands you need are:
groupadd: Create a new group
usermod: add your user to a new group
chgrp: changes files / folders to group you specify
chmod: changes permissions on the files / folders you specify.
All the commands you need are here: http://www.yolinux.com/TUTORIALS/LinuxTutorialManagingGroups.html
If you have ACL enabled on the webroot partition just grant the web server username full rights
setfacl -m u:apache:rwx /var/www/html
Replace apache with the web server username and /var/www/html with your webroot location.
had the same problem
Looks like apache is running as nobody in the nobody group
so if you do a
useradd -G nobody youruser
chown -R youruser:nobody .
Then change the permission to 0775
chmod -R 0775 .
or you may add nobody to your usergroup
useradd -G nobody yourgroup
this be a better solution
Does it work with group write enabled (i.e. 775)?
Check your group permissions for the directory the file is in. As long as your PHP user (usually www-data) is part of that group, and it's the only user, you should be fine with 775 (or even 774).
Like Pascal said!
just find your apache user
<?php exec'whoami'; ?>
and then
useradd -G username username2
chown -R username:username2 .
chmod -R 0775 .
And its done!
Thank you Pascal!
777 is pretty normal, because PHP does not run as you, it runs as a PHP user, Apache, etc. The fact is, your webhost should have a higher set of permissions that prevents other users from writing/deleting your files.

Categories