FreeBSD’de php/FastCGI destegi ile Nginx kurulumu (2)
Gelelim php/FastCGI kurulumuna;
Bunun icin ilk once PHP’yi kurmamiz gerekiyor.
cd /usr/ports/lang/php5
make config
┌────────────────────────────────────────────────────────────────────┐
│ Options for php5 5.2.9 │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │[X] CLI Build CLI version │ │
│ │[X] CGI Build CGI version │ │
│ │[ ] APACHE Build Apache module │ │
│ │[ ] DEBUG Enable debug │ │
│ │[X] SUHOSIN Enable Suhosin protection system (not for jails) │ │
│ │[ ] MULTIBYTE Enable zend multibyte support │ │
│ │[X] IPV6 Enable ipv6 support │ │
│ │[ ] MAILHEAD Enable mail header patch │ │
│ │[ ] REDIRECT Enable force-cgi-redirect support (CGI only) │ │
│ │[ ] DISCARD Enable discard-path support (CGI only) │ │
│ │[X] FASTCGI Enable fastcgi support (CGI only) │ │
│ │[X] PATHINFO Enable path-info-check support (CGI only) │ │
│ │ │ │
│ │ │ │
│ │ │ │
├─└────────────────────────────────────────────────────────────────┘─┤
│ [ OK ] Cancel │
└────────────────────────────────────────────────────────────────────┘
Onumuze bu sekilde bir menu cikacak, burada cgi, cli ve fastcgi ‘nin secili olmasina dikkat ediyor ve daha sonra
make install clean
Komutunu verdigimiz zaman sevgili portsumuz php5 i kuracaktir. Daha sonra;
cd /usr/ports/lang/php5-extensions/
make install clean
komutlarini verip ihtiyac duyulan php extensionlarini kuruyoruz (php-pgsql, php-gd php-mysql vs.)
Kurulum bittikten sonra;
spawn-fcgi dosyasina ihtiyacimiz olacak Nginx’de php calistirabilmek icin. FreeBSD altinda bu dosyayi temin etmenin en kolay yolu; lighttpd paketi icinden spawn-fcgi dosyasini cikartmak olacaktir. Kullandiginiz FreeBSD surumu ve mimariye gore (amd64, i386, IA64 vs.) ftp.freebsd.org adresinden derlenmis paketi temin edebilirsiniz.
Temin ettigimiz spawn-fcgi dosyaini /usr/local/bin/ altina tasidiktan sonra;
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9999 -u www -g www -f /usr/local/bin/php-cgi
komutu ile PHP Fastcgi yi baslatiyoruz.
Peki bu komutta neler var?
-a 127.0.0.1: Nginx’in php dosyalarini calistirabilmesi icin baglanacagi FastCGI adresi.
-p 9999: Nginx’in php dosyalarini calistirabilmesi icin baglanacagi port numarasi.
-u/-g: PHP FastCGI’in altinda calisacagi kullanici adi ve grup.
-f /usr/local/bin/php-cgi: PHP5 fastcgi dosyasinin bulundugu yol.
php/FastCGI’imizin calistigindan emin olmak icin:
sockstat -4 | grep 9999 komutunu veriyor ve
[root@mx-backup /usr/home/noyan]# sockstat -4|grep 9000 www php-cgi 2033 0 tcp4 127.0.0.1:9999 *:* www php-cgi 2032 0 tcp4 127.0.0.1:9999 *:* www php-cgi 2031 0 tcp4 127.0.0.1:9999 *:* www php-cgi 2030 0 tcp4 127.0.0.1:9999 *:* www php-cgi 2029 0 tcp4 127.0.0.1:9999 *:* www php-cgi 1933 0 tcp4 127.0.0.1:9999 *:*
ciktisini gorup rahat ediyoruz
Her seferinde bu komutu vermek yerine; bir rc scripti ile bu islemi yapabiliriz.
#!/bin/sh
# NGINX FastCGI php5 startup shell script
# Feedback
# http://bash.cyberciti.biz/web-server/fastcgi-php-server-start-stop-script/
# Set ME #
PROVIDES=php-cgi
LIGHTTPD_FCGI=/usr/local/bin/spawn-fcgi
SERVER_IP=127.0.0.1
SERVER_PORT=9999
SERVER_USER=www
SERVER_GROUP=www
PHP_CGI=/usr/local/bin/php-cgi
PGREP=/bin/pgrep
KILLALL=/usr/bin/killall
### No editing below ####
cmd=$1
pcgi_start(){
echo "Starting $PROVIDES..."
$LIGHTTPD_FCGI -a $SERVER_IP -p $SERVER_PORT -u $SERVER_USER -g $SERVER_GROUP -f $PHP_CGI
}
pcgi_stop(){
echo "Killing $PROVIDES..."
$KILLALL $PROVIDES
}
pcgi_restart(){
pcgi_stop
pcgi_start
}
pcgi_status(){
$PGREP $PROVIDES > /dev/null
[ $? -eq 0 ] && echo "$PROVIDES running" || echo "$PROVIDES NOT running"
}
pcgi_help(){
echo "Usage: $0 {start|stop|restart|status}"
}
case ${cmd} in
[Ss][Tt][Aa][Rr][Tt]) pcgi_start;;
[Ss][Tt][Oo][Pp]) pcgi_stop;;
[Rr][Ee][Ss][Tt][Aa][Rr][Tt]) pcgi_restart;;
[Ss][Tt][Aa][Tt][Uu][Ss]) pcgi_status ;;
*) pcgi_help ;;
esac
Bu script’i /usr/local/etc/rc.d/php.cgi.sh olarak kaydettikten sonra;
/usr/local/etc/rc.d/php.cgi.sh start komutu ile fastcgi’i calistirabilir
/usr/local/etc/rc.d/php.cgi.sh stop komutu ile fastcgi’i durdurabiliriz.
Son olarak Nginx’e de php dosyalarini calistirmak icin yapmamis gerekenler:
Ilk once sevdigimiz bir editor ile /usr/local/etc/nginx/nginx.conf dosyasini aciyor ve
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9999;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_params;
}
location direktorunu Server { … } kismina ekliyoruz.
Herhangi bir hataya mahal vermemek icin nginx -c /usr/local/etc/nginx/nginx.conf -t komutu ile ayar dosyamizin dogruludan emin olduktan sonra /usr/local/etc/rc.d/nginx restart komutunu vererek Nginx’i yeniden baslatiyoruz.
<?php phpinfo(); ?>
ile son testi yaptiktan sonra da Nginx’imizi mutlu mesut gunlerde kullaniyoruz
FreeBSD’de php/FastCGI destegi ile Nginx kurulumu (Bolum 1)
Kaynak: