How to run Django and Php on one Apache2? - php

I want to run my Django app and mediawiki at same domain on one Apache2.But I find there is a problem hard to solve.
In my config, localhost and localhost/mediawiki can normal access, but when I access to localhost/dblog(It's my Django app's directory), browser shows "Bad Request (400)".
I trid to google and another related questions at stackoverflow, but still can't solve this problem.
Here is my Apache2 config:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ServerName localhost
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www>
Options ALl
AllowOverride All
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess dblog python-path=/var/www/dblog:/usr/lib/python2.7/site-packages
WSGIProcessGroup dblog
WSGIScriptAlias /dblog /var/www/dblog/dblog/wsgi.py
<Directory /var/www/dblog>
Options +ExecCGI
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>
</VirtualHost>
Thank you!

Related

Laravel 8 404 api routes in production

I have never had this issue before, it was working perfectly and after I reinstalled the server I now got a 404 when I call my 0.0.0.0/api/students/show.
I did composer production call on SSH to create latest autoloader. Cleared the cache for php artisan, the normal steps to setup a Laravel production app. But I still get 404 when I call the API endpoint.
Maybe the problems is something with chmod rights? Storage, etc. is already done...
In your apache2.conf make sure you've AllowOverride All and not AllowOverride none.
Example
<Directory /var/www/html/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Original Answer
You should not need to write Directory at all.
This is my working page custom .conf file on sites-available folder:
<VirtualHost *:80>
ServerName matiaslauriti.dev
ServerAlias www.matiaslauriti.dev
Redirect 301 / https://matiaslauriti.dev
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName matiaslauriti.dev
ServerAlias www.matiaslauriti.dev
DocumentRoot /var/www/html/public
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/matiaslauriti.dev/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/matiaslauriti.dev/privkey.pem
</VirtualHost>
</IfModule>
What I do have on my apache2.conf is default, I did not change anything:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options +FollowSymLinks -Indexes
AllowOverride All
Require all granted
</Directory>

Unable to access my virtual host from the same network using IP address

I'm trying to run two different sources in xampp (one for admin one for users).
I have found one solution by using httpd-vhosts.conf.
In C:\xampp\apache\conf\extra\httpd-vhosts.conf file I have added below config.
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\project\user\www"
ServerName 192.169.9.99
<Directory "C:\xampp\htdocs\project\user\www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\project\admin\www"
ServerName 192.169.9.99.co
<Directory "C:\xampp\htdocs\project\admin\www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now, I can able to see user and admin pages running in 192.169.9.99 and 192.169.9.99.co
But, here my problem is, I tried with another system that present in my same network.
It has given proper result for 192.169.9.99 but not for 192.169.9.99.co
192.169.9.99.co redirecting to 99.co website.
Where I did wrong, Is I missed anything?
There are any other solutions for achieving this requirement?
Is this possible to achieve this?Thanks.
#Start
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\project\admin\www"
ServerName 192.169.9.99.co
<Directory "C:\xampp\htdocs\auction\frontend\www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
#next
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\project\user\www"
ServerName 192.169.9.99
<Directory "C:\xampp\htdocs\auction\frontend\www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
192.169.9.99 Will be found earlier because the match.
VirtualHost *:80
192.169.9.99
192.169.9.99.co
I have added "Listen 8081" in httpd.conf, so that now my xammp will listen 80 and 8081 ports.
In httpd-vhosts.conf I have added
<VirtualHost *:8081>
DocumentRoot "C:\xampp\htdocs\project\admin\www"
</VirtualHost>
Document root for port 80 will taken from httpd.conf file.
Now I tried with another system that in my network, on 192.169.9.99 My user site is running.
In 192.169.9.99:8081 My admin site is running.

Run both Django and PHP application in Apache

