I have a been using a library called Unoconv. (Please note that in my local ubuntu [virtualbox-homestead], it's working as expected, but not in AWS.)
$unoconv = Unoconv::create([
'unoconv.binaries' => '/usr/bin/unoconv',
]);
This is what I call in php. And I can confirm that /usr/bin/unoconv exists.
The initial error was:
exception: "Unoconv\Exception\RuntimeException"
file : "/usr/bin/unoconv"
First, I though it was permission issue. So I adapted accordingly:
My Homestead permissions: -rwxr-xr-x 1 root root 63243 Aug 18 2015 unoconv
My AWS permissions: -rwxr-xr-x 1 root root 63243 Aug 18 2015 unoconv
Then I changed my AWS group to:
-rwxr-xr-x 1 www-data www-data 63243 Aug 18 2015 /usr/bin/unoconv
Then I tried editing /etc/nginx/fastcgi_params and added this line:
// This existed, so I didn't touch it
fastcgi_param REDIRECT_STATUS 200;
// I added this line
fastcgi_param PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node/bin
And my nginx looks like this:
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
The error has now changed to:
exception: "Unoconv\Exception\RuntimeException"
file: "/var/www/my_proj/vendor/php-unoconv/php-unoconv/src/Unoconv/Unoconv.php"
line: 68
message:"Unoconv failed to transcode file"
The file path is changed.
Finally, I tried removing fastcgi_param REDIRECT_STATUS 200;, but nginx doesn't compile/throws a syntax error.
I am stuck on how to overcome the issue.
Update:
In /etc/init.d/php7.0-fpm, I can see PATH=/sbin:/usr/sbin:/bin:/usr/bin, but I am not sure how to fix this issue. Should I use /bin instead of /usr/bin? If I do, I get an error "Executable not found, proposed : /bin/unoconv"
Or is it permission issue?
try making the binary executable by using
sudo chmod +x /path/to/unoconv
also , 'which unoconv' command will help you to find out the exact path of unoconv bin library.
also here is the link reference for your similar issue post:
https://github.com/alchemy-fr/PHP-Unoconv/issues/5
Related
I am trying to test-run a django project on my VPS for the first time. I followed a step-by-step tutorial on a blog (thanks to a nice guy on #django channel at liberachat). The setup involves uWSGI and nginx. The django project files are at /srv/www/site/*. uwsgi configuration is at /etc/uwsgi.d/mysite.com.ini, and nginx configuration is at /etc/nginx/conf.d/mysite.com.conf.
Here is what happens when I start uwsgi (systemctl start uwsgi):
Jul 29 14:35:09 mysite.com uwsgi[6998]: [uWSGI] getting INI configuration from mysite.com.ini
Jul 29 14:35:09 mysite.com uwsgi[6318]: Fri Jul 29 14:35:09 2022 - [emperor] curse the uwsgi instance mysite.com.ini (pid: 6998)
Jul 29 14:35:09 mysite.com uwsgi[6318]: Fri Jul 29 14:35:09 2022 - [emperor] removed uwsgi instance mysite.com.ini
How do I interpret and fix that?
contents of /etc/uwsgi.d/mysite.com.ini:
procname-master = demosite
# Now paths can be specified relative to here.
chdir = /srv/www/
# allow nginx
uid = 981
gid = 981
chmod-socket = 644
socket = server.sock
# Task management
; Max 4 processes
processes = 2
; Each running 4 threads
threads = 2
; Reduce to 1 process when quiet
cheaper = 1
; Save some memory per thread
thread-stack-size = 512
# Logging
plugin = logfile
; Log request details here
req-logger = file:logs/request.log
; Log other details here
logger = file:logs/error.log
log-x-forwarded-for = true
# Python app
plugin = python3
; Activate this virtualenv
virtualenv = venv/
; Add this dir to PYTHONPATH so Python can find our code
pythonpath = site/
; The WSGI module to load
module = mysite.wsgi
# Don't load the app in the Master - saves memory in quiet times
lazy-apps = true
contents of /etc/nginx/conf.d/mysite.conf:
# Allow gzip compression
gzip_types text/css application/json application/x-javascript;
gzip_comp_level 6;
gzip_proxied any;
# Look for files with .gz to serve pre-compressed data
gzip_static on;
server {
listen 80;
# The hostname(s) of my site
server_name mysite.com;
# Where to look for content (static and media)
root /srv/www/html/;
# Defines the connection for talking to our Django app service
location #proxy {
# Pass other requests to uWSGI
uwsgi_pass unix://srv/www/server.sock;
include uwsgi_params;
}
# nginx docs recommend try_files over "if"
location / {
# Try to serve existing files first
#try_files $uri #proxy =404;
root /srv/www/html/;
}
}
What did I miss?
Any incoming request of the form:
http://localhost:19090/wms?map=world&layer=world&mode=map&FORMAT=image/jpg
needs to be rewritten to:
http://localhost:19090/wms?map=/home/balajeerc/Projects/mapserver/data/wms/world_map/world.map&layer=world&mode=map&FORMAT=image/jpg
i.e. the ?map=<mapname> needs to be transformed into ?map=<full path to mapname.map file>
Here is the nginx configuration that I have tried so far:
location /wms {
rewrite (^.*map=)([^\&]*)(\&.*) $1/home/balajeerc/Projects/mapserver/data/wms/world_map/$2.map$3 break;
fastcgi_pass 127.0.0.1:19097;
fastcgi_index mapserve*;
fastcgi_param SCRIPT_FILENAME /home/balajeerc/Projects/mapserver/bin/mapserve;
fastcgi_buffers 16 256k;
fastcgi_buffer_size 256k;
rewrite_log on;
include fastcgi_params;
}
I get the error:
msLoadMap(): Regular expression error. MS_DEFAULT_MAPFILE_PATTERN validation failed. when I try this.
What could I be doing wrong?
EDIT:
I did some more investigation and I found that the query string is not getting re-written at all. The way I established this was by running the echo-cpp fastcgi application. The query string as seen by the final fcgi application is the unmodified original that was sent to nginx.
I suppose that means that this is not a mapserver issue but an nginx issue. It appears that rewrite is doing nothing at all.
Managed to solve this after clues from a lot of other nginx related posts. Posting here for posterity.
Apparently, the regex in the 'rewrite' section operates only on paths. That means that everything after the '?' is NOT included in the regex.
What I was trying to do was not just a URL rewrite but modifying one of the request parameters itself. So the way I solved it was as follows:
location /wms {
if ($args ~* (.*map=)([^\&]*)(\&.*)){
set $args $1/home/balajeerc/Projects/mapserver/data/wms/world_map/$2.map$3;
}
fastcgi_pass 127.0.0.1:19097;
fastcgi_index mapserve*;
fastcgi_param SCRIPT_FILENAME /home/balajeerc/Projects/mapserver/bin/mapserve;
fastcgi_buffers 16 256k;
fastcgi_buffer_size 256k;
rewrite_log on;
include fastcgi_params;
}
fastcgi_param world /home/balajeerc/Projects/mapserver/data/wms/world_map/world.map,
should result in:
http://localhost:19090/wms?map=world
I cant run uwsgi in emperror mode with my ini file. I have installed uwsgi with sudo pip install uwsgi.
When I try to start uwsgi, I get error:
sudo /etc/init.d/uwsgi start
/etc/init.d/uwsgi: line 72: /usr/share/uwsgi/init/snippets: No such file or directory
/etc/init.d/uwsgi: line 73: /usr/share/uwsgi/init/do_command: No such file or directory
[....] Starting app server(s): uwsgi/etc/init.d/uwsgi: line 80: do_command: command not found
failed!
I'm using Debian. Firstly I tried to follow django and nginx docs, but when it did not work I googled a lot.
This is my ebook_uwsgi.ini file:
# ebook_uwsgi.ini file
[uwsgi]
emperor = /etc/uwsgi/vassals
#plugins = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module = controller.wsgi:application
# the virtualenv (full path)
home = /var/www/django/ebook
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
no-site = True
wsgi-file = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
env = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable
And here is my ebook_nginx.conf:
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///var/uwsgi/ebook.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8001;
# the domain name it will serve for
server_name IP #.bookdownloading.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/django/ebook/ebook/data; # your Django project's media files - amend as required
}
location /static {
alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
include /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
}
}
Where IP stands for servers real IP.
When I start uwgi with my ini file I get Permission denied:
uwsgi --ini ebook_uwsgi.ini
[uWSGI] getting INI configuration from ebook_uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Tue Apr 14 17:11:32 2015] ***
compiled with version: 4.7.2 on 14 April 2015 16:47:40
os: Linux-2.6.32-042stab104.1 #1 SMP Thu Jan 29 12:58:41 MSK 2015
nodename: zoltan
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 8
current working directory: /var/www/django/ebook/ebook
detected binary path: /usr/local/bin/uwsgi
chdir() to /var/www/django/ebook/ebook/wsgi/ebook/
your processes number limit is 2062113
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
*** starting uWSGI Emperor ***
bind(): Permission denied [core/socket.c line 230]
I am using socked in /var/uwsgi/ebook.sock where I have set www-data as owner of uwsgi directory:
ls -la /var
total 128
drwxr-xr-x 13 root root 15 apr 14 16:29 .
drwxr-xr-x 23 root root 23 apr 12 19:46 ..
drwxr-xr-x 2 root root 19 apr 13 06:25 backups
...
drwxr-xr-x 2 www-data www-data 2 apr 14 16:36 uwsgi
Why do I get Permission denied?
//EDIT:
I was missing some config settings. So here is my new ini file:
# ebook_uwsgi.ini file
[uwsgi]
#emperor = /etc/uwsgi/vassals
#plugins = python #if uwsgi installed with pip, dont have to use this line
# Django-related settings
# the base directory (full path)
chdir = /var/www/django/ebook/ebook/wsgi/ebook/
# Django's wsgi file
module = controller.wsgi:application
# the virtualenv (full path)
home = /var/www/django/ebook
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 1
# the socket (use the full path to be safe
socket = /var/uwsgi/ebook.sock
# ... with appropriate permissions - may be needed
chmod-socket = 664
uid = www-data
gid = www-data
# clear environment on exit
vacuum = true
no-site = True
wsgi-file = /var/www/django/ebook/ebook/wsgi/ebook/controller/wsgi.py
#env = DJANGO_SETTINGS_MODULE=controller.settings # set an environment variable
and nginx settings:
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream ebook {
server unix:///var/uwsgi/ebook.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 8001 default_server;
# the domain name it will serve for
server_name IP; #.bookdownloading.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /var/www/django/ebook/ebook/data; # your Django project's media files - amend as required
}
location /static {
alias /var/www/django/ebook/ebook/wsgi/static/; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass ebook;
include /var/www/django/ebook/ebook/uwsgi_params; # the uwsgi_params file you installed
}
}
No matter if I run uwsgi or not, I get 502 Bad Gateway. Error nginx log:
2015/05/12 16:22:08 [crit] 3002#0: *1 connect() to unix:///var/uwsgi/ebook.sock failed (13: Permission denied) while connecting to upstream, client: 78.45.37.119, server: IP, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///var/uwsgi/ebook.sock:", host: "IP:8001"
Hm, even though I have set owner of stocket file to www-data, it was created as my user and nginx could not read it.
I've read your post and you're getting the permission issue because maybe www-data don't have write permissions on the folder uwsgi, you have two ways of testing it:
Log in with the www-data user and try to create a file inside /var/uwsgi/
To log in with www-data user su - www-data
Change the folder permissions to 775 (chmod 775 /var/uwsgi/)
Another option could be try to change the path of the sockets to the tmp folder. I tried your configuration in a VM using tmp folder and it works perfectly
ebook_uwsgi.ini:
socket = /tmp/ebook.sock
ebook_nginx.conf:
upstream django {
server unix:///tmp/ebook.sock;
}
I too faced the same.
/usr/share/uwsgi/init/snippets and /usr/share/uwsgi/init/do_commands
Above two files are missing with pip install uwsgi
But apt-get install uwsgi adds above two files and resolves issue
Somehow, when I run uwsgi from my linux user, uwsgi ignored my ini file and created ebook.sock with owner and group of my user, not specified www-data. When I changed owner and group manually to www-data, web loaded.
Problem was with permissions for file uwsgi_params. After using nginx file it worked all right.
I'm teaching myself how to setup an Ubuntu Server to run my Django application. I want to use Nginx + uwsgi. I know that this question can be very easy for experts but I've spent 6 days looking for it over the internet without getting it (in any case, forgive me if there is any link with the answer). I've followed a lot of tutorials and posts but I didn't found a solution.
I describe my file structure below:
My django project is located in /usr/local/projects/myproject
My virtualenv is in /root/.virtualenvs/myproject
My uwsgi config file myproject.ini is in /etc/uwsgi/apps-available/ and correctly symbolic linked in /etc/uwsgi/apps-enabled/
[uwsgi]
plugins = python
socket = /tmp/myproject.sock
chmod-socket = 644
uid = www-data
gid = www-data
master = true
enable-threads = true
processes = 2
no-site=true
virtualenv = /root/.virtualenvs/myproject
chdir = /usr/local/projects/myproject
module = myproject.wsgi:application
pidfile = /usr/local/projects/myproject/myproject.pid
logto = /var/log/uwsgi/myproject_uwsgi.log
vacuum = true
My nginx config file myproject.conf is in /etc/nginx/sites-available/ and correctly symbolic linked in /etc/nginx/sites-enabled/
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/myproject.sock; # for a file socket
}
server {
listen 80;
server_name dev.myproject.com www.dev.myproject.com;
access_log /var/log/nginx/myproject_access.log;
error_log /var/log/nginx/myproject_error.log;
location / {
uwsgi_pass unix:///tmp/myproject.sock;
include /etc/nginx/uwsgi_params;
uwsgi_param UWSGI_SCRIPT myproject.wsgi;
}
location /media/ {
alias /usr/local/projects/myproject/media/;
}
location /static/ {
alias /usr/local/projects/myproject/static/;
}
}
When I try to access to dev.myproject.com I get an Internal Server Error. Then I take a look to my uwsgi log:
Traceback (most recent call last):
File "./myproject/wsgi.py", line 9, in <module>
import os
ImportError: No module named os
Sat Jul 26 17:39:16 2014 - unable to load app 0 (mountpoint='') (callable not found or import error)
Sat Jul 26 17:39:16 2014 - --- no python application found, check your startup logs for errors ---
[pid: 8559|app: -1|req: -1/8] 79.148.138.10 () {40 vars in 685 bytes} [Sat Jul 26 17:39:16 2014] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 0)
I need your help because I'm not able to find a solution despite the posibility of being very simple.
If you need to know something else let me know and I will update my question as soon as possible.
I finally found a solution.
I followed kchan's suggestion about not putting any of the contents in the /root/ directory. Basically, I did some small changes in my myproject.conf file and my myproject.ini file. I created a user and structured everything like below:
uwsgi config file myproject.ini in /etc/uwsgi/apps-available/ and correctly symbolic linked in /etc/uwsgi/apps-enabled/
[uwsgi]
plugins = python
socket = /tmp/myproject.sock
chmod-socket = 644
uid = www-data
gid = www-data
master = true
enable-threads = true
processes = 2
virtualenv = /home/user/.virtualenvs/myproject
chdir = /home/user/projects/myproject
module = myproject.wsgi:application
pidfile = /home/user/projects/myproject/myproject.pid
daemonize = /var/log/uwsgi/myproject_uwsgi.log
vacuum = true
nginx config file myproject.conf in /etc/nginx/sites-available/ and correctly symbolic linked in /etc/nginx/sites-enabled/
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/myproject.sock; # for a file socket
}
server {
listen 80;
server_name dev.myproject.com www.dev.myproject.com;
access_log /var/log/nginx/myproject_access.log;
error_log /var/log/nginx/myproject_error.log;
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
location /media/ {
alias /home/user/projects/myproject/media/;
}
location /static/ {
alias /home/user/projects/myproject/static/;
}
}
I must say that I think the real problem was to try to setup my DB configuration in the postactivate file of my virtualenv. Hope to help someone else.
I have a Nginx vhost than is configured as such:
...
location /one {
include uwsgi_params;
uwsgi_pass unix:///.../one.sock;
}
location /two {
include uwsgi_params;
uwsgi_pass unix:///.../two.sock
}
...
This is a simplified configuration of course
When I request /one/something I would like my Python script to receive /something as request_uri.
I'm using BottlePy but would like this to be handled by Nginx and not in my Python code.
Can I do something like uwsgi_param REQUEST_URI replace($request_uri, '^/one', '')?
Edit
Here is the request from my Python code:
[pid: 30052|app: 0|req: 1/1] () {42 vars in 844 bytes} [Tue Aug 21 14:22:07 2012] GET /one/something => generated 0 bytes in 4 msecs (HTTP/1.1 200) 2 headers in 85 bytes (0 switches on core 0)
So Python is OK but uWSGI is not.
How to fix that?
location /one {
rewrite /one/(.+) /$1 break;
include uwsgi_params;
uwsgi_pass unix:///.../one.sock;
}
I know this thread is old, but there is another way to solve this if you are using uWSGI to run your python app.
[uwsgi]
route-uri = ^/one/(.*) rewrite:/$1
I just met the same problem, and here is a solution
location /one {
include uwsgi_params;
uwsgi_pass unix:///.../one.sock;
uwsgi_param SCRIPT_NAME /one;
uwsgi_modifier1 30;
}
You can found more about uwsgi_modifier1 here:
http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html#hosting-multiple-apps-in-the-same-process-aka-managing-script-name-and-path-info
I've solved that in another way:
[uwsgi]
module = wsgi:application
master = true
processes = 10
socket = 127.0.0.1:9090
mount = /one=customscript.py
manage-script-name = true
nginx
location /one {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9090;
}