Archive for the ‘BSD’ Category
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:
FreeBSD’de php/FastCGI destegi ile Nginx kurulumu (1)
FreeBSD altinda, Nginx‘e php destegi vermek istiyorsaniz eger, bir kac adimda Nginx’e php-FastCGI destegini ekleyebiliyoruz….
yapmamiz gerekenler aslinda basit:
Nginx Kurulumu:
# cd /usr/ports/www/nginx
# make install clean
┌────────────────────────────────────────────────────────────────────┐
│ Options for nginx 0.6.35 │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │[ ] DEBUG Enable nginx debugging │ │
│ │[ ] GOOGLE_PERFTOOLS Enable google perftools module │ │
│ │[X] HTTP_MODULE Enable HTTP module │ │
│ │[ ] HTTP_ACCESSKEY_MODULE Enable http_accesskey module │ │
│ │[X] HTTP_ADDITION_MODULE Enable http_addition module │ │
│ │[ ] HTTP_DAV_MODULE Enable http_webdav module │ │
│ │[ ] HTTP_FLV_MODULE Enable http_flv module │ │
│ │[ ] HTTP_GZIP_STATIC_MODULE Enable http_gzip_static module │ │
│ │[ ] HTTP_PERL_MODULE Enable http_perl module │ │
│ │[ ] HTTP_REALIP_MODULE Enable http_realip module │ │
│ │[X] HTTP_REWRITE_MODULE Enable http_rewrite module │ │
│ │[ ] HTTP_SSL_MODULE Enable http_ssl module │ │
│ │[X] HTTP_STATUS_MODULE Enable http_stub_status module │ │
│ │[ ] HTTP_SUB_MODULE Enable http_sub module │ │
│ │[ ] MAIL_MODULE Enable IMAP4/POP3/SMTP proxy module│ │
├─└────v(+)────────────────────────────────────────────────────────┘─┤
│ [ OK ] Cancel │
└────────────────────────────────────────────────────────────────────┘
karsimiza bu sekilde bir configure ekrani cikiyor. Ben Http_module, addition, rewrite ve status module’u sectim. kendi isteginize gore diger moduleleride secmek sizin elinizde tabikide.
OK dedikten sonra kurulumu sevgili portsumuz zaten yapiyor.
daha sonra echo ‘nginx_enable=”YES”‘ >> /etc/rc.conf komutunu verip sistem acilisinda otomatik olarak Nginx’in baslamasini sagliyoruz (bu da tabi size kalmis bir karar, yok ben ek ile baslatmak istiyorum derseniz eger /usr/local/etc/rc.d/nginx start diyerek el ile calistirabilirsiniz.)
FreeBSD’de Nginx’in varsayilan ayarlari:
/usr/local/etc/nginx/nginx.conf -> Ayar dosyasi
80 / 443 -> varsayilan http ve https portu
/var/log/nginx-error.log -> error log
/var/log/nginx-access.log -> access log
/usr/local/www/nginx/ -> document root
Nginx’in calistirilmasi ve test edilmesi:
/usr/local/etc/rc.d/nginx start komutu ile Nginx’i calistirabilirsiniz. Burada dikkat etmeniz gereken bir nokta var. Eger rc.conf dosyasina nginx_enable=”YES” satini eklemediyseniz, servis baglatilmayacaktir. O yuzden rc.conf a gerekli eklemeyi yapmali veya /usr/local/etc/rc.d/nginx den bir kac degisiklik ile el ile baslatilabilir hale getirebilirsiniz. rc.d dosyalarinda degisiklik ilemini pek tavsiye etmedigim icin o konuya hic girmeyecegim ;)
Nginx’i durdurmak icin /usr/local/etc/rc.d/nginx stop ve yeniden baslatmak icinse /usr/local/etc/rc.d/nginx restart komutlarini kullanabilirsiniz.
Nginx’in ayar dosyasini test etmek ve olasi hatalari gormek icinse:
nginx -c /usr/local/etc/nginx/nginx.conf -t komutunu kullanabilirsiniz.
Eger ayar dosyasinda herhangi bir hata yok ise:
[root@mx-backup /usr/home/noyan]# nginx -c /usr/local/etc/nginx/nginx.conf -t
2009/03/28 13:49:46 [info] 64526#0: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
2009/03/28 13:49:46 [info] 64526#0: the configuration file /usr/local/etc/nginx/nginx.conf was tested successfully
Seklinde bir cikti alacaksiniz, problem yok, harika!..
Artik gonul rahatligiyla /usr/local/etc/rc.d/nginx start komutunu verip, Nginx’i calistirabiliriz…