PHP doesn't work on Apache virtual host
Solution 1
For the record, the problem was Plesk.
Probably there was some problem with the manual installation of PHP 5 from Webtatic. After that any new subdomain created with Plesk have in their Apache configuration php_admin_flag engine off
.
It was difficult to find where they are because Plesk creates one configuration file for every [sub]domain in a conf
subdir of the domain directory and include them in httpd.conf
. That is a good practice, but hard to find and you can't personalize it easily if you want to do something different from GUI options (if you change something via GUI the old conf file will be not modified, but a new one will be created and you have to reapply all your modifications).
Solution 2
If it's default installation (httpd, php packages), nothing changed, then it should be a php.ini issue with short_open_tag - php will parse files with .php extension, but ignore content if it doesn't start with <?php
.
Related videos on Youtube
Marco Sulla
Updated on September 18, 2022Comments
-
Marco Sulla over 1 year
I have a virtual private server with Parallels Power Panel on CentOS 6. The default Apache virtual host (accessed using the IP) works wihtout any problem.
Now I created a new domain with Plesk and copied the files in the virtual host directory. Unfortunately PHP scripts doesn't work - you can access them, but they are not prepocessed. PHP module is working since the default virtual host is still working.
I tried to modify the httpd.conf (here is the full file) adding the NameVirtualHost directive and a VirtualHost section without success. This is the section I added:
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin admin@###.com DocumentRoot /var/www/vhosts/###.com/httpdocs/ ServerName www.###.com ServerAlias ###.com ErrorLog /var/log/httpd/###.com/error.log CustomLog /var/log/httpd/###.com/access.log common <Directory "/var/www/vhosts/###.com/httpdocs/"> Options Indexes FollowSymLinks Includes MultiViews ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
and this is my php.conf (in conf.d):
<IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> AddHandler php5-script .php DirectoryIndex index.php AddType application/x-httpd-php-source .phps AddType application/x-httpd-php .php
-
Phil Sturgeon almost 11 yearsWhen you say "you can access them, but they are not pre-processed", do you mean that you see the source code as plain text?
-
Marco Sulla almost 11 years@PhilSturgeon: yes, the browser tries to download the php file, and stop.
-
Phil Sturgeon almost 11 yearsI answered with a bit more info.
-
-
Marco Sulla almost 11 yearsThank you, but all the configuration in step 11 are already present in conf.d/php.conf (I added the code to the question).
-
Phil Sturgeon almost 11 yearsTry this? stackoverflow.com/questions/6245895/…
-
Marco Sulla almost 11 yearsThe default virtual host is working well... read the first part of my question ;)
-
Phil Sturgeon almost 11 yearsI read that, I suggest you read some of the answers. If Apache is serving up PHP files as plain text downloads then you probably dont have mod_php set up properly.
-
Marco Sulla almost 11 yearsSorry, I only read the first answer to your linked question. Anyway PHP is installed, I restart the
httpd
service every time I modify any configuration files, I do not have aphp_admin_value
rule and on CentOS there's onlyconf.d
, notmods-enabled
etc... :( -
Marco Sulla almost 11 yearsCould the problem be related to domain migration? I have bought the domain and hosting space from a provider, and now I migrated the hosting to another provider but I maintained the domain, I simply modified the DNS entries. I must add I'm sure the domain is redirected to the IP of the new hosting server.
-
Phil Sturgeon almost 11 yearsNope. DNS gets things to the server, the server passes the traffic to Apache. Apache is trying to handle PHP. The Apache -> PHP handoff is fucked, so you need to fix that.
-
Marco Sulla almost 11 yearsThank you for your answer, but I do not use short tags. I do not know if apache configuration is the default one, since I'm using a virtual server with CentOS, Plesk and some basic packages preinstalled by my cheap but lacking provider.