I followed this guide and managed to make Python with a Django installation work perfectly, but it seems to have rendered all the locally hosted PHP sites inaccessible returning a 404 error.
httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
#This is placed right after the rule for <Directory "f:/WAMP/www/">
<Directory "f:/WAMP/www/python">
Options ExecCGI
AddHandler wsgi-script .py
Order allow,deny
Allow from all
</Directory>
#This is placed at the end of the file
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include "f:/WAMP/alias/*"
Include "F:/WAMP/www/python/sandbox/apache/apache_django_wsgi.conf"
apache_django_wsgi.conf
Alias /python/images/ "F:/WAMP/www/python/sandbox/images"
<Directory "F:/WAMP/www/python/sandbox/images">
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /python "F:/WAMP/www/python/sandbox/apache/django.wsgi"
<Directory "F:/WAMP/www/python/sandbox/apache">
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName 127.0.0.1
</VirtualHost>
django.wsgi
import os, sys
sys.path.append('F:/WAMP/www/python/sandbox')
os.environ['DJANGO_SETTINGS_MODULE'] = 'sandbox.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
PHP only renders when I comment out the lastline from httpd.conf.
You need to have another virtual host if you're going to set the DocumentRoot:
# This is for PHP
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/
ServerName local.php.dev
</VirtualHost>
# This is for your Django stuff
<VirtualHost *:80>
DocumentRoot f:/WAMP/www/python/sandbox/
ServerName local.py.dev
</VirtualHost>
Otherwise, as it is now, all the local requests are being sent to the python sandbox.
Note that you'll need to have several hosts pointing locally.
Related
I am trying to run two php versions with apache. One (PHP7) is setup with mod and the other (PHP8) I am trying to set up with CGI. I am currently testing both work using the different vhosts for https and http. I have the following virtual hosts in my httpd-vhosts.conf file:
<VirtualHost 0.0.0.0:80>
SetEnv PHPRC "C:/Program Files/PHP/php-8.1.12/"
ScriptAlias /php8112/ "C:/Program Files/PHP/php-8.1.12/"
Action application/x-httpd-8112 "/php8112/php.exe"
AddType application/x-httpd-8112 .php
<Directory "C:/Program Files/PHP/php-8.1.12/">
<Files "php.exe">
Require all granted
</Files>
</Directory>
DocumentRoot "D:/Test/Site/public"
ServerName test.local
CustomLog "C:/Users/me/Logs/test_access.log" combined
ErrorLog "C:/Users/me/Logs/test_error.log"
</VirtualHost>
<VirtualHost 0.0.0.0:443>
DocumentRoot "D:/Test/Site/public"
ServerName test.local
SSLEngine on
SSLCertificateFile "C:/Program Files/Apache24/conf/server.cert"
SSLCertificateKeyFile "C:/Program Files/Apache24/conf/server.key"
</VirtualHost>
and a simple index.php in D:/Test/Site/public:
<?php
phpinfo();
?>
Accessing via HTTPS works and correctly gives me the PHP Info page. Accessing via HTTP gives me a 404 Not Found error, however. Why would this be?
I have tried reordering the directives and adding a directory directive for the DocumentRoot directive. Neither seemed to make a difference.
I am using Apache 2.4 on Windows 10
I have a problem setting up my Apache server with mod_php. I have a website whose index.php page is generated in ~200ms. But Apache serves it in about 1.5sec. Why is this slowdown taking place?
If needed, my /etc/apache2/ports.conf file is:
Listen 80
<VirtualHost *:80>
ServerName mysite.local
ServerAlias www.mysite.local
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:9999/
ProxyPassReverse / http://localhost:9999/
</VirtualHost>
My file /etc/apache2/sites-available/mysite.local.conf is:
Listen 9999
User max
Group max
<VirtualHost *:9999>
ServerName 127.0.0.1:9999
DocumentRoot /home/max/www/mysite.local/www/html/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/max/www/mysite.local/www>
Options FollowSymLinks
AllowOverride All
#Order allow,deny
#Allow from all
Require all granted
</Directory>
ErrorLog /home/max/www/mysite.local/logs/error.log
LogLevel warn
CustomLog /home/max/www/mysite.local/logs/access.log combined
</VirtualHost>
My main question is why is this so slow and how can make it faster? I have tested putting the index.php content into a plain html file, and it is served in ~10ms. so the problem is probably with mod_php? Thanks in advance.
A reason could be that apache checks for .htaccess files recursively within each directory of the root for each request. apache is used very widely but not very fast or even optimized.
I definitely would suggest an nginx server combined with php-fpm. The configuration is very straight forward and if you're familiar with apache, you should not have problems using nginx. How To: https://tecadmin.net/setup-nginx-php-fpm-on-ubuntu-20-04/
I have installed the Zend framework. However, when I try to set up the virtual host - apache.
localhost doesn't work.its execute zend folder.its out side of wamp folder.
What have I done:
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include "c:/wamp/alias/*"
NameVirtualHost localhost
<VirtualHost *:80>
DocumentRoot "C:/websites/zendy/public"
ServerName zendy
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "C:/websites/zendy/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "C:/wamp/www">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
how to work this two virtual hosts?
I have two virtual hosts on windows(for example: test1.dev and test2.dev). But it always load content of test1.dev for both virtual hosts.
Following are my files:
hosts:
127.0.0.1 localhost
127.0.0.1 test1.dev
127.0.0.1 test2.dev
httpd.conf:
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include "c:/wamp/alias/*"
<VirtualHost 127.0.0.1>
ServerName test1.dev
DocumentRoot "C:\wamp\www\test1\public"
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName test2.dev
DocumentRoot "C:\wamp\www\test2\public"
</VirtualHost>
Can someone recognize the problem ?
I'm guessing you're missing the NameVirtualHost 127.0.0.1:80 line somewhere :)
I did some thing like this
1- for the local host its :
NameVirtualHost localhost:80
<VirtualHost localhost:80>
ServerName localhost
ServerAlias localhost
DocumentRoot D:/wamp/www
ErrorLog "D:/wamp/www/error.log"
CustomLog D:/wamp/www/access.log common
<Directory "D:/wamp/www">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
2 - and for any other local domain
NameVirtualHost zf.local:80
<VirtualHost zf.local:80>
ServerName zf.local
ServerAlias zf.local
DocumentRoot D:/Workspace/Zend/documentation
ErrorLog "D:/Workspace/Zend/documentation/error.log"
CustomLog D:/Workspace/Zend/documentation/access.log common
<Directory "D:/Workspace/Zend/documentation">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
You don't have to write virtual host info into httpd.conf. Just uncomment line on which you load conf/extra/httpd-vhosts.conf, then go to this file and put your info there. Should work.
Example of my httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost 127.0.0.1>
DocumentRoot "C:/wamp/www"
ServerName dev
</VirtualHost>
You need to include something similar to following line
NameVirtualHost *
Also, it seems you are using https connection to the server which doesn't play well with virtual hosts because of the SSL protocol limitation. The Host header in the http request is encrypted and by the time apache decrypts it, it has already passed on the request to one of the virtual host.
I changed
NameVirtualHost *:80
to
NameVirtualHost 127.0.0.1:80
and it works for me
Don't forget to check for lines like "Listen [::0]:80" in httpd.conf and add your ports there too, if NameVirtualHost doesn't work.
Hey guys I've written a very straight forward tutorial which includes the whole process. Let me know if you run into any problems in a comment.
http://www.kintek.com.au/web-design-blog/configuring-multiple-domains-within-wamp-for-local-development/
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>