smarty and suphp permissions - saving as different user - php

Right now i have to give 777 permission to the directory where files are saved and instead of saving it as "user1" is saving it as apache
-rwxrwxrwx 1 apache apache 6865 Aug 30 17:20 homepage.tpl.php
How can the files be saved as user1 and without 777 permission outside my docroot wich is home/user1/public_html/
lets say in /home/user1/private/homepage.tpl.php
Im using a Centos LAMP with suPHP.
Thanks in advance.

Solved
To fix it I had to reinstall suphp with this conf.
/etc/suphp.conf
check_vhost_docroot=true
and use the correct handlers
[handlers]
;Handler for php-scripts
x-httpd-php="php:/usr/bin/php-cgi"
;Handler for CGI-scripts
x-suphp-cgi="execute:!self"
Inside the virtual host
suPHP_Engine on
suPHP_UserGroup user user
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php

Related

Apache Unable to Write to File

I am using Fedora 24 on VirtualBox to host a small PHP web app. I am trying to append text into a file that is in the same local directory as the PHP file (/var/www/html/). No matter what kind of permissions or ownerships I try to set onto the directory (html/) or the file I constantly get "Permission denied in /var/www/html/pdf.php on line 21" errors.
Is there any configuration settings in my php.ini file that I need to enable to allow editing of files? I've even tried setting the directory and file to chmod 777 just to see if it would give me access but even that is being rejected.
EDIT: I have also tried creating directories and files in other locations with the same results. I tried to have Apache run the mkdir and touch commands with the same results.
EDIT 2: At the request of the comment left to my initial question. Here is the ownership information for the target directory:
ls -l /var/www/html/
drwxrwxr-x. 2 apache apache 4096 Nov 23 21:28 docs
The ownership information for the file:
-rwxrwxr-x. 1 apache apache 1381 Nov 28 17:47 pdf.php
Try assigning to www-data:nobody
chown -R www-data:nobody *, check apache group on your httpd.conf.
Verify /var/html perms to 775 at least.
Spent a lot of time looking for this answer but it's all in bits and pieces and no one every posts a solution (well most of the time) so here is my solution and it's used on various web control panels as well.
install and use MOD_RUID2
Install PHP with CLI (this is standard on newer versions)
In your HTTPD.CONF file in the virtual hosts, you'll add the following, replacing username with the user's login name, and usergroup with the user's group (These are usually the same)
<IfModule !mod_ruid2.c>
SuexecUserGroup username usergroup
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid username usergroup
RGroups #none
</IfModule>
An example of a Virtual host conf is:
<VirtualHost *:443>
DocumentRoot "/home/imtheuser/public_html"
ServerName imtheuser.com
<IfModule !mod_ruid2.c>
SuexecUserGroup imtheuser imtheuser
</IfModule>
<IfModule mod_ruid2.c>
RMode config
RUidGid imtheuser imtheuser
RGroups #none
</IfModule>
<Directory "/home/imtheuser/public_html">
allow from all
Options None
Require all granted
</Directory>
</VirtualHost>
This will allow apache/php to write to a directory owned by the user. It's much safer then setting your chmod to 0777.

Why don't php files in subdomain run under same user/group as main domain (Webmin)?

System: LAMP stack running CentOS 6 and Virutalmin/Webmin.
I set up a subdomain using Webmin, within an existing main domain (also created with Webmin). The main domain runs as user 910, group 582. Placing a php script in the main domain's public_html dir with this code:
<? echo `whoami`; ?>
generates the username of the domain owner.
Placing the same script in the subdomain's public_html generates 'apache'.
Both directories and files have the same ownership (910:582).
In /etc/httpd/conf/httpd.conf both virtual hosts have the same SuexecUserGroup line:
SuexecUserGroup "#910" "#582"
I need the subdomain to run under the same user, so Wordpress can access the files directly. Otherwise I have to chown everything in the subdomain to apache:apache which is a security risk/bad practice.
What am I missing here?
Thanks!
Turns out this issue was due to several things:
mod_php5 being enabled by default. Adding the directive
php_admin_value engine Off
to the httpd.conf file for this virtual host disables mod_php5 which is incompatible with suexec.
Add FCGIWrapper directive, which wasn't created by Webmin
FCGIWrapper [home dir]/fcgi-bin/php5.fcgi .php
Create the php5.fcgi file in the fcgi-bin directory. I just copied this file from another virtual host as it's only a bash shell script to launch the php interpreter.
Add AddHandler and AddType directives to the main VirtualHost section and also the public_html <directory> section:
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
Ensure all file ownership and permissions are set correctly to the owner of the account.

active .user.ini for one user

