How to install mod_wsgi for apache2.4 with python 3.6 in centos? - apache

I am a new to web development.I have created Django(-v 2.2) web application and I want to deploy it on my linux server(OS Centos).After installation apache2, when I was going to install libapache2-mod-wsgi-py3, it says that no package available. Is there different name for libapache2-mod-wsgi-py3 for OS Centos?

It is always recommended to install mod_wsgi directly into the python3 package using pip3.
pip3 install mod_wsgi
If you install mod_wsgi into the OS, it could cause conflict and unexpected behavior.

Do you have apache2-dev installed?
Also, for mod_wsgi it is better to go the CMMI path (configure-make-make install) in order to compile it with the correct version and load it in Apache as a module. This worked for me on Debian VPS:
To do so,
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/4.6.5.tar.gz
tar xvfz 4.6.5.tar.gz
cd mod_wsgi-4.6.5
whereis apxs
whereis python3
./configure --with-apxs=/usr/bin/apxs --with-python=/usr/bin/python3.5
make
sudo make install
Double check the path for apxs and python, and run make install as sudo.
When it’s all ready, check the last line of prompt results, as there will be a path to a file: /usr/lib/apache2/modules/mod_wsgi.so
To cleanup after installation, run:
make clean
If you need to build the module for a different version of Apache, you should run:
make distclean
If you have a httpd.conf file, you should edit and add this line:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
If not, create it and paste that line, and edit /etc/apache2/apache2.conf. file, by adding this line:
Include /etc/apache2/httpd.conf
You don't need that file to configure apache, but you can create it if other software relies on it being there.
You should restart Apache and check the log
sudo tail /var/log/apache2/error.log
as there should be a line that says:
Apache/2.4.25 (Debian) mod_wsgi/4.6.5 Python/3.5 configured -- resuming normal operations

Related

How to install mod_wgsi for apache 2.4+ with python3.5 on CentOS 7

