Tag: ubuntu

Instalacja nginx z php5 debian

Przedstawię dziś jak zainstalować i skonfigurować serwer nginx z obsługą php5

Pierwsze co to instalujemy sam serwer.

apt-get install nginx

Cały config serwera jest w /etc/nginx

Poniżej zamieszczam moją zawartość pliku /etc/nginx/sites-available/default. Wartość zmiennej root (u mnie /var/www/) należy zmienić na katalog, który ma być udostępniany przez serwer.

server {
  listen   80;
  server_name  localhost;

  root  /var/www;
  index  index.php index.html index.htm;
  access_log  /var/log/nginx/localhost.access.log;

  location = / {
    autoindex on;
  }
  location / {
    autoindex on;
  }

  ## obsługa PHP na serwerze FastCGI
  location ~ \.php($|/) {
    set $script  $uri;
    set $path_info  "";
    if ($uri ~ "^(.+\.php)(/.+)") {
      set $script  $1;
      set $path_info  $2;
    }
    include /etc/nginx/fastcgi_params;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$script;
    fastcgi_param  SCRIPT_NAME  $script;
    fastcgi_param  PATH_INFO  $path_info;
  }

  # wyłączenie logowania obrazków
  # i nagłówek Expires
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
    access_log  off;
    expires  30d;
  }
}

Po czym restartujemy serwer

/etc/init.d/nginx restart

Instalujemy interfejs CGI dla interpretera PHP (php5-cgi) i starter serwera FCGI (spawn-fcgi).

apt-get install php5-cgi spawn-fcgi

Teraz tworzymy skrypt dzięki któremu CGI będzie startować z systemem. (wartość zmiennej CHDIR należy zmienić na wartość dyrektywy root z konfiguracji nginxa)

nano /etc/init.d/php5-cgi
#!/bin/bash

NAME="PHP5-CGI"
SPAWNFCGI="/usr/bin/spawn-fcgi"
PHPFCGI="/usr/bin/php5-cgi"
FCGIPORT="9000"
FCGIADDR="127.0.0.1"
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
ALLOWED_ENV="PATH USER"
PIDFILE="/var/run/php5-cgi.pid"
USER="www-data"
CHDIR="/var/www"

## no config below this line

SCRIPTNAME=$0
COMMAND=$1
USAGE="Usage: $SCRIPTNAME {start|stop|restart|status}"
DESC="$NAME at $FCGIADDR:$FCGIPORT"

if [ -z "$PHP_FCGI_CHILDREN" ]; then
  PHP_FCGI_CHILDREN=5
fi

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN"
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS"
ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS"

PID=`cat $PIDFILE`

function err {
      echo $@ >2
}
function die {
      err $@
      exit 1
}

function is_daemon_running {
    test -n "$PID" && test -n "`ps h -p $PID`" && return 0
    return 1
}

function daemon_start {
    if is_daemon_running; then
        err "Process already running: $PID"
        return 1
    fi
    EX="$SPAWNFCGI -d $CHDIR -u $USER -a $FCGIADDR -p $FCGIPORT -f $PHPFCGI -P $PIDFILE"
    E=""
    for i in $ALLOWED_ENV; do
        E="$E $i=${!i}"
    done
    nohup env - $E sh -c "$EX" &> /dev/null &
    return $?
}

function daemon_stop {
    if [ -z "$PID" ]; then
        err "No pid found in pidfile: $PIDFILE"
        return 1
    elif [ -z "`ps h $PID`" ]; then
        err "Process not running: $PID"
        return 1
    fi
    kill $PID
    return $?
}

RETVAL=0
function save_retval {
    RETVAL=$1
    log_end_msg $1
}

. /lib/lsb/init-functions

case "$COMMAND" in
    start)
        log_daemon_msg "Starting $DESC"
        daemon_start
        save_retval $?
        ;;
    stop)
        log_daemon_msg "Stopping $DESC"
        daemon_stop
        save_retval $?
        ;;
    restart)
        log_daemon_msg "Restarting $DESC"
        daemon_stop
      sleep 1
        daemon_start
        save_retval $?
        ;;
    status)
        if is_daemon_running; then
            log_daemon_msg "$DESC running"
            save_retval 0
        else
            log_daemon_msg "$DESC not running"
            save_retval 1
        fi
        ;;
    *)
        die $USAGE
        ;;
