apache2 python cgi misconfiguration - permissions

I am having problems with executing a python script from a browser.
My script is simple as follows,
cameron_toll.py
#!/usr/bin/env python
print "Content-type: text/html\n\n";
import mapnik
print "Done"
The permissions are as follows,
-rwxrwxrwx 1 www-data www-data 77 2011-11-28 12:59 cameron_toll.py
drwxrwsr-x 2 antony antony 4096 2011-11-28 10:42 cgi-bin
I have also tried setting "antony antony" to the cameron_toll.py but still does not work.
My error log file is,
[Mon Nov 28 14:36:43 2011] [error] [client 92.27.17.145] suexec policy violation: see suexec log for more details
[Mon Nov 28 14:36:43 2011] [error] [client 92.27.17.145] Premature end of script headers: cameron_toll.py
the script runs fine from my shell window which means that python is ok and mapnik is imported fine.
Any ideas or suggestions would be extremely appreciated.

Ok, I think I have got it. It was a permission error indeed. I had a user misconfiguration. The User did not have rights to execute..

Related

Impossible to import flask_cors with apache2, mod_wsgi under Python3.5 on a Raspberry pi

I try to setup a website based on Flask on a Raspberry Pi 3B+, with Apache2 (2.4.25), and mod_wsgi, but I am unable to import the module flask_cors in Python3.5...
I installed mod_wsgi with the command ssudo apt-get install libapache2-mod-wsgi
Because I only plan on using the Raspberry for hosting my website, I tried to install the packages needed by Flask system-wide, with the version 3.5 of Python, with the following command: pip3 install -r requirements.txt where requirements.txt is the following:
click==6.7
Flask==0.12.3
Flask-Cors==3.0.3
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
six==1.11.0
Werkzeug==0.12.2
Requests==2.20.0
I think I understood that on a Raspi, it is best to import the modules wit the command pip3 install -U <module> because the packages are not installed on the default location for python, which is confirmed in my case by the following command python -m site that yields the following information:
sys.path = [
'/home/pi/.local/lib/python3.5/site-packages',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-arm-linux-gnueabihf',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/pi/.local' (exists)
USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (exists)
ENABLE_USER_SITE: True
My Flask and dependencies are indeed installed in the /home/pi/.local/lib/python3.5/site-packages folder. But this does not seem to be a problem because when checking for importing on a python shell, everything seems fine systemwide:
pi#raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask_cors import CORS
>>>
Knowing that, I tried to put the following files to setup my apache server:
flaskregul.conf in the folder /etc/apache2/sites-enabled:
<VirtualHost *:80>
WSGIScriptAlias / /var/www/flaskregul/flaskregul.wsgi
Alias /static/ /var/www/flaskregul/dist/static/
<Directory /var/www/flaskregul/dist/static>
WSGIProcessGroup flaskregul
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/flask.monnomdedomaine.com.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
flaskregul.wsgi in /var/www/flaskregul:
import sys
sys.path.insert(0,"/var/www/flaskregul") # path to my __init__.py file
sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages") # path to the site-packages folder where the modules are installed by pip3
from __init__ import app as application
__init__.py in /var/www/flaskregul:
from flask import Flask
from flask_cors import CORS
I encounter an impossibilty to specifically import the flask_cors module, because the launching of the file __init__.py yields the following errors in the file /var/log/apache2/flask.monnomdedomaine.com.log:
[Sat Nov 10 00:37:22.220394 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Target WSGI script '/var/www/flaskregul/flaskregul.wsgi' cannot be loaded as Python module.
[Sat Nov 10 00:37:22.220972 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] mod_wsgi (pid=6804): Exception occurred processing WSGI script '/var/www/flaskregul/flaskregul.wsgi'.
[Sat Nov 10 00:37:22.221936 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] Traceback (most recent call last):
[Sat Nov 10 00:37:22.222365 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/flaskregul.wsgi", line 1, in <module>
[Sat Nov 10 00:37:22.222395 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from __init__ import app as application
[Sat Nov 10 00:37:22.222445 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] File "/var/www/flaskregul/__init__.py", line 2, in <module>
[Sat Nov 10 00:37:22.222463 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] from flask_cors import CORS
[Sat Nov 10 00:37:22.222557 2018] [wsgi:error] [pid 6804:tid 1955591216] [client 192.168.1.67:33550] ImportError: No module named 'flask_cors'
Whereas the import of Flask seems fine...
I've tried to debug this by changing the WSGI script file by this one:
import sys
sys.path.insert(0,"/var/www/flaskregul")
sys.path.insert(0,"/home/pi/.local/lib/python3.5/site-packages")
def application(environ, start_response):
status = '200 OK'
output = u''
output += u'sys.version = %s\n' % repr(sys.version)
output += u'sys.prefix = %s\n' % repr(sys.prefix)
output += u'sys.path = %s\n' % repr(sys.path)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output.encode('UTF-8')]
This is a piece of advice the advice on this web page from mod_wsgi: https://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html. When opening the webpage, I obtain this result:
sys.version = '3.5.3 (default, Sep 27 2018, 17:25:39) \n[GCC 6.3.0 20170516]'
sys.prefix = '/usr'
sys.path = ['/home/pi/.local/lib/python3.5/site-packages', '/var/www/flaskregul', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/local/lib/python3.5/dist-packages/virtualenv-16.1.0-py3.5.egg', '/usr/lib/python3/dist-packages']
I have the impression that the path is correct! I actually succeed in importing my own modules located in the /var/www/flaskregul location...
I am lost, I don't understand why specifically the module flask_cors is unavaiblable, because it is indeed in the path:
pi#raspberrypi:~/.local/lib/python3.5/site-packages $ l | grep flask
drwxr-xr-x 5 pi pi 4096 nov. 9 23:30 flask
drwxr-xr-x 3 pi pi 4096 nov. 10 00:08 flask_cors
pi#raspberrypi:~/.local/lib/python3.5/site-packages $ l flask_cors
total 44
-rw-r--r-- 1 pi pi 13771 nov. 10 00:08 core.py
-rw-r--r-- 1 pi pi 4937 nov. 10 00:08 decorator.py
-rw-r--r-- 1 pi pi 7405 nov. 10 00:08 extension.py
-rw-r--r-- 1 pi pi 924 nov. 10 00:08 __init__.py
drwxr-xr-x 2 pi pi 4096 nov. 10 00:08 __pycache__
-rw-r--r-- 1 pi pi 22 nov. 10 00:08 version.py
Any help would be very much appreciated! I am currently losing my hair at a worriyng rate!
Oh my god I solved it in a desperate try before giving up.
I executed the following commands on a shell: (pip is the pip of the python3.5 /!\)
pip uninstall flask
pip uninstall flask_cors
sudo pip install --upgrade pip
hash -d pip
sudo pip install -U flask
sudo pip install -U flask_cors
Website up and running! :D

Moodle 3.4 installation on Centos 7

Installing a test Moodle (3.4.1) using the instructions on Moodle site but only got blank page when accessing it. I put the moodle installation on /var/www/html/moodle. The install.php script returns with success.
I am using PHP 7.0 on the ius repository.
httpd error log has these entries:
[Thu Jan 18 10:45:24.626059 2018] [:error] [pid 29857] [client ::1:41946] PHP Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
[Thu Jan 18 10:21:39.114019 2018] [:error] [pid 28769] [client ::1:41930] PHP Fatal error: Unknown: Failed opening required '/var/www/html/moodle/index.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
I have tried to chmod to 755 and still the same problem.
Am I missing some php libraries?
Thanks,
Alex
try to give all the rights
sudo chmod -R 777 /path/to/moodle
Probably I did something wrong during the first install. Redid a clean install and everything works fine.

Unable to start Apache 2.4.18 on Windows

I try to start up my HTTP service by the following procedure:
Startup easyPHP DevServer 16.1
Open Dashboard
Opens on the local machine 127.0.0.1:1111
Try to start the HTTP server using Apache 2.4.18
opens Apache page with VC11 compiler and server with
php version 5.6.17 listening on port 80.
Clicking on the Start button results in a short execution
and then no result. Both the error and access logs are empty.
Any suggestions are appreciated.
In order to properly execute PHP7 you must allready install the Redistribuable Visual C++ V14 (as shown in the PHP7 information detail on easyphp dashboard)
You can find it out here https://www.microsoft.com/download/details.aspx?id=48145
Currently PHP7 is only available in easyPHP in 32bits version, so install the compatible version of VC14.
But soon I hope we can use the x64 PHP7 version, and then you must install the x64 VC14 version
Windows 7 SP1 box, EasyPhp-DevServer-16.1.
Since I have a website to migrate, I decided to update EasyPHP on my computer to start with fresh-up-to-date versions of PHP, Apache, MySQL. Maybe I shouldn't have... the TaskBar icon and admin interface have changed, nothing works like before.
But I am stubborn, and I want it to work. So I try to run something, and it is not. Here are the symptoms, very close to Richard's:
Trying to start Apache 2.4.18, choosing PHP 7.0.2. Click on green "Start" button, it turns into a red "Stop" button. Everything is OK? Nope. Clicking on the "Error log" button, the page comes back to previous state with green "Start" button and nothing in the error log textarea.
OK, so I choose PHP 5.6.17 and click on "Start". I have popups claiming for instance "bz2: Unable to initialize module. Module compiled with module API=20131226. PHP compiled with module API=20121212. These options need to match."
The button turns to red "Stop", and clicking on "Error log" button produces this output:
PHP Warning: PHP Startup: bz2: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: gd: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mbstring: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mysql: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: mysqli: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: sockets: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: sqlite3: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: xsl: Unable to initialize module\nModule compiled with module API=20131226\nPHP compiled with module API=20121212\nThese options need to match\n in Unknown on line 0
[Mon Feb 22 16:51:45.788809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00455: Apache/2.4.18 (Win32) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 22 16:51:45.789809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00456: Apache Lounge VC11 Server built: Dec 11 2015 11:26:53
[Mon Feb 22 16:51:45.789809 2016] [core:notice] [pid 3292:tid 236] AH00094: Command line: '..\\eds-binaries\\httpserver\\apache2418x160222160722\\bin\\eds-httpserver.exe -d C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722'
[Mon Feb 22 16:51:45.797809 2016] [mpm_winnt:notice] [pid 3292:tid 236] AH00418: Parent: Created child process 2568
Xdebug requires Zend Engine API version 220131226.
The Zend Engine API version 220121212 which is installed, is outdated.
Since Apache seems to be running, I then launch MySQL. Then I try to run PHPMyAdmin. Here is the resulting message:
phpMyAdmin - Error
The mbstring extension is missing. Please check your PHP configuration.
Of course, since this extension didn't manage to be initialized!
So, here are my complementary questions to Richard's:
What can cause Apache to neither launch nor write any log when choosing PHP 7.0.2?
What can cause Apache to not initialize modules when launching with PHP 5.6.17?
Thanks for any clue,
Seagram
Hello again,
I found out an answer to myself for question 2. that may interest others:
When I installed EasyPHP-DevServer-16.1, I didn't uninstall EasyPHP-DevServer-14.1VC11. In order to have another development working months ago, I have modified my PATH environment variable to point to the php executable in this version.
Now I have removed this path reference in the PATH variable. I also exited from EasyPHP TaskBar icon. THIS IS IMPORTANT in order for this tool to forget the old PATH value. Then I restarted it, clicked on DashBoard again and launched Apache.
Now Apache starts smoothly with PHP 5.6.17 and the error log file contains only:
[Mon Feb 22 17:16:20.295146 2016] [core:warn] [pid 6652:tid 236] AH00098: pid file C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Mon Feb 22 17:16:20.313147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00455: Apache/2.4.18 (Win32) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 22 17:16:20.313147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00456: Apache Lounge VC11 Server built: Dec 11 2015 11:26:53
[Mon Feb 22 17:16:20.313147 2016] [core:notice] [pid 6652:tid 236] AH00094: Command line: '..\\eds-binaries\\httpserver\\apache2418x160222160722\\bin\\eds-httpserver.exe -d C:/BIN/EasyPHP-Devserver-16.1/eds-binaries/httpserver/apache2418x160222160722'
[Mon Feb 22 17:16:20.321147 2016] [mpm_winnt:notice] [pid 6652:tid 236] AH00418: Parent: Created child process 4052
[Mon Feb 22 17:16:20.895180 2016] [mpm_winnt:notice] [pid 4052:tid 316] AH00354: Child: Starting 64 worker threads.
However, with PHP 7.0.2., Apache keeps on not starting and doesn't trace anything in error log.
Something else is missing...

Centos | Yiiframework | Permission Denied

I am facing permission denied error while trying to deploy an Yii based application on Apache Httpd server, following are logs of same.
require_once(): Failed opening required
'/home/tarun/scripts/yii-1.1.13/framework/yii.php'
(include_path='.:/usr/share/pear:/usr/share/php') in
/var/www/hellouttarakhand.com/index.php on line 12 [Sat Apr 06
14:49:03 2013] [error] [client ::1] PHP Warning:
require_once(/home/tarun/scripts/yii-1.1.13/framework/yii.php): failed
to open stream: Permission denied in
/var/www/hellouttarakhand.com/index.php on line 12
Due to above error, application page always appears blank as script is not able to execute.
I have given chmod 777 to yii root folder as well executed following command
chcon -Rv --type=httpd_user_content_rw_t
/home/tarun/scripts/yii-1.1.13/
but still no luck with this error.
Any pointers will be appreciated.

symfony unlink warning in Apache error log

I have a symfony 1.4 project that is continually putting the following warning in the Apache error log:
[Wed Sep 26 06:18:22 2011] [error] [client 192.168.100.12] PHP Warning: unlink(/var/cache/project-ttp/device/dev/config/config_autoload.yml.php): No such file or directory in /usr/share/project-ttp/lib/vendor/symfony/lib/autoload/sfAutoload.class.php on line 132
Any idea what may be causing this?