Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.46k stars 2.79k forks source link

Install on Nginx 1.4.6 #6163

Closed kkoci closed 7 years ago

kkoci commented 7 years ago

Hi, I'm installing dolibarr on Nginx 1.4.6, into Linux Mint Rafaela (Ubuntu 14.04)

Following the install instructions, it says to unzip the folder, place it on the web server root, create the conf.php file, which I did.

Everything seems to be working fine,

BUT, on the second step ie: http://localhost/dolibarr/htdocs/install/step2.php it throws me a 404 error.

Has anybody encounter this before?

I can't keep going with the installation

samsooo commented 7 years ago

Can we have a look at your site configuration file : /etc/nginx/sites-enabled/...

kkoci commented 7 years ago

Hi!

Thanks for the answer

Well, because the installation instructions of Dolibarr, don't specify anything, I did not create any sites-available nor sites-enable for it, I know I should create one, but if I read I don't need it, I'll take it as it is.

I suppose there is need for one configuration file.

Could You give me an example of one suitable nginx config file to Dolibarr?

I couldn't find any, anywhere

I do have some sites-enabled conf files, but not specifically for dollibar, I guess that is the reason, but again, please, is there some example I shall follow for it?

Thank You

samsooo commented 7 years ago

Yes, that's because Dolibarr is not intended to work with nginx. But it works pretty well.

Here is a configuration file that works with Nginx + PHP-fpm. I suppose you have a unix socket pool configured to listen at /var/run/php5-fpm.sock (default configuration)

# Dolibarr server configuration
server {
        listen 80;
        listen [::]:80;

        root /path/to/your/htdocs;

        # Optionnal
        error_log /path/to/your/log/directory/nginx.error.log;
    access_log /path/to/your/log/directory/nginx.access.log;

        index index.php index.html index.htm;

        # Optionnal
        server_name your-fqdn.tld;

        location / {
                try_files $uri $uri/ /index.php;
        }

        location ~ [^/]\.php(/|$) {
                try_files $uri =404;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 600;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

}
gnovaro commented 7 years ago

This process take some seconds to execute check if you alrdeady have setted this in your config. fastcgi_read_timeout 600;

rdoursenaud commented 7 years ago

Yeah, the install instructions are mainly targeted at (legacy) Apache + mod_php users. Nginx setup is a bit more involved.

The usual nginx setup involves php-fpm as the fast CGI application server.

The sample configuration above looks good. I'd just add this section for the REST API:

[…]

    # REST API support
    location /public/api {
        if ( !-e $request_filename) {
            rewrite ^.* /public/api/index.php last;
        }
    }

[…location…]

And some fastcgi directives to include in your php location (600 seconds read timeout is overkill IMHO):

# Faster upload
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param  REQUEST_BODY_FILE $request_body_file;
client_body_temp_path /dev/shm/client_body_temp;

# Longer timeout
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

If you're developing, you might also want:

# Enable Dolibarr tuning informations
fastcgi_param DOL_TUNING true;
fastcgi_param MAIN_SHOW_TUNING_INFO true;

For HTTPS I use something like (You can remove the http2 directive if you want to stick to HTTP/1.1):

# Redirect HTTP to HTTPS
server {
  listen 80;
  listen [::]:80;
  server_name your.domain.tld;
  rewrite ^ https://$server_name$request_uri? permanent;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name your.domain.tld;
    ssl_certificate /path/to/your/bundle.crt;
    ssl_certificate_key /path/to/your/private.key;
    keepalive_timeout 70;

   # Optional HSTS support
   #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

   […config…]
}

There's also some optimizations you may want to consider:

# Cache static files
location ~ \.(js|css|png|jpg|jpeg|gif|ico)$ {
  expires max;
  log_not_found off;
}

# Dolibarr compression
# See: https://wiki.dolibarr.org/index.php/FAQ_Increase_Performance#Compression_of_resources_by_Dolibarr
# Prefer web server Gzip compression if possible (See below).
location ~ \.jgz$ {
  add_header Content-Encoding gzip;
  gzip off;
  types {
    text/javascript jgz;
  }
}
http {
    […]
    # Gzip compression (Beware of increased memory footprint and server load)
    # Equivalent to: https://wiki.dolibarr.org/index.php/FAQ_Increase_Performance#Enable_compression_of_resources_by_Apache
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    # Upload larger files
    client_max_body_size 4M;
    client_body_buffer_size 128k;
    […]
}

Finally, if you deploy using Git, it may be a good idea to hide dot files and directories:

# Prevent serving hidden files (ie, .gitignore)
location ~ /\. {
  access_log off;
  log_not_found off;
  deny all;
}
rdoursenaud commented 7 years ago

@kkoci Any news? Success, failure? I'd be willing to add nginx instructions if given feedback by the community ;) Not that my setup doesn't run perfectly since 4 or 5 years :p But I tend believe there's no one-size-fits-all when it comes to this. Sane defaults are sorely needed though.

kkoci commented 7 years ago

Hi @rdoursenaud sorry for the delay :)

