PHP Version Doesn't Change After Adding AddHandler - php

I am trying to get one of my sites on my server to use PHP 7.3. I have added this to my .htaccess file:
AddHandler application/x-httpd-php73 .php
It is the only line in that file. My directives of the root of the site look like this:
<Directory "/var/www/html/dev">
allow from all
AllowOverride All
Require all granted
</Directory>
Whenever I run my phpInfo script, it is still reporting PHP 7.0. What am I missing?

Related

Netbeans lamp php interpereter not working

I am following this netbean guide https://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html#createDocumentRootLocation
But I am stuck at creating the virtual host. I try to do as in the tutorial but there is no <Directory> tags in the "000-default.conf" file. I kept going and ignored that.
I did as in the tutorial and put it in my /home/user/public_html. but now when I run it the php code is not interpreted
If I a2ensite the default I can access virtual host set at /var/www/html and that php is interpreted
There are no errors the php is just not being interpreted, what am I doing wrong here.
Im using:
Ubuntu 18.10 LTS
PHP 7.2.10-0ubuntu1 (cli)
Apache/2.4.34
Edit:
My "TestPhp.conf" file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/jelly/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit 2 and answer:
Turned out to be some lines in my "php7.2.conf" file that had to be commented out as the out-commented lines in that file explains. as running PHP scripts in user directories is disabled by default.
what is your test script like? if you start with <? try <?php instead.
Also check php.ini for expose_php = false (may hide php form the headers)
If the error persists, include your config and test script, along with any errors in http.log
You need to find a config file which enables php
I only have a Ubuntu, and the files in my installation may vary compared to yours:
Enable PHP engine [php.load]
This is the part that loads the PHP interpreter, and allows you to use php scripts
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Enable .php file directed to php [php5.conf]
This is the part tells apache to send *.php (and in this case some other extensions like *.phtml) to the php interpreter
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Require all denied
</FilesMatch>
EDIT I noticed that you were on UBUNTU as well
use sudo a2enmod and select php in the list
EDIT 2
Note that if you are following a general Guide and not a UBUNTU specific one, you may encounter several issues since the UBUNTU apache config is spread out in several files, as opposed to one big file, which is what you may encounter in other distros

Apache: How to run php files as CGI

How to run php as CGI in wampserver.
I want to run php files in this directory c:/wamp64/www as cgi.
I try to run cgi by following config:
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler cgi-script .php
Require local
</Directory>
but displays in error logs:
malformed header from script 'index.php': Bad header: Security Alert! The PHP
How can i solve this problem and run php files as cgi?

.htaccess not read on localhost xampp