I active custom user php.ini . now user's can have their own .user.ini.
now i want some of my user use this feature and other deny from using custom .user.ini
so i uncomment line :
; To disable this feature set this option to empty value
user_ini.filename =
now this feature is disable for all user, how can i active it for user1 not all of them(exm) ?
server is LAMP with no panel of course
CentOs 6.x apache + SUphp FaCGI
I used this directive in virtual host but it didn't work
DocumentRoot /home/mam/public_html
ServerName mam.test.ir
suPHP_Engine on
suPHP_UserGroup mam mam
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php
php_value user_ini.filename ".user.ini"
suPHP_ConfigPath /home/mam/public_html
is there any idea ?????? NOTE: I don't want to use .htaccess for this
I figured it out myself :|
For doing this you have to way one is include file and second is:
suPHP_ConfigPath /home/mam/public_html/php.ini
You need to use absolute path :)
A trick could be to use CHMOD to make the .user.ini in the specific virtual host document root readable and writable only to the admin/root user (feature disabled) or to the user too (feature enabled).

Downloads files instead of opening them

I downloaded EasyPHP 14.1 VC9, and downloaded all of my files from my webhost (new computer). Now when going to any folder below the data/localweb/ level just causes my browser to download the file instead of executing and opening it.
For example:
data/localweb/index.php works fine.
data/localweb/somefolder/index.php doesn't work.
No wordpress or any craziness, just vanilla PHP. Any PHP on the root folder works fine, but my server architecture is just folders off the root - any way to keep it and have PHP find ALL php files and execute them as long as they are under the root folder?
I have these lines in the Apache config:
AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc
LoadModule php5_module "${path}/binaries/php/php_runningversion/php5apache2_4.dll"
OS: Win7 Home Premium 64bit
facepalm
Let this be a lesson learned for everyone out there.
The key we should be looking for from now on is 'downloaded from webhost'.
My somefolder/ contained an extra .htaccess that was from my webhost. Deleting it solved the problem.

phpmyadmin - save file to disk

when i point my browser to http://localhost/phpmyadmin, instead of showing me its front page, it comes up with save as dialog.
I'm running:
Apache/2.2.3 (Debian) PHP/5.2.0-8+etch13 Server
I've reinstalled both apache2 and php5.
After re-install i don't have httpd.conf file, how can i get it back? Is there a standard file which i can just copy into /etc/apache2?
I did a locate httpd.conf and the only file i got was the empty file i have under /etc/apache2/ which i made.
Did you configure the php extension to send an http header?
In httpd.conf:
AddType application/x-httpd-php .php
EDIT
The file is not necessarily named httpd.conf, that's just the default name. Try searching for other configuration files in the Apache directory -- the extension probably is .conf but it might be something else...
If you used apt-get on debian to install apache2, try /etc/apache2/apche2.conf
/EDIT
I also get this problem when I install ISPconfig. I solved the problem by this tutorial:
http://www.howtoforge.com/perfect-server-debian-wheezy-apache2-bind-dovecot-ispconfig-3-p4
I think the main code is change suphp.conf config.
sudo nano /etc/apache2/mods-available/suphp.conf
comment out the <FilesMatch "\.ph(p3?|tml)$"> section and add the line AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml - otherwise all PHP files will be run by SuPHP
<IfModule mod_suphp.c>
#<FilesMatch "\.ph(p3?|tml)$">
# SetHandler application/x-httpd-suphp
#</FilesMatch>
AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml
suPHP_AddHandler application/x-httpd-suphp
<Directory />
suPHP_Engine on
</Directory>
# By default, disable suPHP for debian packaged web applications as files
# are owned by root and cannot be executed by suPHP because of min_uid.
<Directory /usr/share>
suPHP_Engine off
</Directory>
# # Use a specific php config file (a dir which contains a php.ini file)
# suPHP_ConfigPath /etc/php5/cgi/suphp/
# # Tells mod_suphp NOT to handle requests with the type <mime-type>.
# suPHP_RemoveHandler <mime-type>
</IfModule>
Hope I can help someone :)
I think you just do not know where that config file is. I don't think apache can run without httpd.conf. Here is how you can find your config:
$>locate httpd.conf
/etc/httpd/conf/httpd.conf
$>vim /etc/httpd/conf/httpd.conf
Once you located it, find where other AddType reside and add
AddType application/x-httpd-php .php
Last thing you need to do is restart your httpd, it depends on install, but doing apachectl restart does the trick. You might have to locate it just like you did with httpd.conf file and type in the entire path to the file.
Afterwords, your phpmyadmin should come up.
I dont know anything about this but... does someone knows a way in javascript to download selected files, for example I select through checkboxes 2 files, and then I click on a button in order to download these 2 files choosing the route where i will save the archives

Categories