esac

exit $RETVAL

Powyższy skrypt zapewnia poprawny start i stop serwera FCGI oraz kontrolę zmiennych środowiskowych. Konfiguracja obejmuje nazwę hosta i port, ilość procesów interpretera PHP oraz ilość obsługiwanych zapytań przed restartem procesu. W przypadku, gdy potrzebny będzie drugi serwer PHP5-CGI na tej samej maszynie, wystarczy sklonować ten skrypt konfigurując na inny host lub port.

Jeżeli chcemy by startowało to razem z systemem wydajemy polecenie

update-rc.d php5-cgi defaults

Udostępnianie plików – SAMBA

W dzisiejszym poradniku pokażę jak łatwo jest udostępnić pliki z Linux, dla systemu Windows

Pierwsze co robimy to instalacja sabmy

apt-get install samba

Podczas instalacji na pierwsze pytanie wpisujemy obojętnie co, a na 2 dajemy „Nie”

Domyślny plik z ustawieniami samby, można wywalić

rm /etc/samba/smb.conf

Tworzymy własny config

nano /etc/samba/smb.conf

Wklejamy poniższy:

[global]
workgroup = GRUPA_ROBOCA
server string = dth
security = SHARE
obey pam restrictions = Yes
passdb backend = tdbsam
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n *passwd:*password\supdated\ssuccessfully* .
syslog = 0
log file = /var/log/samba/log.%m
max log size = 1000
dns proxy = No
panic action = /usr/share/samba/panic-action %d
invalid users = root

[transfer]
comment = Pliki
 # Katalog na pliki
path = /home/public
public = yes
writable = yes
create mask = 0777
directory mask = 0777
force user = nobody
force group = nogroup
available = yes

W tym confingu należy zmienić grupę roboczą oraz katalog, który chcemy udostępnić
Oczywiście po zapisaniu pliku, musimy stworzyć katalog

w moim przypadku to

mkdir /home/public

Następnie nadajemy chmody, aby wszyscy użytkownicy sieci lokalnej mieli dostęp

chmod 777 /home/public

Oraz restartujemy sambę

/etc/init.d/samba restart

FAQ

1. Żeby udostępnianie działało, samba musi mieć tę samą grupę roboczą, co system Windows


Aktualne repozytoria, Debian, Ubuntu, apt-get

Ubuntu

Otwieramy plik

sudo nano /etc/apt/sources.list

Wklejamy

# Ubuntu - podstawowe repozytoria
deb http://pl.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://pl.archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb http://pl.archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb-src http://pl.archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu maverick-security main restricted universe multiverse
deb-src http://security.ubuntu.com/ubuntu maverick-security main restricted universe multiverse
deb http://extras.ubuntu.com/ubuntu maverick main
deb-src http://extras.ubuntu.com/ubuntu maverick main

Zapisujemy

wydajemy polecenie:

sudo apt-get update

Debian

Jako root, otwieramy plik

nano /etc/apt/sources.list

Wklejamy

#~~~~~~Squeeze~~~~~~#
deb http://ftp.pl.debian.org/debian/ stable main non-free contrib
deb-src http://ftp.pl.debian.org/debian/ stable main non-free contrib
deb http://security.debian.org/ stable/updates main contrib non-free
deb-src http://security.debian.org/ stable/updates main contrib non-free
deb http://ftp.pl.debian.org/debian/ stable-updates main non-free contrib
deb-src http://ftp.pl.debian.org/debian/ stable-updates main non-free contrib

#~~~~~~Backports_Squeeze~~~~~~#
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Zapisujemy, wydajemy polecenie

apt-get update

Linki

Meble na zamówienie, wymiar, Wrocław, Trzebnica, Oborniki Śląskie

stat4u
© 1996-2010 cabana HomePage. Wszystkie prawa zastrzeżone.
Szablon iDream: Templates Next , tłumaczenie: kredyt mieszkaniowy