I have a fresh install of CentOS (latest 8 and Stream 9) and I did this do install PHP and Apache:
dnf install httpd php
Everything works fine and PHP files are being interpreted correctly.
I realized there is a file at /etc/httpd/conf.modules.d/20-php.conf that loads PHP inside Apache using a line like:
LoadModule php_module modules/libphp.so
Great! But I cant find anywhere else a code like AddHandler xxxx php. On all the previous times I installed PHP+Apache there always would be a line to load php using AddHandler.
I am asking this because I want to allow PHP to be interepreted in my entire server HOWEVER I dont want PHP to be interpreted if the user access any directory with name dont_interpret_php. In this case, if there is a PHP file inside this directory, it should be server by Apache as is, without interpreting its content.
I found some ways on Google to do that but all of them require modifying the line AddHandler but I cant find it anywhere (not in httpd.conf, not in virtualhosts file... no where!).
Thank you so much!
Here's a fragment from one of my configurations (Apache/2.4.25):
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
Try grep -R php in your /etc/APACHE_CONFIG_DIR
Related
I've been trying to get PHP working locally on my machine in Fedora 26.
I have httpd installed, and that seems to be working. When I first had it set up, typing localhost in my browser showed me the HTML contents /var/www/html/index.html, but not the PHP contents. <?php phpinfo(); ?> was not working, either.
I think PHP is also working, since php -r "phpinfo();" works in the command line.
I tried following the advice in this thread by adding AddType application/x-httpd-php .php to my httpd.conf file, and this made my browser try to download the PHP files instead of displaying them. Weirdly, when I took this line back out and restarted httpd, my browser is still trying to download the files.
First of all add php AddType to to httpd.conf file:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
And then load php module in apache configuration based on your php version that installed on your machine and you wanted to use:
LoadModule php7_module modules/libphp7.0.so
I am setting up a test server before upgrading an elderly version of mediawiki on a production server. I am trying to duplicate what will be on the production server - apache2.4 and php5.3.
When I try to access any php file, the server displays it as text rather than running it.
This is all running on Ubuntu 12.04 LTS. The apache package available is version 2.2, so I can't simply apt-get.
I have built apache 2.4 from source, and it correctly serves an index.html from my designated DocumentRoot.
In httpd.conf, I have added:
DocumentRoot = /var/www
AddType application/x-httpd-php .php
<filesMatch>"\.php$:"
SetHandler application/x-httpd-php .php
</filesMatch>
I have installed php5.3, and it is working - I can run phpinfo.php from a command line.
In /etc/php5/apache2/php.ini I have (error displays are for testing only):
engine = On
display_errors = On
display_startup_errors = On
doc_root = /var/www
I am not able to find a reference to a mod_php of any sort either in the httpd.conf or in the directory in which httpd is installed (/usr/local/apache2).
Some of the references on the web mention "modules-available" and "modules-enabled" but these appear to be a convenience added by Debian, and are not part of the apache source build.
What am I missing? I'm sure it's something simple.
After searching and using packages from several repositories for both apache and php, and trying to build either or both from source, I determined that there did not seem to be a libphp5.so that was compatible with apache 2.4. In any case, I didn't find it.
I reconfigured everything to use php as cgi rather than as a module, and got things working that way, which was enough for my intended purpose.
You need to load php module in httpd.conf:
On my Linux Slackware I have this in /etc/httpd/mod_php.conf
LoadModule php5_module lib/httpd/modules/libphp5.so
# Tell Apache to feed all *.php files through PHP. If you'd like to
# parse PHP embedded in files with different extensions, comment out
# these lines and see the example below.
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
And in /etc/httpd/httpd.conf:
# php
Include /etc/httpd/mod_php.conf
So I've installed LAMP on an Ubuntu machine for some php development and everything is working fine except instead of parsing and displaying php pages, the browser is asking me if I want to download them. I know this is a well documented issue, and I've already been to the Ubuntu page concerning it, and gone through all the potential causes. I've installed libapache2-mod-php5 and upon running sudo a2enmod php5 I get module php5 already enabled. So I think I've pretty much narrowed the problem down to a php file authorizations issue.
Now I should point out that this only happened after I modified the config file to allow a UserDir in my /home/public_html. With the default configuration in folder /var/www php files parsed just fine, and still do, so long as I gave myself root access or modify their permisssions. And I didn't change anything else in the config file.
So, my question is, how do I check/modify the php authorization files? Where are they? What exactly do I check? I can't seem to find any good info on this.
Try an installation of:
sudo apt-get install php5 libapache2-mod-php5
Then restart the service..
/etc/init.d/apache2 restart
or if using httpd:
/etc/init.d/httpd restart
Then let me know how that goes.
So I figured this out with some really tedious searching, I'm surprised the solution is not more widely available, it's really very simple. The /etc/apache2/mods-available/php5.conf file comes with these lines.....
8 # To re-enable php in user directories comment the following lines
9 # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
10 # prevents .htaccess files from disabling it.
11 <IfModule mod_userdir.c>
12 <Directory /home/*/public_html>
13 php_admin_value engine Off
14 </Directory>
15 </IfModule>
...which obviously disable php in user directories. These need to be commented out.
This solved my problem, but I just couldn't figure out why:
AddType application/x-httpd-php .php
I added the above in the /etc/httpd/conf/httpd.conf
My problem arose right when I edited the httpd.conf to configure
I'm on Centos 7 running PHP 7.0.
I had to load the PHP 7 module in my /etc/httpd/conf/httpd.conf file.
LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
As always, remember to sudo service httpd restart after making changes to apache
I want to install dompdf, and so I need PHP, and consequently Apache (for instance) installed. I've managed to install Apache 2.0.64 on my Windows 7 64 bit. It was apparently working fine, until I've installed PHP 5.4.9 and configured httpd.conf, so Apache could "see" the PHP installation. I've been using this link for guidance on that -> http://www.webdevelopersnotes.com/how-do-i/install-PHP-windows-7.php After that, when I try to start Apache2 the "The requested operation has failed!" error pop-up appears. If I comment the lines that I've inserted into httpd.conf, Apache works again. The lines are:
AddType application/x-httpd-php .php
(...)
LoadModule php5_module "c:/Program Files (x86)/php_5.4.9/php5.dll"
(...)
PHPIniDir "C:/Program Files (x86)/php_5.4.9"
I've spent a lot of hours and searched but couldn't find a similar problem to mine nor a solution of my own. Does anybody has a hint on this?
Thank you very much,
João
This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 7 years ago.
I've been writing PHP applications using PHP for a while in WAMP. Now I'm installing PHP and Apache HTTP Server separately on my work PC. I've installed PHP 5, and the latest Apache. I go to localhost and see it works!
Now I add a file called test.php which displays:
<?php
phpinfo();
?>
But in the browser it just displays plain text. Is there somewhere I have explicitly tell it to use PHP 5?
You should install the PHP 5 library for Apache.
For Debian and Ubuntu:
apt-get install libapache2-mod-php5
And restart the Apache:
service apache2 restart
You'll need to add this to your server configuration:
AddType application/x-httpd-php .php
That is assuming you have installed PHP properly, which may not be the case since it doesn't work where it normally would immediately after installing.
It is entirely possible that you'll also have to add the php .so/.dll file to your Apache configuration using a LoadModule directive (usually in httpd.conf).
Yet another reason (not for this case, but maybe it'll save some nerves for someone) is that in PHP 5.5 short open tags <? phpinfo(); ?> are disabled by default.
So the PHP interpreter would process code within short tags as plain text. In previous versions PHP this feature was enable by default. So the new behaviour can be a little bit mysterious.
You need to configure Apache (the webserver) to process PHP scripts as PHP. Check Apache's configuration. You need to load the module (the path may differ on your system):
LoadModule php5_module "c:/php/php5apache.dll"
And you also need to tell Apache what to process with PHP:
AddType application/x-httpd-php .php
See the documentation for more details.
You might also, like me, have installed php-cgi prior to installing Apache and when doing so it doesn't set up Apache properly to run PHP, removing PHP entirely and reinstalling seemed to fix my problem.
You will need to add handlers in Apache to handle php code.
Edit by command sudo vi /etc/httpd/conf/httpd.conf
Add these two handlers
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
at position specified below
<IfModule mime_module>
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
--Add Here--
</IfModule>
for more details on AddType handlers
http://httpd.apache.org/docs/2.2/mod/mod_mime.html
Are you using the userdir mod?
In that case the thing is that PHP5 seems to be disabling running scripts from that location by default and you have to comment out the following lines:
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
in /etc/apache2/mods-enabled/php5.conf (on a ubuntu system)