Run inkscape in PHP

旧时模样 提交于 2019-12-22 04:54:24

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/3219507/run-inkscape-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!