8

I need to run inkscape in PHP so I can convert an svg image to PDF. However every time I try:

//some PHP code system("inkscape -z --file=svg.svg --export-pdf=pdf.pdf"); //more code

I get no new file and I get this in the apache erro log.

(inkscape:28607): libgnomevfs-WARNING **: Unable to create ~/.gnome2 directory: Permission > denied

Emergency save activated! Emergency save completed. Inkscape will close now. If you can reproduce this crash, please file a bug at www.inkscape.org with a detailed description of the steps leading to the crash, so we can fix it. ** Message: Error: Inkscape encountered an internal error and will close now.

Segmentation fault

I am running on ubuntu with apache server. What can I do to correct this problem?

petermlm
  • 930
  • 4
  • 12
  • 27
  • 1
    If the Inkscape option proves to be too much trouble, you could try [TCPDF](http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf) as suggested in the answer to [SVG to PDF on a shared linux server](http://stackoverflow.com/questions/2143971/svg-to-pdf-on-a-shared-linux-server) here on SO. – Mike Jul 10 '10 at 17:51

2 Answers2

7

This is related to system permissions, the easier way to fix is create a .gnome2 folder at root home folder of the user who's running that code and give it permissions to write (666 should be fine).

Note that if you're doing this by FTP folders/files starting with . (hidden files on linux), might not show up on listings depending on your client's config.

For example:

mkdir -p /var/www/.gnome2 /var/www/.config /var/www/.config/inkscape
chmod 755 /var/www/.gnome2 /var/www/.config /var/www/.config/inkscape
chown -R www-data /var/www/.gnome2 /var/www/.config /var/www/.config/inkscape
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Rod
  • 2,046
  • 2
  • 20
  • 24
  • 1
    The user that tries to run inkscape is www-data, the user who runs apache, I think. Any way, I believe the problem is that this user doesn't have a home folder, in fact the only home folder in the PC where the problem is happening is my home folder. Is it possible to create a home folder for www-data? would this resolve the problem? If yes, how can i create that folder? – petermlm Jul 10 '10 at 14:38
  • 1
    Assuming you're running this on apache, find out under what user the httpd process is running at top, then create the .gnome2 folder under that user, that will probably fix the issue. Usually apache runs under apache user and apache group, you may need to create a /home/apache/.gnome2, sounds unusual, but might work. Don't forget to chown. – Rod Jul 10 '10 at 15:43
  • 1
    I can't get it to work. Isn't it possible to edit the sudoers file to get it to work. – petermlm Jul 11 '10 at 10:11
  • 3
    It worked! I created the directories: /var/www/.gnome2 /var/www/.config /var/www/.config/inkscape. And modified the owner of this directories with chown so that the owner would be www-data, the user that runs apache. Thank you very must! – petermlm Jul 11 '10 at 10:56
1

Inkscape is executed by the webserver-user normally www-data. The default setup that Ubuntu provides for www-data locates the home directory of www-data in /var/www.

Ther are two possibilities:

a) Changing the home directory of www-data to /home/www-data

b) Disable the VirtualHost in /var/www

In both cases you have to change the rights of ~www-data. First "chown" the directory to www-data:www-data and give them writing privileges.

Next time if you execute inkscape via PHP (as www-data user) the missing directories will be created.