Issues seting up production from development - site_config.json does not exist

Hi, I’m having issues getting the production environment working after running through the frappe framework development tutorial. When I finished working on the tutorial I used the command bench use site1.local to change to the default erpnext site that was installed as default, from the tutorial site “library”

I then followed the “Easy Production Setup” instructions on this page:
https://frappe.github.io/frappe/user/en/bench/guides/setup-production.html with a minor change as follows(maybe/maybe-not someone needs to update that page?):

Instead of (as per the link) sudo bench setup production which produces the following error on my machine

Usage: bench setup production [OPTIONS] USER
Error: Missing argument "user".

I included my username as sudo bench setup production chris which did not return any errors and when prompted I answered yes to replace the supervisor.conf and nginx.conf files.

I then tried to access the site in my browser at http://localhost and got this error

Not Found`

./localhost/site_config.json does not exist

I have check that this file is inside the ~/frappe-bench/sites/site1.local folder and contains the following code:

{
 "db_name": "1bd3e0294d", 
 "db_password": "something",
 "developer": 1
}

The nginx.conf and supervisor.conf files are in the the ~/frappe-bench/config directory and populated. The links are at /etc/nginx/conf.d/frappe-bench.conf and /etc/supervisor/conf.d/frappe-bench.conf and “nginx” and “supervisord” are running. The ~/frappe-bench/sites/currentsite.txt file contains “site1.local” (without the quotes).

I’ve tried restarting the nginx and supervisor servers, got rid of the "developer": 1 in the site_config.json file, tried all the ideas that I have found in this forum but still nothing. I can change back to “developer mode” and run the commands at https://github.com/frappe/bench/wiki/Stopping-Production-and-starting-Development and then go to http://localhost:8000 and access my erpnext site, but not in production mode.

Any ideas?

Just guessing here as haven’t used that install method but have you tried pointing your browser to
localhost:8080
failing this how about
sudo bench setup production frappe
Pass: ??? - maybe frappe ???
then
sudo service nginx reload
sudo supervisorctl reload

Just clutching at straws sorry…
Good Luck

1 Like

Thanks System19 but I have tried localhost:8080 and with the user “frappe” as sudo bench setup production frappe but both produce errors. There is no web site served on port 8080 and there is no user on my system called frappe.

I installed erpnext via the easy method install script copied and pasted from the main erpnext git hub site. I then worked with erpnext in production mode for a while and since discovering that there was no feature to have “weekly” recurring sales orders I thought I would have a look at hacking that feature in, as it is the “make or break” feature for our decision to use erpnext or something else. I then enabled developer mode and started working on the tutorials for frappe.

We are a agricultural/horticultural business that sells microgreens and mushroom direct to restaurants on weekly standing orders. I don’t have time to sit at the computer to make the regular sales orders manually every week! Sorry, that’s another issue I, no doubt, will be asking for help on in the near future. : )

Switching to/from production/developer mode shouldn’t cause any issues.
Upon re-reading your original post it sounds like you are running a local test setup. Why bother switching to Production?
Just run in Dev mode with “developer”: 1 in siteconfig.json enabled?
The only difference is that you have to run bench start.
Also depending on the amount of work done. Maybe it would be best to export any custom Doc’s etc and any data from your doctypes via the Data Import Tool Doctype and do a fresh install? Sorry thats not an elegant solution but possibly the quickest depending on the amount of work done.
I find it easier to drop the DB and redo the easy install process without the --setup-production at the end.

I can only guess as there are currently large changes occuring under the hood (In particular moving from Bench V1 to V2) that something has gone screwy some where.

Adding “weekly” to reccuring sales orders and invoices would be a great feature. Good Luck.

Cheers System19 but no, I am running just the easy production setup script from the main github page, then enable dev mode from there, so it is a standard install. I am just continuing to work away although I am a little cautious about spending too much time on it because a simple thing like this has no answers and where you start talking about dropping databases and installing without the --setup-production parts etc… Where is the documentation for this?

I am actually finding this whole process to be quite bemusing mostly because, on one hand the erpnext crew have done such a good job of things including their tutorial docs etc, but then there are so many different ways of doing the same things and I am constantly finding things like what you just mentioned about running the easy install process without --setup-production. Where is the documentation about this? Why is it so hard to install a ‘production’ install on macosx (I was told to do a beta dev install)? etc? etc? I understand I am being hypocritical with these comments as I should have gathered all the disparate bits of code and things I have stumbled on in this forum to create a document about them and, here’s the big hypocrite moment, I have not put my hand up to help yet!

Back to my original topic (with humility) of any ideas about why I am getting this error when trying to switch from dev mode to production? Is it something to do with my nginx frappe-bench.conf file? Is it a permissions thing in the sense that there is no user on my system called ‘frappe’ (never created with easy setup script) and I have to run sudo bench setup production chris because I have to pass a user to that command and maybe it should be some system user for nginx to be able to access the relevant files it needs access to? eg a log file in /var/log?

Just looking at the frappe/bench installation instructions and noticed this in bold/italic:

Easy Setup

This is an opinionated setup with logging and SE Linux. So, it is best to setup on a blank server.
Supported for CentOS 6, CentOS 7, Debian 7 and Ubuntu 12.04 to 15.x
This script will install the pre-requisites, install bench and setup an ERPNext site
Passwords for Frappe, Frappe Administrator and MariaDB (root) will be generated
You can then login as Administrator with the Administrator password printed

I have the file that was created in the system user roots’ directory with the passwords etc. Does this mean that a user was suppose to be created on my debian OS called “Frappe” or “frappe”? If so, is this the user I am suppose to pass to the command assudo bench setup production frappe? If so again, why wasn’t the user “Frappe” or “frappe” created with the install script, given that it ran with no errors? Who is this user “frappe”, a system user? A mariadb database user? What permissions should that particular user have upon creation including directories etc etc? Now I am clutching at straws! : )

OK, so I have gotten a little bit further by digging in some logs. I looked at ~/frappe-bench/logs/web.access.log and this is what the error is logged as:

2016-07-13 07:18:36,636 Request Error 
 site: localhost
 form: None

Traceback (innermost last):
  File "/home/chris/frappe-bench/apps/frappe/frappe/app.py", line 54, in application
    init_request(request)
  File "/home/chris/frappe-bench/apps/frappe/frappe/app.py", line 104, in init_request
    frappe.init(site=site, sites_path=_sites_path)
  File "/home/chris/frappe-bench/apps/frappe/frappe/__init__.py", line 121, in init
    local.conf = _dict(get_site_config())
  File "/home/chris/frappe-bench/apps/frappe/frappe/__init__.py", line 175, in get_site_config
    raise IncorrectSitePath, "{0} does not exist".format(site_config)
 IncorrectSitePath: 404: Not Found

--------------

I noticed the second line site: localhost and wondered why the command bench use site1.local was not changing something somewhere properly. I had run the command bench use site1.local many times in my frustration before but I ran it again for good measure. No change, still the 404 error.

Then I looked at the error from nginx/web browser again:

Not Found`

