Apache, Apache Default folder, Apache PHP not parsing - php

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.

Related

Apache 2.2 not loading PHP 5.5 module

There are several questions about this out there, but I have exhausted all fixes and this still doesn't work.
I'm using Windows 7 OS (stupid, I know).
Basically I downloaded PHP 5.2.5 and installed with VC6 (there were some issues with VC9 and up not working with Apache 2.2). I edited the php.ini file to have the following additions:
extension_dir = "C:/php/ext/"
extension = php5apache2_2.dll
extension = php5ts.dll
I then added the php5apache2_2.dll and php5ts.dll files into the C:/php/ext/ directory. These did not come with the PHP download...I had to find them at random places online. Could that be an issue?
The first extension is the PHP module for Apache 2.2. The next one is something I found on a couple of blog posts that sometimes isn't there and needs to be added for PHP to work with Apache.
In the Apache 2.2 httpd.conf file, I added:
LoadModule php5_module "C:/php/ext/php5apache2_2.dll"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
PHPIniDir "C:/php/"
These are all in the appropriate places, etc. I also set the DirectoryIndex to include index.php
Yes, everything is at the right path/in the right folder.
When I restart Apache, it will never restart unless I comment out the PHPIniDir line. The error log I get is:
Invalid command 'PHPIniDir', perhaps misspelled or defined by a module not included in the server configuration
I'm starting to get a bit lost with all of the supposed "fixes" out there and am afraid of getting in over my head and screwing up my computer (some of the suggestions involve pasting stuff in the system32 folder, etc.).
Can anyone help??
Delete last slash from below line:
PHPIniDir "C:/php/"

apache2.4 build not finding php5.3

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

Apache won't parse php page

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

Apache with passenger and php modules, not executing php

I have a rails setup which is served by Apache Passenger, there are 2 apps on the server which are served by passenger and all was working fine. I then wanted to install wordpress on the same server and so I installed the required packages "php5 php5-mysql libapache2-mod-php" and setup a separate vhost for wordpress, when I try to run the wordpress index.php file, apache doesn't execute but rather offers me to download.
I have googled this to no resolution, this problem is pretty common but none of the solutions have worked for me. Solutions that I have tried:
Adding "AddType application/x-httpd-php .php" in apache2.conf
making the wordpress directory executable, also changed the owner of the directory to www-data
In the vhost of wordpress, disabled Passenger by setting PassengerEnabled Off in the Directory directive.
Verified that php module is loaded by apache2ctl -M
Checked error log and nothing there, enabled error log for that vhost but nothing there.
any pointers, help appreciated thanks. BTW, the same setup works on local development box, its just this instance being painful can't recreate things from scratch.
Do you have a handler for the *.php extension?
My handler looks like this (with type included for clarity):
AddHandler php5-script .php
AddType text/html .php
Or from the documentation:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
How did you enable the php module, did you use a2enmod or did you add it by hand?
Try removing the extra "AddType application/x-httpd-php .php" in apache2.conf and then run
sudo a2dismod php5; sudo a2enmod php5; sudo service apache2 restart
If you have already done that, please provide the contents of php5.conf, vhost file and everything else you believe is relative.

Why are my PHP files showing as plain text? [duplicate]

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)

Categories