Run inkscape in PHP
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 cl开发者_JS百科ose 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?
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
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.
精彩评论