Thank You very much to all of You

Well, it gives me an Error 404 on this step:

http://localhost/dolibarr/htdocs/install/step2.php

I'm using the first sites-available/sites-enabled example on this thread, the example given by @samsooo , maybe I should follow the edits proposed by You, going to try and write back :)

rdoursenaud commented 7 years ago

@kkoci Don't mind any delay. It's an asynchronous medium ;) Thanks for replying. Looking forward to receiving more feedback.

eonlab commented 7 years ago

Hi, sorry to re-open this issue but I'm having some problems with the rest api and nginx. Dolibarr is setup in a subfolder (/public/erp) and everything is working except the rest api. When I try to access: /erp/api/index.php/login?login=auserlogin&password=thepassword I always get:

404

Not Found

Routes.php:458 at route stage

So after a while I realised that nginx is not passing the right string to $_SERVER["PHP_SELF"], instead of passing: /erp/api/index.php/login is passing only: /erp/api/index.php

This is what I'm using on nginx config: location /erp/api { try_files $uri $uri/ /erp/api/index.php?$query_string; }

also tried this:

location ~ ^/erp/api/([^/]+)/ { try_files $uri $uri/ /erp/api/index.php/$1?$query_string; } but gives 500 Internal Server Error

How can I change it so it passes the complete string: /erp/api/index.php/login

Thank you.

rdoursenaud commented 6 years ago

@eonlab Here's an nginx location configuration that enables the REST API with the latest Dolibarr versions.

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }

    # Mitigate https://httpoxy.org/ vulnerabilities
    fastcgi_param HTTP_PROXY "";

    root           /[YOUR_INSTALL_PATH]/dolibarr/htdocs;
    fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    # Dolibarr Rest API path support
    fastcgi_param  PATH_INFO       $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_script_name;
}
rdoursenaud commented 6 years ago

Oh, and if you want pretty REST API URLs (without index.php) add this location before:

# Pretty REST API URL
location ~ ^/api/(?!(index\.php))(.*) {
    try_files $uri /api/index.php/$2?$query_string;
}
ghost commented 5 years ago

Hi @rdoursenaud

Thanks for sharing your nginx conf for Dolibarr >=v7 . Just one problem with it. When we access to the admin page of API Rest module, index.php is downloaded. He're my conf :

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/htdocs;

    index  index.php index.html index.htm;

    client_max_body_size 100M;

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        # Mitigate https://httpoxy.org/ vulnerabilities
        fastcgi_param HTTP_PROXY "";

        fastcgi_pass php:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # Dolibarr Rest API path support
        fastcgi_param  PATH_INFO       $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED $document_root$fastcgi_script_name;
    }

}

And the link of the downloaded index.php : http://local.dolibarr/api/admin/index.php

Any idea ? Thanks.

fappels commented 5 years ago

Can you try to add:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}
ghost commented 5 years ago

Can you try to add:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

Doesn't work either :(

rreevolution commented 4 years ago

@gaius57 Hi! I'm having the same problem, did you solved it?

jyhere commented 3 years ago

@gaius57 Hi! I'm having the same problem, did you solved it?

Have a look at the Dolibarr WIKI nginx configuration, it's working fine. https://wiki.dolibarr.org/index.php?title=Module_Web_Services_API_REST_(developer)

BorysVrublevskyi commented 3 years ago

Getting errors on API page (https://erp.mysite.loc/api/index.php/explorer/) with config from https://wiki.dolibarr.org/index.php?title=Module_Web_Services_API_REST_(developer)#Nginx_setup Files locate in htdocs/includes/restler/framework/Luracast/Restler/explorer

GET https://erp.mysite.loc/api/index.php/explorer/css/typography.css HTTP/2 404 Not Found 39ms]
GET https://erp.mysite.loc/api/index.php/explorer/css/reset.css HTTP/2 404 Not Found 38ms]
GET https://erp.mysite.loc/api/index.php/explorer/css/screen.css HTTP/2 404 Not Found 34ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/object-assign-pollyfill.js HTTP/2 404 Not Found 33ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/jquery-1.8.0.min.js HTTP/2 404 Not Found 42ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/jquery.slideto.min.js HTTP/2 404 Not Found 35ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/jquery.wiggle.min.js HTTP/2 404 Not Found 33ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/jquery.ba-bbq.min.js HTTP/2 404 Not Found 32ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/handlebars-4.0.5.js HTTP/2 404 Not Found 31ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/lodash.min.js HTTP/2 404 Not Found 31ms]
GET https://erp.mysite.loc/api/index.php/explorer/lib/backbone-min.js HTTP/2 404 Not Found 40ms]
GET https://erp.mysite.loc/api/index.php/explorer/swagger-ui.js HTTP/2 404 Not Found 33ms]