apache2.4 build not finding php5.3 - php

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

Related

Cant find AddHandler of PHP inside Apache configuration files

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

Centos config php on apache server

I'm using a stand alone server (Not connected to the internet) which contains Apache server (httpd service) and php version 5.5 (installed with ./configure, make & make install).
This 2 applications were installed separately.
How can I config my Apache server to work with that php?
Unfortunately I can't use yum.
Thanks.
You have apache and php already installed on your server. So you just need to configure apache to work with PHP.
Configure Apache to run PHP as a Module
Add the following line in httpd.conf file if it's not already there,
LoadModule php5_module modules/libphp5.so
Tell Apache to parse certain extensions as PHP
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
And restart apache (httpd) server,
service httpd restart
refer php.net for more details.

How to update PCRE in CENTOS/Redhat 6

For installing Scribunto, a Mediawiki add ins, it requires at least PCRE version 8.1. But in CENTOS update, the maximum version is 7.8.
I compiled the source code version 8.33 successfully and with "pcretest -C" command, it is already version 8.33. But the phpinfo() has still the old PCRE 7.8.
How to point PCRE in php to the newest version?
Sigh.
I feel ya.
I can tell you that what finally worked for me was building PCRE from source and using FastCGI (the mod_fcgid package in CentOS 6) with a stanza like this in /etc/httpd/conf.d/php.conf:
<IfModule fcgid_module>
SetEnv LD_PRELOAD /usr/local/lib/libpcre.so.1
ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/
AddType application/x-httpd-fastphp .php
Action application/x-httpd-fastphp /fcgi-bin/php-cgi
<Directory /var/www/fcgi-bin/>
# Allows /usr/bin/php-cgi to be symlinked here
Options +FollowSymLinks
</Directory>
</IfModule>
Here are a list of things I tried with the default "modular" PHP setup (php5_module) before giving up and resorting to FastCGI.
PassEnv LD_PRELOAD with LD_PRELOAD=/usr/local/lib/libpcre.so.1 defined in /etc/sysconfig/httpd.
SetEnv LD_PRELOAD /usr/local/lib/libpcre.so.1
LoadFile /usr/local/lib/libpcre.so.1
However, I was putting these directives inside VirtualHost sections, generally, so I won't rule out the possibility that order was the problem. That is, it's entirely possible that these directives would need to come before the PHP module was loaded, and I wasn't doing that. I was using an /etc/httpd/conf.d/php.conf and a vhosts.conf and generally trying not to sully the top-level config file while I was experimenting.
Eventually I ran out of patience and tried going the FCGI route, and that worked for me. If you're married to running PHP as a loadable module, then you may wish to try some of the above options with things like LoadFile specified in httpd.conf before the PHP DSO is loaded.

Apache/PHP on Windows 8