As title says "How to install mod_wgsi for python3.5 on CentOS 7"?
$pip3.5 install mod_wgsi did not work
Collecting mod_wgsi
Could not find a version that satisfies the requirement mod_wgsi (from versions: )
No matching distribution found for mod_wgsi
sudo yum install libapache2-mod-wsgi-py3 failed too:
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
* base: mirror.daniel-jost.net
* epel: mirrors.n-ix.net
* extras: mirror.daniel-jost.net
* ius: mirror.amsiohosting.net
* remi: mirror.23media.de
* remi-php56: mirror.23media.de
* remi-safe: mirror.23media.de
* updates: mirror.daniel-jost.net
No package libapache2-mod-wsgi-py3 available.
Error: Nothing to do
Any suggestions on how to run apache2.4+ mod_wsgi with python3.5 on CentOS 7 are very welcome!
I tried following Carl's answer, but it didn't solve the problem. It turns out that the version I installed required some extra configuration steps after installation.
Background
I looked at Apache's modules folder before I installed the mod_wsgi upgrade:
$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so
Then I installed the SCL repository, and looked to see which versions of mod_wsgi are available.
$ sudo yum install -q -y centos-release-scl
[...]
$ yum search mod_wsgi
[...]
koschei-frontend.noarch : Web frontend for koschei using mod_wsgi
mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python27-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
python33-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python34-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python35-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
rh-python36-mod_wsgi.x86_64 : A WSGI interface for Python web applications in Apache
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
[...]
I'm using Python 3.6, so I installed the matching version and restarted Apache.
$ sudo yum install -q -y rh-python36-mod_wsgi
[...]
$ sudo systemctl restart httpd
Sadly, that didn't solve the problem. When I looked in Apache's modules folder, nothing had changed. Weird!
$ ls -l /lib64/httpd/modules
[...]
-rwxr-xr-x. 1 root root 172800 Oct 30 22:44 mod_wsgi.so
So what did get installed?
$ rpm -ql rh-python36-mod_wsgi
/opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf
/opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/CREDITS.rst
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/LICENSE
/opt/rh/rh-python36/root/usr/share/doc/rh-python36-mod_wsgi-4.5.18/README.rst
Extra Configuration Steps
It installed the files I need, but it didn't put them anywhere useful. With some hints from the README.rst file, I copied them into the right place.
sudo cp /opt/rh/httpd24/root/usr/lib64/httpd/modules/mod_rh-python36-wsgi.so /lib64/httpd/modules
sudo cp /opt/rh/httpd24/root/etc/httpd/conf.modules.d/10-rh-python36-wsgi.conf /etc/httpd/conf.modules.d
sudo systemctl restart httpd
Now I have the right version of mod_wsgi, and my Django app will run under Apache.
I see you already have the IUS repo enabled. Rather than jumping through SCL hoops, you can just install a normal package.
yum install python35u-mod_wsgi
This will use standard filesystem locations to work with stock Apache HTTPD 2.4.
/etc/httpd/conf.modules.d/10-wsgi-python3.5.conf
/usr/lib64/httpd/modules/mod_wsgi_python3.5.so
Have you check the rh-python35 Software Collection which provides a rh-python35-mod_wsgi package ?
More information about SCL, see:
The Software Collection (SCL) Repository
The Software Collection Special Interest Group
RHSCL 2.3 release announcement
I would use the SCL packages for python 3.6 (though feel free to substitute 3.5 below).
To start:
yum install centos-release-scl
yum install rh-python36 rh-python36-mod_wsgi
Note that will bring in the SCL package httpd24-httpd and put the mod_wsgi file in that installation. I would recommend you use that installation and not install the base CentOS httpd package. At time of writing, for CentOS 7, the httpd package is 2.4.6 and the httpd24-httpd package is 2.4.37.
Then you create a virtualenv with:
/opt/rh/rh-python36/root/usr/bin/python -m venv /path/to/venv36
source /path/to/venv36/bin/activate
pip install ...
Now you can put the config for your site in /opt/rh/httpd24/root/etc/httpd/conf.d/mysite.conf, which could contain something like:
<VirtualHost *:80>
LoadModule wsgi_module modules/mod_wsgi.so
ErrorLog /var/log/httpd24/mysite-err.log
CustomLog /var/log/httpd24/mysite.log combined
# recommended way of setting DJANGO_SETTINGS_MODULE http://stackoverflow.com/a/25496668/3189
WSGIProcessGroup mysite.settings.production
WSGIDaemonProcess mysite.settings.production python-path=/path/to/mysite/:/path/to/venv36/lib/python3.6/site-packages
WSGIScriptAlias / /path/to/mysite/wsgi.py process-group=mysite application-group=%{GLOBAL}
</VirtualHost>
Now you start the SCL apache with:
systemctl start httpd24-httpd
And your site should be working.

Homebrew PHP Install Breaks Apache 2.4

When I recently installed PHP56 via Homebrew, Apache would no longer start, with this error in the logs:
Cannot load /usr/local/opt/php56/libexec/apache2/libphp5.so into server: dlopen(/usr/local/opt/php56/libexec/apache2/libphp5.so, 10): image not found
Note: I'm running Apache 2.4 on Mac El-Capitan.
How can I resolve this error and get Apache running again?
I've seen this before. If you brew options php56, it says:
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
you have to install php with the --with-apache option. See brew options php56 for more details.
Thus, try uninstalling (brew uninstall php56) then reinstalling php56 with the flag --with-apache for Apache v2.4.x (--with-apache22 for Apache 2.2). Generally, you can check your Apache version by typing in command line: httpd -v.
My version is 2.4.18, so I would brew install php56 --with-apache, which creates the proper file path /usr/local/opt/php56/libexec/apache2/libphp5.so.
Now, it is properly compiled with Apache Handler module.
IMPORTANT: installing php56 with this option appears to also install httpd24. From a brew program stance, this makes sense. However, this may break your server set up. If you don't want to use brew's Apache install, do a brew unlink httpd24 after this.
To see additional brew build options, try brew options php56.

Not able to install mod_perl module on the server