I have a problem with a .htaccess file not being read by Apache. I'm using it on my local machine, port 81. I'm using Windows 10.
I created a .htaccess file in the root directory of my .php files.
When I enter some rubbish inside .htaccess file nothing happens (website loads normally). I've checked many tutorials, threads and was unable to find a viable solution.
What I have done so far:
Entered anything in the .htaccess file to check or the 500 error (didn't work)
Checked the httpd.conf file for AllowOverride All (for directory as well)
Re-installed Xampp
This is how my settings in httpd.conf look like now:
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
<Directory />
AllowOverride All
# Require all denied
</Directory>
I've got no idea what to do next. Any ideas?
Is this section in httpd.con like this, or is looking for any other file name?
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess

ubuntu server 12.04 - php files downloading

hoping someone can help me, i am having the same problem with the php files trying to download.
i have tried all answers but the:
ln -s /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php5.conf ln -s /etc/apache2/mods-available/php5.load /etc/apache2/mods-enabled/php5.load
when i try them i get unable to create symbolic link file exists, so i guess thats done all ready, anyone else have anything more i can try, i am new to linux and i followed this guide to set everything up: http://www.howtoforge.com/perfect-server-ubuntu-12.04-lts-apache2-bind-dovecot-ispconfig-3
the strange thing is joomla and drupal sites work, but own php script doesent.
i have tried everything on this page:
apache2 on ubuntu - php files downloading
but none of them work.
when i try to run this command: sudo a2enmod php
i get, module php does not exist. i guess i need to run a command to install it? if so what is it please.
thanks all.
Heres More info as requested:
not sure where isp config stores the folders for each website, but i connected to the ftp site and uploaded into the web folder, same as i did for the working drupal and joomla sites that are working
sites enabled:
/
000-apps.vhost#
000-default#
000-ispconfig.conf#
000-ispconfig.vhost#
100-analytics.cyberglide.co.uk.vhost#
100-cyberglide.co.uk.vhost#
100-hideandcollars.co.uk.vhost#
100-jubileeleather.co.uk.vhost#
100-rookselectrical.co.uk.vhost#
100-wolds-uniforms.co.uk.vhost#
all sites are working (they are running joomla or drupal) but www.jubileeleather.co.uk/index.php
had to put up a html file until i can get it sorted.
php script:
<?php
//Add required class and config files below
require ('_class/cms.php');
require ('config/db.php');
//Get Required Page, if its not set call it the index
$page = (isset($_GET['page'])) ? $_GET['page'] : 'index';
//If the page is set as index
if($page == 'index'){
//Include Index
require ('public/index.php');
}
//Else if the page is contact
elseif ($page == 'contact') {
//Include Contact
require ('public/contact.php');
//If the page is none of the above
} else {
//Include Layout
require ('public/layout.php');
}
?>
i am using putty via ssh, how would i copy content from a file to post on here? also which files would you need? thanks again.
here is the contents of the jubileeleather v host file, not sure what i am looking for in here:
AllowOverride None
Order Deny,Allow
Deny from all
DocumentRoot /var/www/jubileeleather.co.uk/web
ServerName jubileeleather.co.uk
ServerAlias www.jubileeleather.co.uk
ServerAdmin webmaster#jubileeleather.co.uk
ErrorLog /var/log/ispconfig/httpd/jubileeleather.co.uk/error.log
Alias /error/ "/var/www/jubileeleather.co.uk/web/error/"
ErrorDocument 400 /error/400.html
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/405.html
ErrorDocument 500 /error/500.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
<IfModule mod_ssl.c>
</IfModule>
<Directory /var/www/jubileeleather.co.uk/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/clients/client3/web4/web>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# suexec enabled
<IfModule mod_suexec.c>
SuexecUserGroup web4 client3
</IfModule>
# Clear PHP settings of this website
<FilesMatch "\.ph(p3?|tml)$">
SetHandler None
</FilesMatch>
# php as fast-cgi enabled
# For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
<IfModule mod_fcgid.c>
IdleTimeout 300
ProcessLifeTime 3600
# MaxProcessCount 1000
DefaultMinClassProcessCount 0
DefaultMaxClassProcessCount 100
IPCConnectTimeout 3
IPCCommTimeout 360
BusyTimeout 300
</IfModule>
<Directory /var/www/jubileeleather.co.uk/web>
AddHandler fcgid-script .php .php3 .php4 .php5
FCGIWrapper /var/www/php-fcgi-scripts/web4/.php-fcgi-starter .php
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/clients/client3/web4/web>
AddHandler fcgid-script .php .php3 .php4 .php5
FCGIWrapper /var/www/php-fcgi-scripts/web4/.php-fcgi-starter .php
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# add support for apache mpm_itk
<IfModule mpm_itk_module>
AssignUserId web4 client3
</IfModule>
<IfModule mod_dav_fs.c>
# Do not execute PHP files in webdav directory
<Directory /var/www/clients/client3/web4/webdav>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler None
</FilesMatch>
</Directory>
DavLockDB /var/www/clients/client3/web4/tmp/DavLock
# DO NOT REMOVE THE COMMENTS!
# IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
# WEBDAV BEGIN
# WEBDAV END
</IfModule>
Apart from having the own PHP files in a directory with PHP parsing enabled (can't really say how it's done with Apache as I'm not using for some time), you should check if your script has the correct extension (should be always .php) and script opening tag <?php - don't use short tag <? to avoid possible problems when moving the script to live server.
Tho since your files are returned for download, I think you don't have your scripts in directory with enabled PHP parsing. Posting your Apache and PHP config files could help us to identify the problem.

Execute custom filename with PHP (via Apache)

On my development machine, this works as expected (requests to server.com/.myhandler are executed as php), but when I uploaded to the production machine (running ubuntu server 11.04) it just serves the un-executed php. Is there anything extra I must configure for this to work?
Contents of .htaccess file:
AddType text/html .myhandler
<FilesMatch "\.myhandler$">
SetHandler application/x-httpd-php
</FilesMatch>
DirectoryIndex .myhandler index.php index.htm
Most possibly this type of configuration is not allowed via .htaccess in the directory where your script and .htaccess reside in. Put this in your Apache site / VirtualHost configuration:
<Directory /absolute/path/to/webroot/>
AllowOverride All
</Directory>

Categories