ubuntu server 12.04 - php files downloading - php

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.

Related

How can i block direct access to specific folder?

There is my problem, i have an img tag, src gets image from icon/ folder and i need to disable direct link access to that folder and content inside that when user type something like 'mywebsite.com/icon/logo.png', using htaccess, but allow content inside src attribute to get and display it without 403 error message 'access denied' in browser console, i made lot of research but nothing helped me, if i missing something please provide your opinions thanks.
my .htaccess code is here:
<IfModule mod_rewrite.c>
<If "%{HTTP_HOST} == 'http://mywebsite.com/icon/'">
deny from all
</If>
<Else>
allow from all
</Else>
</IfModule>
The best way to do this is disable it with webserver apache2. In my 14.X Ubuntu - open /etc/apache2/apache2.conf you have to change from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
now just restart apache.
to restart apache2 run:
sudo service apache2 restart
This will disable directory listing from all folder that apache2 serves.

How to run two versions of PHP for two projects on same apache server

I have 2 different virtual hosts on my apache server. One of them needs php7.x and another need php5.x.
Is it possible to use project-specific PHP versions?
I have tried the following,
Running two PHP versions on the same server
but my apache server crashed saying there's some syntactical error in one of the fpm's config file.
Also I cant follow this solution since It advices to uninstall apache and start over again and I can't do that on a live server.
Is there any way to do this without uninstalling the apache server.
Thank you for your suggestions.
for windows on file httpd-vhosta.conf
<VirtualHost *:80>
DocumentRoot "d:/server/htdocs/"
ServerName localhost
ServerAlias www.localhost
<Directory "d:/server/htdocs/">
Require all granted
<Files ~ "\.php$">
AddHandler fcgid-script .php
#FcgidWrapper "d:/server/php/php-5.6.40-Win32-VC11-x64/php-cgi.exe" .php
FcgidWrapper "d:/server/php/php-7.1.24-Win32-VC14-x64/php-cgi.exe" .php
Options +ExecCGI
</Files>
</Directory>
ErrorLog "D:/server/apache/logs/error-localhost.log"
SetEnv APP_ON_LOCAL 1
</VirtualHost>

How to execute php code in html files (php-fpm and apache 2.4) on centos 7

As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.
Can you please guide us how we can execute PHP code in .html files.
Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.
After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :
"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf
and
SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf
PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.
Your help would be appreciated.
This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:
<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443
<Directory "/home/myvhost/public_html">
allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Require all granted
php_admin_value open_basedir /home/myvhost/public_html
</Directory>
SuexecUserGroup myvhost myvhost
ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</FilesMatch>
</VirtualHost>
And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):
[myvirtualhost.com]
user = myvhost
group = apache
listen = 127.0.0.1:9000
security.limit_extensions = .php
So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.

PHP-FPM requires restart to access generated file when visiting webpage

As part of a web-based project I work on, we generate new "sites" which are accessed by passing in a different parameter to $_GET. All of the sites live in /usr/local/sites. None of the sites are owned (either user or group) by the user we use (hwphp, www-data is the default apache user still), but the user is in the group so can read all files in the directories.
I have a python script that generates sites and after running it, half the time when I try and visit it by going to http://localhost/index.php?site=newsite I get File not found: /var/local/sites/newsite/config/config.ini though running PHP CLI it can find the file and hwphp user can read it just fine, just when I go through PHP-FPM/Apache it fails.
Here's my pool configuration:
; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[submitty]
user = hwphp
group = hwphp
listen = /run/php/php7.0-fpm-submitty.sock
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
and my apache configuration:
<VirtualHost 192.168.56.101:80>
AddDefaultCharset utf-8
ServerAdmin ADMIN#DOMAIN.HERE
ServerName 192.168.56.101
DocumentRoot /usr/local/submitty/site/public
DirectoryIndex index.html index.php index.htm index.cgi
SuexecUserGroup hwphp hwphp
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi .php
Action php7-fcgi /php7-fcgi
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm-submitty.sock -pass-header Authorization
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler php7-fcgi
</FilesMatch>
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
<Files .*>
Order allow,deny
Deny from all
</Files>
<Files *~>
Order allow,deny
Deny from all
</Files>
<Files #*>
Order allow,deny
Deny from all
</Files>
<Directory />
AllowOverride None
</Directory>
<Directory /usr/local/submitty/site/public>
Require all granted
Order allow,deny
Allow from all
</Directory>
LogLevel error
ErrorLog ${APACHE_LOG_DIR}/submitty.log
CustomLog ${APACHE_LOG_DIR}/submitty.log combined
</VirtualHost>
as soon as I do:
service php7.0-fpm restart
and it works fine and the file is found. Not sure why this might be as it makes no sense (and why a simple restart is what fixes it).
Server is Ubuntu 16.04, using PHP 7 and Apache 2.4, everything from the stock apt-get installs.
The issue ended up being that PHP was doing some caching of the file read which was causing the issues when trying to open the files. Doing a restart of php-fpm flushed the cache and made things just work.

ProxyPassMatch and Options +Indexes (mod_autoindex)

I have a simple setup with Apache2.4 and PHP-FPM and I am trying to enable +Indexes option but I get 404 "File not found." when trying to access a folder that doesn't have an index file even when autoindex is enabled.
Here's part of my vhost:
#php
ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/fpm/fatal.sock|fcgi://
#super public directory with Indexes!
<Location /pub>
Options +Indexes
IndexOptions +FancyIndexing
</Location>
When I try to access http://domain.com/pub/ I expected to see a list of files I put there but instead I get error 404 Not Found.
I wonder where this comes from since ProxyPassMatch shouldn't forward the request because there is no .php in the query so next is directory index which looks for index.php which doesn't exists (404) but why then mod_autoindex doesn't work?
When I remove the ProxyPassMatch line the autoindex works just fine and I see the folder content listed.
Any ideas?
I found the answer here http://blog.famillecollet.com/post/2014/03/28/PHP-FPM-and-HTTPD-2.4-improvement
As the ProxyPassMatch directive is evaluated at the very beginning of each request:
AddType (for MultiView) or DirectoryIndex directives are not usable
right management per directory is not available
each Alias directive needs another proxy rule
The SetHandler directive, evaluated later, is much more flexible / usable.
So I changed my vhost to look like this and got rid of the ProxyPassMatch directive.
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/fpm/fatal.sock|fcgi://"
</FilesMatch>
Note: this solution applies to Apache 2.4.9+
(I do wonder if there are any performance difference and in what direction?)

Categories