In my site I am getting an error : an error occurred while processing this directive
It was working fine before moving to the new server. So when I checked I found that mod_perl module is missing. So I tried to install it by downloading the module to the server and then tried to run using Perl Makefile.pl but it was asking for apache src and I was not able to find it. I can see /usr/bin/apache/ folder but no source file inside the folder.
So I tried to install the module from Cpanel but I got the following error:
The C compiler is not functional and auto repair failed. Perl module installs require a working C compiler. Please repair the C compiler and try again.
Please let me know how to install it as I have tried most of the cases searching the net.
Thanks in advance
It's probably best to use your distro's packaging system to install mod_perl, especially, if apache is installed from a package too.
Yum based systems:
yum install mod_perl
Deb based systems
apt-get install mod_perl
you may need to enable the module using a2enmod
Mostly gcc is either corrupted or not present on your system. Please try to re/install gcc on your system
sudo apt-get update
sudo apt-get install build-essential
On Redhat:
yum update
yum install devtoolset-2-toolchain
It seems like a problem with your installation of gcc. You're using CloudLinux, so you should use yum to reinstall gcc.
$ sudo -i yum install gcc
But you don't need gcc if you install the pre-build packages.
$ sudo -i yum install mod_perl
Either way, you're going to need to get to grips with package installation for your system - and for that you're going to need root access.

Installing Cobbler on Ubuntu 15.10 seems to break apache, how can I fix this?

I am trying to install Cobbler on a brand new Ubuntu 15.10 virtual box but it is not working. When I run the apt-get install cobbler cobbler-web it seems to break apache completely to the point I can't get it working again.
I see this in the apache error log:
[wsgi:crit] [pid 8112:tid 140273573488512] mod_wsgi (pid=8112): The mod_python module can not be used on conjunction with mod_wsgi 4.0+. Remove the mod_python module from the Apache configuration.
and this in the auth.log:
polkitd(authority=local): Unregistered Authentication Agent for unix-process:8081:54865 (system bus name :1.24, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
I have tried removing the mod_python and wsgi modules but apache still doesn't start up. And I think Cobbler uses them anyways, so I kind of need them.
I have also tried disabling polkitd. I don't find any clues when searching for that weird error message.
I was able to install Cobbler on Ubuntu 14.04 pretty easily and apache works fine.
Here is the basic chain of install commands I used:
apt-get update
apt-get install apache2
apt-get install isc-dhcp-server
apt-get install bind9 bind9utils bind9-doc
apt-get install cobbler cobbler-web debmirror mkisofs
Disable the module by typing sudo a2dismod python
You should then see this:
Module python disabled. To activate the new configuration, you need to
run: service apache2 restart
So type sudo service apache2 restart.
If that doesn't fix it, check the error log for more information by typing
cat /var/log/apache2/error.log.

Issues installing mod_wsgi - cannot find Makefile.in

I'm trying to rebuild mod_wsgi and am running into this issue? Does anyone know what's going on here?
/tmp/mod_wsgi-3.4# ls
config.log LICENCE posix-ap2X.mk.in win32-ap22py31.mk
config.status Makefile.in README
configure mod_wsgi.c win32-ap22py26.mk
configure.ac posix-ap1X.mk.in win32-ap22py27.mk
root#vps-547073:/tmp/mod_wsgi-3.4# ./configure
checking for apxs2... no
checking for apxs... no
checking Apache version... ./configure: line 1704: apxs: command not found
./configure: line 1704: apxs: command not found
./configure: line 1705: apxs: command not found
./configure: line 1708: /: Is a directory
checking for python... /usr/bin/python
./configure: line 1877: apxs: command not found
configure: creating ./config.status
config.status: error: cannot find input file: Makefile.in
See the mod_wsgi instructions:
http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide#Apache_Requirements
It says:
On Linux systems, if Apache has been installed from a package
repository, you must have installed the corresponding Apache "dev"
package as well.
For most Linux distributions, the "dev" package for Apache 2.X is
"apache2-dev" where the corresponding Apache package was "apache2".
Some systems however distinguish the "dev" package based on which MPM
is used by Apache. As such, it may also be called "apache2-worker-dev"
or "apache2-prefork-dev". If using Apache 2.X, do not mix things up
and install "apache-dev" by mistake, which is the "dev" package for
Apache 1.3 called just "apache".
You are missing that dev package for Apache. This is why 'apxs' cannot be found and subsequent issues occur.
Try to install apache-dev. Use below command in terminal to install.
sudo yum install httpd-devel
OR
Ubuntu/Debian: sudo apt-get install apache2-dev