./localhost/site_config.json does not exist

I wondered if nginx couldn’t find the site_config.json file because it was looking for a directory called localhost instead of site1.local? So I created a symlink in the ~/frappe-bench/sites/ folder called localhost and linked it to the folder ~/frappe-bench/sites/site1.local. Tried http://localhost in my browser and voila! My production site there ready to go.

So, the next question: Why is the command bench use site1.local not creating the necessary configuration somewhere in the python goodness of frappe/bench after changing from production to development to production again?

Just for good measure, here is my nginx.conf file as created automatically when running sudo bench setup production chris:

upstream frappe-bench-frappe {
    server 127.0.0.1:8000 fail_timeout=0;
}

upstream frappe-bench-socketio-server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80;
    server_name
        site1.local
        library
        ;

    root /home/chris/frappe-bench/sites;

    
    location /assets {
        try_files $uri =404;
    }

    location ~ ^/protected/(.*) {
        internal;
        try_files /$host/$1 =404;
    }

    location /socket.io {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Frappe-Site-Name $host;
        proxy_set_header Origin $scheme://$http_host;
        proxy_set_header Host $host;

        proxy_pass http://frappe-bench-socketio-server;
    }

    location / {
        try_files /$host/public/$uri @webserver;
    }

    location @webserver {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Frappe-Site-Name $host;
        proxy_set_header Host $host;
        proxy_set_header X-Use-X-Accel-Redirect True;
        proxy_read_timeout 120;
        proxy_redirect off;

        proxy_pass  http://frappe-bench-frappe;
    }

    # optimizations
    sendfile on;
    keepalive_timeout 15;
    client_max_body_size 50m;
    client_body_buffer_size 16K;
    client_header_buffer_size 1k;

    # enable gzip compresion
    # based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
    gzip on;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/rss+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/font-woff
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/plain
        text/x-component
        ;
        # text/html is always compressed by HttpGzipModule
}
1 Like

Well done on the symlink solution… I just had a look and yes at the moment there are about 6 different install procedures available. The last time I installed a production instance about a year ago there was only one option. You have picked a very transitional time in regards install methods. This is due to Bench V2 and V7 using RQ and depreciating Celery. I would if possible just run with the Dev scripts so when that code branch becomes the Master release branch your transition to and from Production and Development will be much easier.
By this time the only changes between the two will be that production auto starts ERPNext upon CentOS 7 boot and if/when Frappe crashes then Frappe auto restarts. This functionality does not help during development.

Change the 2 lines in nginx.conf to read:

proxy_set_header X-Frappe-Site-Name site1.local;

then:

$sudo bench setup reload-nginx

(now you can remove your symlink)

Hope it helps,

1 Like