16th Luglio 2007

Configurare suphp con Apache

Questo modulo per apache serve a risolvere un problema che da sempre crea non pochi problemi legati alla gestione dei permessi tramite apache.

Infatti solitamene si incappa nel problema che caricando un file tramite uno script in php ad esempio, l’ownership del file caricato viene cambiata, rendendo di fatto difficoltosa la gestione dello stesso tramite ftp che risulta essere associato ad un altro utente.

Stiamo parlando di hosting condivisi multiutente che lavorano tramite virtualhost

Installare suphp su fedora core 5

Basta semplicemente installare mod_suphp

[root@backup ~]# yum install mod_suphp

e configurare i file
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.d/mod_suphp.conf
/etc/suphp.conf

NEl file /etc/httpd/conf.d/php.conf fare attenzione a commentare questa riga

#AddHandler php5-script .php

in modo da togliere all’interprete di default il php

Nel file /etc/httpd/conf.d/mod_suphp.conf aggiungere

AddHandler x-httpd-php .php

e decommentare le righe

LoadModule suphp_module modules/mod_suphp.so

suPHP_Engine on
suPHP_AddHandler x-httpd-php

Infine nel file /etc/suphp.conf cambiare il parametro

umask=0022

con i prmessi desiderati per i file creati dagli script.

Inoltre modificare le security optoins come segue

; Security options
;allow_file_group_writeable=false
allow_file_group_writeable=true
allow_file_others_writeable=false
;allow_directory_group_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false

e mettere i minimum UID e GUD con quelli di apache pe mantenere la compatibilità con eventuali script con l’ownership di apache
in fedora il 48 corrisponde all’utente apache, bisogna mettere zero altrimenti ci son problemi con phpmyadmin che gira come root, oppure bisogna studiare una soluzione alternativa che non tratto in questo documento.

; Minimum UID
min_uid=0

; Minimum GID
min_gid=0

Inoltre bisogna mettere a false questo sennò da problemi con mysql.domain.tld per il mysql

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=false

Di seguito trovate i tre file di configurazione.

###########################
/etc/httpd/conf.d/php.conf#
###########################
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php5_module modules/libphp5.so

#
# Cause the PHP interpreter to handle files with a .php extension.
#
#AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

#################################
/etc/httpd/conf.d/mod_suphp.conf#
#################################
# This is the Apache server configuration file providing suPHP support..
# It contains the configuration directives to instruct the server how to
# serve php pages while switching to the user context before rendering.
# For directives see <URL:http://httpd.apache.org/docs-2.0/mod/mod_suphp.html>

LoadModule suphp_module modules/mod_suphp.so
AddHandler x-httpd-php .php

# To use suPHP to parse PHP-Files

# This option tells mod_suphp if a PHP-script requested on this server (or
# VirtualHost) should be run with the PHP-interpreter or returned to the
# browser “as it is”.
### Uncomment to activate mod_suphp
suPHP_Engine on
suPHP_AddHandler x-httpd-php

# This option tells mod_suphp which path to pass on to the PHP-interpreter
# (by setting the PHPRC environment variable).
# Do *NOT* refer to a file but to the directory the file resists in.
#
# E.g.: If you want to use “/path/to/server/config/php.ini”, use “suPHP_Config
# /path/to/server/config”.
#
# If you don’t use this option, PHP will use its compiled in default path.
#suPHP_ConfigPath /etc

################
/etc/suphp.conf#
################
[global]
;Path to logfile
logfile=/var/log/suphp.log

;Loglevel
loglevel=info

;User Apache is running as
webserver_user=apache

;Path all scripts have to be in
docroot=/

;Path to chroot() to before executing script
;chroot=/mychroot

; Security options
;allow_file_group_writeable=false
allow_file_group_writeable=true
allow_file_others_writeable=false
;allow_directory_group_writeable=false
allow_directory_group_writeable=true
allow_directory_others_writeable=false

;Check wheter script is within DOCUMENT_ROOT
check_vhost_docroot=true

;Send minor error messages to browser
errors_to_browser=true

;PATH environment variable
env_path=/bin:/usr/bin

;Umask to set, specify in octal notation
;umask=0077
umask=0022

; Minimum UID
min_uid=500

; Minimum GID
min_gid=500

; Use correct permissions for mod_userdir sites
handle_userdir=true

[handlers]
;Handler for php-scripts
x-httpd-php=php:/usr/bin/php-cgi

;Handler for CGI-scripts
x-suphp-cgi=execute:!self

This entry was posted on Lunedì, Luglio 16th, 2007 at 7:31 pm and is filed under apache, hosting, mod_suphp, suphp, virtualhost, webserver. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 2 responses to “Configurare suphp con Apache”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On Gennaio 23rd, 2008, H7-25 said:

    Ho dei problemi di load usando suphp sai se è possibile utilizzare qualche tipo di cache come APC con questo modulo ?

  2. 2 On Gennaio 23rd, 2008, admin said:

    Ciao, problemi di load in che senso? Upload di file, carichi di Cpu o che?

    Puoi postare l’errore esatto che ti esce?

    Come acceleratori ne avevo provati alcuni anche senza suphp, ma mi davano alcuni problemi con degli script di alcuni cms (”premature end of script” o simili) per cui sono stato costretto a rimuoveri, non so se possano dare problemi con suphp, ma sinceramente non credo è una cosa abbastanza a se stante.

Leave a Reply

  • Pubblicità

  • Statistiche

  • Adsense