I'm trying to host Django and PHP(wordpress) app in Apache
domain.com, should point to Django app
domain.com/wp, should point to wordpress app
Here is my 000-default.conf in /etc/apache2/sites-available
<VirtualHost *:80>
DocumentRoot "/var/www/html/wp"
ServerName domain.com/wp
Alias /wp /var/www/html/wp
<Directory /var/www/html/wp>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
Alias /static /var/www/html/portal/static
<Directory /var/www/html/portal/static>
Require all granted
</Directory>
<Directory /home/ubuntu/portal/portal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess portal python-path=/home/ubuntu/portal:/home/ubuntu/portal/env/lib/python2.7/site-packages
WSGIProcessGroup portal
WSGIScriptAlias / /home/ubuntu/portal/portal/wsgi.py
</VirtualHost>
domain.com is taking me to wordpress application.
Can anyone tell me where the issue is or give me a direction to solve this.
Few issues, first thing is that the ServerName is just a servername and not a url. The second issue is that you should combine the two VirtualHost entries.
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName domain.com
Alias /wp /var/www/html/wp
<Directory /var/www/html/wp>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
Alias /static /var/www/html/portal/static
<Directory /var/www/html/portal/static>
Require all granted
</Directory>
# this really should be a sub directory of /var/www/html
# if your server config follows symlinks, just make a symlink
<Directory /home/ubuntu/portal/portal>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess portal python-path=/home/ubuntu/portal:/home/ubuntu/portal/env/lib/python2.7/site-packages
WSGIProcessGroup portal
WSGIScriptAlias / /home/ubuntu/portal/portal/wsgi.py
</VirtualHost>

Virtualhost Apache, Rails and PHP

I am trying to have a Rails application to coexist on one server along with a PHP page. I am using Apache installed through Passenger.
So, I have created a virtualhost file for my php page, and it is as such:
<VirtualHost *:80>
ServerAdmin mail#mail.com
ServerName subsite.site.com
DocumentRoot "/var/www/subsite"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/subsite">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
My problem is that this mysite.site.com keep being redirected to the main rails site. Any idea?

How do I run Django and PHP together on one Apache server?

I can currently run either Django through mod_wsgi or PHP on my Apache server.
My Django projects run at: http://localhost and source is at C:/django_proj
My PHP projects run at: http://php.localhost and source is at C:/web
If I turn both on, php.localhost and localhost go to the Django project. I've already set them up through Apache virtual hosts.
Here are some relevant lines in httpd.conf:
DocumentRoot "C:/web"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "C:/web">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "C:/django_proj">
Order allow,deny
Allow from all
</Directory>
Include "C:/django_proj/apache/apache_django_wsgi.conf"
The relevant lines in apache_django_wsgi.conf is:
WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
<Directory "C:/django_proj/apache">
Order allow,deny
Allow from all
</Directory>
Inside httpd-vhosts.conf:
<Directory C:/web>
Order Deny,Allow
Allow from all
</Directory>
<Directory C:/django_proj>
Order Deny,Allow
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot "C:/django_proj"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/web"
ServerName php.localhost
</VirtualHost>
My PHP project is current inaccessible. Does anyone have any ideas what I'm missing?
I run dozens of mod_wsgi/Django sites, PHP sites, and a Rails site with a single Apache.
It's mostly done using virtual hosts but I have some that are running both on the same domain.
You just need to put your WSGIScriptAlias /... after any other Location/Alias directives.
Lets say, for example, I want to run phpMyAdmin on the same domain as a Django site. The config would look something like this:
Alias /phpmyadmin /full/path/to/phpmyadmin/
<Directory /full/path/to/phpmyadmin>
Options -Indexes
...etc...
</Directory>
WSGIScriptAlias / /full/path/to/django/project/app.wsgi
<Directory /full/path/to/django/project>
Options +ExecCGI
...etc...
</Directory>
Edit:
Your configuration should look something like this:
<VirtualHost *:80>
DocumentRoot "C:/django_proj"
ServerName localhost
WSGIScriptAlias / "C:/django_proj/apache/proj.wsgi"
<Directory "C:/django_proj/apache">
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/web"
ServerName php.localhost
Alias / C:/web
<Directory C:/web>
Options Indexes FollowSymLinks
AllowOverride None
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
You don't need those <Directory> directives in http.conf... do all your configuration in the Virtual hosts.
Also, completely get rid of the <Directory /> block.
Your WSGIScriptAlias / ... directive is telling Apache that everything request starting with "/" should get fed through Django's WSGI handler. If you changed that to read WSGIScriptAlias /django-proj/ ... instead, only requests starting with "/django-proj" would get passed into Django.
An alternative would be to start setting up virtual hosts for each project. This way you could configure Apache to put each project at the / of it's own domain, and you wouldn't need to worry about the configuration for one project affecting one of your other projects.
I had the same problem.
Try removing this block <Directory /> in httpd-conf.
Include httpd-vhost.conf and and try puting my WSGIScriptAlias / "/somewhere/file.wsgi" in virtual host section of httpd-vhosts which listens to port 80.
I would like to add that if you are using Apache ProxyPass, it's possible to deny certain URL patterns so that it falls to mod_php.
ProxyPass /wordpress !
<Location /wordpress>
Require all granted
</Location>

Categories