PHP in userdir not working - php

My /etc/apache2/mods-enabled/userdir.conf file looks like:
<IfModule mod_userdir.c>
UserDir /var/zpanel/hostdata/*/public_html/
UserDir disabled root
<Directory /var/zpanel/hostdata/*/public_html/*>
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch
<Limit GET POST OPTIONS>
# Apache <= 2.2:
Order allow,deny
Allow from all
# Apache >= 2.4:
# Require all granted
</Limit>
<LimitExcept GET POST OPTIONS>
# Apache <= 2.2:
Order deny,allow
Deny from all
# Apache >= 2.4:
#Require all denied
</LimitExcept>
</Directory>
</IfModule>
And file /etc/apache2/mods-enabled/php5.conf
<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>
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /var/zpanel/hostdata/*/public_html/*>
# php_admin_value engine On
# </Directory>
#</IfModule>
But php not working when in accessing web site via userdir.
www.example.com/~admin
When i access via domain then it works. I have zPanel installed
Server version: Apache/2.4.18 (Ubuntu)

In my /etc/apache2/mods-available/php7.0.conf I have this section
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
I think now you know what to do.

Try the following actions:
Make sure mod_userdir is enabled (a2enmod userdir).
The $HOME and public_html dirs have the right read permissions.
sudo -Hu SOMEUSER sh -c 'chmod 755 $HOME $HOME/public_html'
Make sure php_admin_value engine is On.
sudo vim /etc/apache2/mods-enabled/php*.conf
Then find the line containing php_admin_flag and change it to:
php_admin_flag engine On
This is due that PHP is disabled by default for user dirs for Apache 2.
In your particular case, you've to uncomment the following lines:
<IfModule mod_userdir.c>
<Directory /var/zpanel/hostdata/*/public_html/*>
php_admin_value engine On
</Directory>
</IfModule>

As mention by #kenorb, this is because PHP is disabled php_admin_value engine Off by default in userdirs for Apache2.
But instead of changing the php_admin_value engine to On in /etc/apache2/mods-enabled/php*.conf, it is advised in the .conf file itself that the lines starting from <IfModule> to </IfModule> be commented out, so that .htaccess can handle the setting separately. This can be done as shown below:
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>

Related

Unable to use multiple php versions in xampp

I have php 7.4 by default in my xampp (in the path c:\xampp\php) and my most projects are running on it.Now, I've a php 8 project & so need to run xampp with php 8.1 on a different port(8056).I tried doing it with the answer mentioned in this link:
How to use Multiple xampp Like xampp php version 5, xampp php version 7, version 8. I also install it but problem new laravel project npm not install
Although the new port (8056) is also getting listed under ports in Xampp control panel, not able to load xampp with it.When running http://localhost:8056/ , am getting the error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at postmaster#localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.52 (Win64) OpenSSL/1.1.1m PHP/7.4.27 Server at localhost Port 8056
In the last line of this error,it seems it is still running on php.7.4 . I wanted only php 8.1 to listen on this port. How can I fix this? Any help is much appreciated.
Steps I did:
1.downloaded php 8(non thread safe version) & extracted file to the path c:\xampp\php8
2.As the php.ini file does not exists in the path c:\xampp\php8, created a new text file & named it php.ini.Copied the contents in php.ini-development to php.ini and uncommented the line
extension_dir = "ext"
3.Added content mentioned in step 3 & step 4- option 2 with only modifications for the php version name as below.Below given is the full content of my current xampp - Apache config file (httpd-xampp.conf)
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadFile "C:/xampp/php/libsqlite3.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php7_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php7_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/xampp/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php7_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
</IfModule>
ScriptAlias /php8 "C:/xampp/php8"
Action application/x-httpd-php8-cgi /php8/php-cgi.exe
<Directory "C:/xampp/php8">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
Listen 8056
<VirtualHost *:8056>
<FilesMatch "\.php$">
SetHandler application/x-httpd-php8-cgi
</FilesMatch>
</VirtualHost>
saved its contents & restarted xampp & apache.
I used XAMPP and had ran into the same issue. I have since moved to Laragon and it makes using different versions of PHP & MySQL simple.
Check it out: Laragon
i agree laragon is best for windows not sure if you can use multiple php on xamp without installing it in different folders
maybe this works
Is there way to use two PHP versions in XAMPP?

php file wont run properly on my server that I just set up via Cyberduck

I've set up a local server with Vagrant via Cyberduck on my Mac. There seems to be no problem with running a file in general (I guess?) except for php file for some reason. It simply shows what I typed in, which is
<?php
echo "hello from Vagrant";
instead of saying hello from Vagrant
I also did sudo vi /etc/httpd/conf.d/php.conf and see what seems to be the problem that's causing this.
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule !prefork.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Deny from all
Satisfy All
</IfModule>
</Files>
#
# Allow php to handle Multiviews
#
AddType text/html .php
#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php
# mod_php options
<IfModule mod_php5.c>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
#
# Uncomment the following lines to allow PHP to pretty-print .phps
# files as PHP source code:
#
#<FilesMatch \.php$>
# SetHandler application/x-httpd-php-source
#</FilesMatch>
Also here's some quick info about my software version that I've used so far.
PHP 5.6.15
Apache 2.2.15
CentOS 6.7
Cyberduck 4.7.3
Anyone knows any solution to this? Thank you in advance!

Apache downloading php files instead of executing them

I am trying to install phpmyadmin in my Ubuntu Server and when I try to access via browser to it, a php file downloads instead of displaying the web page. I placed a phpinfo testfile in /var/www and it is working fine.
I have already commented lines in php5.conf file:
<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
Order Deny,Allow
Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Order Deny,Allow
Deny from all
</FilesMatch>
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
#</IfModule>
I am using Apache/2.4.6 and Ubuntu Server 13.10
If you installed phpmyadmin as application, then try to download source code from official website and run it manually (copy into your directory /var/www and add VirtualHost settings in apache config ) It's easier than try to decide your issue.

apache2 keeps serving old versions of php files

as in the title, this problem still persist, i've configured a virtualHost in apache2(on Ubuntu 12.04 on OVH Dedicated server), i've put a simple index.php in the base directory of my VirtualHost that contains this simple code:
<?php
echo "Hello world! ";
?>
but when i update my file by adding or removing code, i chek it by accessing the url http://test.xxxxx.ma:8082, the update is not applied, i've cleared my browser cache, used a new browser, i've cheked if mod_cache is enabled but it's not and i'm sur i'm working on the right directory, the new version of the file index.php is only served after a restart of apache2, my VirtualHost configuration is as follow :
<VirtualHost *:8082>
DocumentRoot "/var/www/vhosts/xxxxx.ovh.net/test"
ServerName test.xxxxx.ma
<Directory "/var/www/vhosts/xxxxx.ovh.net/test">
<IfModule sapi_apache2.c>
php_admin_flag engine on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch +Indexes
allow from all
</Directory>
</VirtualHost>
try adding
# Disable Caching for Scripts and Other Dynamic Files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
in a .htaccess file

Apache uploads (gives for download) php instead of executing it

Im using Virtualmin on top of Webmin to configure my websites on a VPS.
Everything worked fine, but now I try to create a new domain, but when I put files in its public_html it gives the php-files to download instead of executing it. How to solve this
These is my apache config (can't find anything strange):
/etc/apache2/sites-available/testbyc.--.nu.conf
SuexecUserGroup "#1009" "#1011"
ServerName testbyc.--.nu
ServerAlias www.testbyc.--.nu
ServerAlias webmail.--.--.nu
ServerAlias admin.testbyc.--.nu
DocumentRoot /home/byc/domains/testbyc.--.nu/public_html
ErrorLog /var/log/virtualmin/testbyc.--.nu_error_log
CustomLog /var/log/virtualmin/testbyc.--.nu_access_log combined
ScriptAlias /cgi-bin/ /home/byc/domains/testbyc.--.nu/cgi-bin/
ScriptAlias /awstats/ /home/byc/domains/testbyc.--.nu/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/byc/domains/testbyc.--.nu/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/byc/domains/testbyc.--.nu/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/byc/domains/testbyc.--.nu/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/byc/domains/testbyc.--.nu/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.testbyc.--.nu
RewriteRule ^(.*) https://testbyc.--.nu:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.testbyc.--.nu
RewriteRule ^(.*) https://testbyc.--.nu:10000/ [R]
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "testbyc.--.nu statistics"
AuthType Basic
AuthUserFile /home/byc/domains/testbyc.--.nu/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*) https://testbyc.--.nu:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*) https://testbyc.--.nu:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
Alias /pipermail /var/lib/mailman/archives/public
Try commenting out the line
php_admin_value engine Off
It's related to a larger issue that I'm still researching, but a recent update to Virtualmin added that line to some FCGI-related config files, breaking some things for some users.
As the accepted answer has said comment out
php_admin_value engine Off
We had this issue moving a site from one Virtualmin Install with PHP 5.X to a new server with PHP 7.1.
What had happened is that the default configuration for PHP7.1 had the following
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_flag engine Off
</Directory>
</IfModule>
This stopped virtualmin from running PHP scripts in users directories by adding that flag to all the local .conf files.
The php7.conf file /etc/apache2/mods-available/php7.conf also had the following
SetHandler application/x-httpd-php
This was causing all child sites to run with the process www-data and not the virtualmin user. Causing write access errors. So comment that out also.

Categories