Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to give program permission to write files??

  1. #1
    Join Date
    Oct 2006
    Location
    Maine
    Beans
    15
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    How to give program permission to write files??

    I've installed Apache2, PHP, MySQL and PHPMyAdmin to get a webserver up and running.

    I've installed imagemagick and magickwand (allows me to edit images with PHP code).. The problem is when I go to save the edited image, I get an error:

    Fatal error: magickwriteimage(): C API cannot write the image at MagickWand index 0 to filename "logo.jpg" (reason: unable to open image `/var/www/logo.jpg': Permission denied @ blob.c/OpenBlob/2480) [on C source line 374] in /var/www/testrotate.php on line 11

    Basically if I set the security permissions on the www folder to allow anyone to make changes / read & write the program works fine... If I set security to normal I get the error above. Do I need to create a new user for the imagemagick program? How do I give it access to save images to the folder without letting "everyone" do it.

  2. #2
    Join Date
    Nov 2006
    Location
    Montreal, Canada
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to give program permission to write files??

    You can either alter the permissions on /var/www or create virtual hosts in Apache with a DocumentRoot inside your home directory.

  3. #3
    Join Date
    Jan 2008
    Beans
    4,757

    Re: How to give program permission to write files??

    I think what needs to be done is to create a directory inside /var/www with the user "www-data" as the owner or group with write access.
    Then save the file in there, rather than directly in the root of /var/www.

    ie:
    Code:
    sudo mkdir /var/www/data
    sudo chgrp www-data /var/www/data
    sudo chmod 2775 /var/www/data
    Then update your code accordingly to save in that directory.


    But as said above, virtual hosts may be the better way to go from a security view.

    Regards
    Iain

  4. #4
    Join Date
    Oct 2006
    Location
    Maine
    Beans
    15
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to give program permission to write files??

    Quote Originally Posted by tinivole View Post
    I think what needs to be done is to create a directory inside /var/www with the user "www-data" as the owner or group with write access.

    But as said above, virtual hosts may be the better way to go from a security view.

    Regards
    Iain
    Thanks Iain, I'm a little bit of a newb when it comes to setting up a webserver in ubuntu, I havnt used virtual hosts before, but i've done some reading to understand them better.

    Updating the security for www-data wasnt effective, nor when I created a folder inside of the www directory to assign permissions to, but still if permissions are set so Everyone has read / write capability, it works. Thus I dont think www-data is the correct user for the job?

    Could you also go into further detail on how I would use virtual hosts to accomplish this task?
    Last edited by boon4376; July 12th, 2009 at 03:09 PM.

  5. #5
    Join Date
    Dec 2007
    Location
    Chandigarh-India
    Beans
    82
    Distro
    Ubuntu 19.10 Eoan Ermine

    Re: How to give program permission to write files??

    run the app as root "sudo" or open the saving directory as root and provide the permissions
    After Endless Roots and Hackintosh, I have stopped flaunting my Medals. That doesn't mean I don't like the fight; but I do for the Kick of it.

  6. #6
    Join Date
    Nov 2006
    Location
    Montreal, Canada
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to give program permission to write files??

    Quote Originally Posted by boon4376 View Post
    Could you also go into further detail on how I would use virtual hosts to accomplish this task?
    Make a copy of /etc/apache2/sites-available/default, let's call it 'mysite'

    Code:
    sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
    Now you'll nee to edit the new file to point to your home directory. I've included a sample.

    Code:
    <VirtualHost *:80>
    	ServerAdmin webmaster@localhost
           ServerName mysite.example.com
    
    	DocumentRoot /home/username/mysite
    	<Directory /home/username/mysite/>
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride All
    		Order allow,deny
    		allow from all
    	</Directory>
    
    	ErrorLog /var/log/apache2/mysite/error.log
    
    	# Possible values include: debug, info, notice, warn, error, crit,
    	# alert, emerg.
    	LogLevel warn
    
    	CustomLog /var/log/apache2/mysite/access.log combined
    
    </VirtualHost>
    Once you've saved these changes, you'll need to enable the site.

    Code:
    sudo a2ensite /etc/apache2/sites-available/mysite
    Almost there. We've specified a separate directory for storing log files, so we'll need to create that.

    Code:
    sudo mkdir /var/log/apache2/mysite
    Finally, we need to add the site to your hosts file. Edit /etc/hosts and add the following:

    Code:
    127.0.0.1    mysite.example.com
    Now we restart Apache

    Code:
    sudo /etc/init.d/apache2 restart
    You can now store all your work in /home/username/mysite and navigate to it by pointing your browser to http://mysite.example.com

  7. #7
    Join Date
    Oct 2006
    Location
    Maine
    Beans
    15
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to give program permission to write files??

    Quote Originally Posted by jskandhari View Post
    run the app as root "sudo" or open the saving directory as root and provide the permissions
    Well its not really an app, its a PHP library for image processing, and I start nautilus with "sudo" before going in to apple permissions.

    Thanks celaruan, I'll start working on that and see how it goes

  8. #8
    Join Date
    Oct 2006
    Location
    Maine
    Beans
    15
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to give program permission to write files??

    Quote Originally Posted by Celauran View Post
    Once you've saved these changes, you'll need to enable the site.

    Code:
    sudo a2ensite /etc/apache2/sites-available/mysite
    Im getting an error when I try to do this
    Code:
    Error: No site found matching /etc/apache2/sites-available/records!
    I've tried creating the "records" file a few times from copying the default one... Is there an extension I'm supposed to be using? When I navigate to the folder I can see that the file exists.

  9. #9
    Join Date
    Nov 2006
    Location
    Montreal, Canada
    Beans
    485
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: How to give program permission to write files??

    Navigate to /etc/apache2/sites-available and execute it there.

    Code:
    cd /etc/apache2/sites-available
    sudo a2ensite records
    Not sure why you can't call it with a path, but apparently you can't. Sorry.

  10. #10
    Join Date
    Oct 2006
    Location
    Maine
    Beans
    15
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to give program permission to write files??

    Quote Originally Posted by Celauran View Post
    Navigate to /etc/apache2/sites-available and execute it there.

    Code:
    cd /etc/apache2/sites-available
    sudo a2ensite records
    Not sure why you can't call it with a path, but apparently you can't. Sorry.
    ok that fixed that problem... I now have the virtual host working and can get to the images / files through the web browser, however I still cannot use imagemagick to write images to that directory and still get the error. (thanks for teaching me how to setup virtual hosts

    [code]Fatal error: magickwriteimage(): C API cannot write the image at MagickWand index 0 to filename "logo.jpg" (reason: unable to open image `/var/records/logo.jpg': Permission denied @ blob.c/OpenBlob/2480) [on C source line 374] in /var/records/testrotate.php on line 11[code]



    UPDATE: ok so changing the permissions on the folder is not working, If I make the owner of "records" www-data and hit "apply permissions to enclosed files" It doesnt actually apply the permissions to the images in there. For example, after hitting to apply to enclosed files, I opened an image inside the folder, and the image's owner has not changed.... If I manually changed that image's owner to www-data, the code executed flawlessly and the image was altered and saved over itself like its supposed to do....

    So I have 80,000 images (These are archived records in the format of tiff images being stored on a local intranet server), I cant very well go through and apply permissions separately to each one for www-data, So how do I apply permissions to all of them at the same time?

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •