Apache Virtual Host Not Parsing PHP

Apache Virtual Host not parsing PHP

This finally put me on the right path:

http://www.linuxquestions.org/questions/linux-server-73/php-not-working-on-one-vhost-but-works-on-all-others-851093/

Here's the solution:

In the <Directory> section, I included these lines:

<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>

Or, a redacted copy/paste of the solution on my server:

<Directory "/var/www/vhosts/A2/httpdocs">
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>

(Other configuration parameters)

</Directory>

Virtual Host not parsing PHP

The solution was that while php was enabled, for some reason the default setting in httpd.conf was not to read .php files as .php.

Although I am not really sure why that would not be the default setting, I added the following to my httpd.conf and now it works just fine:

AddType application/x-httpd-php .php

Virtual Host not parsing PHP

The solution was that while php was enabled, for some reason the default setting in httpd.conf was not to read .php files as .php.

Although I am not really sure why that would not be the default setting, I added the following to my httpd.conf and now it works just fine:

AddType application/x-httpd-php .php

Apache Virtual Hosts Not Working As Expected

It seems the problem comes from the way you use the VirtualHost directive.

Using a fully qualified domain name for the IP address of the virtual host is not recommended. It is misleading how it works. Name based virtual hosts determine the host through the ServerName directive, and not through the FQDN in the VirtualHost directive (<VirtualHost FQDN:80>). In fact this is seen as <VirtualHost 127.0.0.1:80>

What happens is your case is documented in the VirtualHost doc, last 2 paragraphs (just before "Security"), quoted:

When a request is received, the server first maps it to the best
matching based on the local IP address and port
combination only. Non-wildcards have a higher precedence. If no match
based on IP and port occurs at all, the "main" server configuration is
used.

If multiple virtual hosts contain the best matching IP address and
port, the server selects from these virtual hosts the best match based
on the requested hostname. If no matching name-based virtual host is
found, then the first listed virtual host that matched the IP address
will be used
. As a consequence, the first listed virtual host for a
given IP address and port combination is the default virtual host for
that IP and port combination.

So when you ask for localhost/somedir, the server will try to find from the non-wildcards VHosts declarations, but do not find any with corresponding host name (ServerName), and so it chooses as "default" the first VHost with IP:Port, and not the first with *:Port.

To solve your problem, try to use <VirtualHost *:80> in all three vhost declarations :

<VirtualHost *:80>
DocumentRoot "c:/wamp/www/"
ServerName localhost
ServerAlias *.localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias *.laravel.dev
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "c:/wamp/www/learningLaravel/public"
ServerName learningLaravel.dev
ServerAlias *.learningLaravel.dev
</VirtualHost>

And reload / restart Apache.

(My only doubt about this is why Nasreddine could make a working test case with your setup.)

Virtual hosts not working properly in ubuntu LAMP stack

Make sure your rewrite mod is enabled.

or simply run this in terminal

$ sudo a2enmod rewrite

$ sudo systemctl reload apache2

PHP not running in VirtualHost on Apache

Hi Miro,

did you consider to SWITCH from MPM-EVENT to MPM-PREFORK, in order to be able to USE the libapache2 - PHP - module ?

LoadModule php5_module  /usr/lib64/httpd/modules/libphp5.so
#Error: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.

=> HOME > Tools & Settings > Apache Web Server > ( option ) MPM mode

php files aren't parsed for virtual hosts

Most likely you don't have short_open_tag enabled in php.ini, more information here:

http://php.net/manual/en/ini.core.php#ini.short-open-tag

Or better yet, use <?php instead of <?.



Related Topics



Leave a reply



Submit