1

I am trying to run a Linux server configuration for a catalog project. I am using: Apache2, Flask, and SQLAlchemy and I had to install and configure PostgreSQL. The site I am trying to run is the Public IP Address: http://52.27.140.219/. I am happy to provide greater detail. I am new with Linux and many things discussed here, but I believe my work is strong, except for the end problem below.

Important steps in Terminal:

From: (venv)grader@ip-10-20-8-44:/var/www/catalog/catalog$ sudo service apache2 restart [sudo] password for grader: * Restarting web server apache2 [ OK ]

Error Logs

(venv)grader@ip-10-20-8-44:/var/www/catalog/catalog$ sudo tail -20 /var/log/apache2/error.log
[Wed Jul 01 16:51:36.873041 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] Traceback (most recent call last):
[Wed Jul 01 16:51:36.873059 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704]   File "/var/www/catalog/catalog.wsgi", line 7, in <module>
[Wed Jul 01 16:51:36.873105 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704]     from catalog import app as application
[Wed Jul 01 16:51:36.873117 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704]   File "/var/www/catalog/catalog/__init__.py", line 35, in <module>
[Wed Jul 01 16:51:36.873257 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704]     open('client_secrets.json', 'r').read())['web']['client_id']
[Wed Jul 01 16:51:36.873279 2015] [:error] [pid 14600:tid 140294116747008] [client 73.221.39.5:60704] IOError: [Errno 2] No such file or directory: 'client_secrets.json'
[Wed Jul 01 16:53:36.405496 2015] [mpm_event:notice] [pid 14596:tid 140294245513088] AH00491: caught SIGTERM, shutting down
[Wed Jul 01 16:53:37.387879 2015] [mpm_event:notice] [pid 14715:tid 140705447798656] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Wed Jul 01 16:53:37.387939 2015] [core:notice] [pid 14715:tid 140705447798656] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jul 01 17:35:23.312436 2015] [mpm_event:notice] [pid 14715:tid 140705447798656] AH00491: caught SIGTERM, shutting down
[Wed Jul 01 17:35:24.360945 2015] [mpm_event:notice] [pid 15120:tid 140719357745024] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Wed Jul 01 17:35:24.361007 2015] [core:notice] [pid 15120:tid 140719357745024] AH00094: Command line: '/usr/sbin/apache2'
[Wed Jul 01 17:35:35.741239 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] mod_wsgi (pid=15123): Target WSGI script '/var/www/catalog/catalog.wsgi' cannot be loaded as Python module.
[Wed Jul 01 17:35:35.741269 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] mod_wsgi (pid=15123): Exception occurred processing WSGI script '/var/www/catalog/catalog.wsgi'.
[Wed Jul 01 17:35:35.741302 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] Traceback (most recent call last):
[Wed Jul 01 17:35:35.741317 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118]   File "/var/www/catalog/catalog.wsgi", line 7, in <module>
[Wed Jul 01 17:35:35.741359 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118]     from catalog import app as application
[Wed Jul 01 17:35:35.741369 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118]   File "/var/www/catalog/catalog/__init__.py", line 35, in <module>
[Wed Jul 01 17:35:35.741483 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118]     open('client_secrets.json', 'r').read())['web']['client_id']
[Wed Jul 01 17:35:35.741501 2015] [:error] [pid 15123:tid 140719262549760] [client 73.221.39.5:61118] IOError: [Errno 2] No such file or directory: 'client_secrets.json'

When I sudo nano /etc/apache2/sites-available/catalog.conf, I have:

WSGIPythonPath /var/www/catalog/catalog/venv/:/var/www/catalog/catalog/v$
<VirtualHost *:80>
      ServerName 52.27.140.219
      ServerAdmin admin@52.27.140.219
      ServerAlias c-73-221-39-5.hsd1.wa.comcast.net
      WSGIScriptAlias / /var/www/catalog/catalog.wsgi
      <Directory /var/www/catalog/catalog/>
          Order allow,deny
          Allow from all
      </Directory>
      Alias /static /var/www/catalog/catalog/static
      <Directory /var/www/catalog/catalog/static/>
          Order allow,deny
          Allow from all
      </Directory>
      ErrorLog ${APACHE_LOG_DIR}/error.log
      LogLevel warn
      CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>

2 Answers2

2

Don't use a relative path name to the file. Instead construct an absolute path name. This is needed because the current working directory of the process will not be where your code is located. Read:

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
2

So as Graham said, eventually, you end up with something like:
APP_PATH = '/var/www/catalog/ CLIENT_ID = json.loads(open(APP_PATH + 'client_secrets.json', 'r').read())['web']['client_id']

Anne Sophie
  • 121
  • 1
  • 6