I'm having trouble with Apache/PHP on Windows 8. I have previously been using them on XP (along with MySQL) with no problems. I never used Windows 7.
Apache installs without issues. Everything works OK, including all my virtual servers.
PHP installs OK, the installation puts entries into httpd.conf without giving errors.
However, when I try to load Apache after installing PHP, Apache won't load.
I'm confused by the error that Apache returns when the PHP entries are included in httpd.conf:
Syntax error on line 1029 of C:/Program Files/Apache Group/Apache2/conf/httpd.conf:
Cannot load C:/Program Files/PHP/php5apache2_2.dll into server: The specified module could not be found.
The lines are:
#BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
PHPIniDir "C:\Program Files\PHP\"
LoadModule php5_module "C:\Program Files\PHP\php5apache2_2.dll"
#END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL
(line 1029 is the LoadModule line).
That location for the dll is definitely correct. The syntax of the line is as inserted by PHP. I have compared the syntax to previous versions of httpd.conf that I have and it appears correct. I think the syntax error is a red herring.
I have tried:
Switching backslashes to slashes in the dll location.
Adding PHP to the path.
Installing Apache and PHP in both sequences.
Checking the permissions to the PHP folder and the individual files
to ensure that SYSTEM has read/execute.
Comment out the PHP lines and Apache loads fine. If I comment out the LoadModule line and and just leave the PHPIniDir line, it still fails. Apache seems to be behaving as though it can't see the PHP directory, but I can't work out why.
There is nothing on the Windows event log. Latest versions of PHP and Apache. I'm at a bit of a loss what to try next. Any suggestions please?
Download and follow instructions from this link:
http://www.apachelounge.com/download/
The latest download (2.4) works on Windows 8 and Server 2012.
I downloaded and tested with the following on Windows 8:
Each zip has a readme.txt or install.txt with instructions.
Apache 2.4
http://www.apachelounge.com/download/win32/binaries/httpd-2.4.3-win32.zip
PHP 5.4.8
http://windows.php.net/downloads/releases/php-5.4.8-Win32-VC9-x86.zip
PHP 5.4.8 handler for Apache
http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip
My httpd.conf lines that were added/modified were:
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module "C:/Apache24/php-5.4.8/php5apache2_4.dll"
LoadFile "C:/Apache24/php-5.4.8/php5ts.dll"
PHPIniDir "C:/Apache24/php-5.4.8"
<IfModule php5_module>
<Location />
AddType text/html .php
AddHandler application/x-httpd-php .php
#AddHandler application/x-httpd-php-source .phps
</Location>
</IfModule>
Its mentioned in the Readme.txt file packed with the dll's at ApacheLounge, but not anywhere else on the download page or in the filename (as all other versions):
"Runs with PHP 5.4 Thread Safe (TS), and only with Apache 2.4 Win32 VC9 or VC10"
The dlls are only for the TS version, so if you've downloaded the other one, you are basically screwed. TS php binaries fixed it for me.
GL.
Presuming this is your development, not deployment environment, why don't you just download xampp from apache friends? It should come preconfigured, and you will deploy in other setup anyway.
I ran into the similar issue when reinstalling Apache and PHP on Win 8 (I am more Linux user though). And similar to the original post, no matter what I tried to do in httpd.conf and php.ini Apache simply either did not start or did not see the PHP. After spending unreasonable amount of time, I decided to download the PHP 5.3 (5.3.27)-VC9 x86 Thread Safe (2013-Jul-10 21:56:58) Installer [45.86MB] instead of the non-tread safe version which I have been using before. There is a difference in the .msi installers. The one for the thread-safe version actually contains the required files and if you follow the installer prompts it will actually asks you if the php installation should be "linked" to Apache server. Then you just provide the hhtpd.conf directory and all works fine. Thats my 2c on this :)
I think the problem is in the blank "Program Files".

How to configure PHP under Apache web server in GENTOO Operating System?

is there anyone who knows how to install / configure php under apache?
I have emerge php apache both.
I wanted to use mod_php for apache in GENTOO OS.
php temp.php
command line runs fine, but http://localhost/temp.php is not executing on web server instead it shows the content of the php code.
I found a blog and I followed his instruction and it works !
I'm sharing the solution Referenced Blog
I put these lines in /etc/make.conf:
USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png"
If you want to install also phpmyadmin, then you should also add pcre session unicode:
USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png pcre session unicode"
I then changed the file /etc/init.d/apache2, in order to enable public_html folders for users (corresponding to the ~ directory), setting -D USERDIR:
APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5 -D USERDIR
Before starting mysql, you must create (once and for all) the mysql main database, and this can be done simply by running:
/usr/bin/mysql_install_db
There appear to be a number of ways to achieve this but many seem a bit out of date or overly complicated. As of Feb 1 2010 all I did to get PHP and Apache2 working on Gentoo was to install Apache and PHP like this:
bash$ emerge apache
Followed the instructions for the particular extensions I wanted at this list at the Gentoo site
NOTE: this is the important one to get Apache and PHP working together:
bash$ echo "dev-lang/php apache2" >> /etc/portage/package.use
Another common PHP extension:
bash$ echo "dev-lang/php mysql" >> /etc/portage/package.use
And so on.
Then just run bash$ emerge dev-lang/php and restart Apache with the /etc/init.d/apache2 script. PHP should now be available.
You may find some informations in Apache 2.0 on Unix systems
Especially, the
LoadModule php5_module modules/libphp5.so
and
SetHandler application/x-httpd-php
Lines should help :-)
The corresponding lines I have in my Apache's configuration (Apache 2, PHP 5.2, Ubuntu) are :
LoadModule php5_module /usr/lib/apache2/modules/libphp-5.2.9.so
<IfModule mod_php5.c>
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
</IfModule>
above link dead, try this one:
http://overlays.gentoo.org/proj/php/
Try to use official GENTOO documentation:
http://www.gentoo.org/proj/en/php/php4-php5-configuration.xml

Categories