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
Related
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
I have been messing around with apache in the terminal on macOS Catalina 10.15.4. I was following tutorial & tutorial2. I got everything working, up to a point. The localhost displays just fine and I can add html websites to the default domain and they load perfectly. My issues are:
PHP is not parsing from default apache folder. Just displays code in browswer.
I have tried editing the document root in httpd.conf, but nothing changes
I have tried to undo most of what I have done so far, but now I am getting this error:
'Set the 'ServerName' directive globally to suppress this message'
Any advice?
Is there a way to reset all apache's settings to their default values?
make certain that in your /usr/local/etc/http/httpd.conf you have something like:
LoadModule php7_module /usr/local/opt/php#7.2/lib/httpd/modules/libphp7.so
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
ymmv. I am assuming you brewed in apache, and you have php installed.
This works on mojave, with apache and php7.2 brewed. Adapt to your own setup. Never wanted ever to downgrade to catalina, so i dunno how the apple and brew crews mangled the configurations, but should be close.
Im running USBWebserver v8.6 on a USB drive on a windows 10 machine, I need to update PHP to run Mautic and it requires PHP version 5.6.19 while my USB server has PHP Version 5.4.17. I tried to download windows version and extract it to the PHP folder on the drive and did a restart on the web server but that did not work.
I don't know how to update the PHP please help.
Did you change the httpd.conf file in the Settings folder?
Almost at the end of that file there are these lines:
# For PHP 5 do something like this:
LoadModule php5_module "{path}/php/php5apache2_4.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# configure the path to php.ini
PHPIniDir "{path}/php"
Change these values according the PHP installation you want. Let me know if this works for you. I got this information from the documentation on how to install PHP.
I am using Apache 2.2.3 server on RHEL5. In my system, php is installed (PHP 5.1.6). I placed a simple php script
<?php
phpinfo();
?>
in my /var/www. However, when I start my server (it starts fine) and go to the php page, it does not show anything. My local machine has ubuntu installed, where I can see the file properly.
Following the information provided here (http://dan.drydog.com/apache2php.html), I did following things:
Added following lines to /etc/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script .php
AddType text/html .php
AddType application/x-httpd-php-source phps
restarted httpd,
service httpd restart
But I still don't see any results. What am I doing wrong?
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)