I would like to inform at the first that I wrote this after I finished my work and i couldn’t revise it well ,so fell free to ask,use ,or even correct whatever you want .Actually I mentioned the use/the reason for every single command here to give you the needed concept to search for the reason if it didn’t work/gave you un expecteded o/p .
I would like too to mention that this tutorial helped me aloot even in writing this http://interfacelab.com/nginx-php-fpm-apc-awesome/
ok now i will write a fast How-to for my second task
I was asked to do the foloowing :
-Install a LEMP server {Linux nginx mysql php }
-choose any open source bloging project and install it {choosed wordpress}
-configure my ADSL router to port forward any requests to my server {http , ssh}
-install dynamic dns client on my server and make it update my free sub-domian reserved at dyndns.net continously
Some notes && background :
-nginx is a very powerfull web server which is well known with its great performance .although it is well known too that it dont have many modules and options like other web servers{apache …etc}.It is v v light though you can use it as a reversed proxy {This is actually one of the common uses for it }
-nginx dont handle php scripts from modules but the only way is to use fast cgi {http://en.wikipedia.org/wiki/FastCGI}as a concept .We can here use spawn-fgci or php-fpm .at the first i used spwn but later I moved to php-fpm .because it has less errors and better performance .
-php-fpm is actually a patching to the php source code no more .
-I choosed wordpress as I am using a P3 machine in my office,and wordpess is +performance than drupal{although drupal has many and many added options }
-I have a repotec ADSL router {will find the model and wirte it here later inshallah}.please note that there is some brands/models of ADSL modems+routers{including mine } don’t provide the port forwarding in a stable way .and there is others that don’t work at all .
-As i don’t have a static IP in my ADSL line I have to setup a dynamic dns client that will update a sub dmoain registered for free on dyndns.net so that any time i want to access my server i will find that it has updated the real ip of my adsl line and binded it to my-sub-dmain.dyndns.net
Notes:
-Installation was not smooth at all .There was many and may depencies I had to reolve ,many errors to handle and so .For sorry I couldn’t take snapshots of all of them but :-I will try to remeber and search 2-You are welcomed to leave a comment/send me asking {actually I prefer to comment to let others see the question and the answer }
Now lets see the work plan
-install some depencies
-download php {i used 5.2.13 }
-download php-fpm {note that every php version has its php-fpm }
-compile,make,make install php
-some modules
-edit some php configuration files
-installing mysql
-install php5-mysql
-downloading and installing nginx
-configuring a default site for nginx
-starting &&testing
-adding them to startup
Step-by-step
apt-get install make bison flex gcc patch autoconf subversion loca
apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-devcd /usr/local/src/gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1./configure --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-pgsql --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-mysqlmake all installstrip /usr/local/bin/php-cgipecl install memcache
pecl install apcpecl install syck-betacp /usr/local/src/php-5.2.8/php.ini-recommended /usr/local/lib/php.inimkdir /etc/php/
ln -s /usr/local/lib/php.ini /etc/php/php.iniln -s /usr/local/etc/php-fpm.conf /etc/php/php-fpm.conf<value name="owner">www-data</value>
<value name="group">www-data</value><value name="user">www-data</value><value name="group">www-data</value>cd ..
sudo tar zxvf nginx-0.6.35.tar.gzsudo rm -f nginx-0.6.35.tar.gzcd nginx-0.6.35sudo ./configure --sbin-path=/usr/local/sbin --with-http_ssl_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_modulesudo make && sudo make installln -s /usr/local/nginx/conf /etc/nginxfastcgi_connect_timeout 60;
fastcgi_send_timeout 180;fastcgi_read_timeout 180;fastcgi_buffer_size 128k;fastcgi_buffers 4 256k;fastcgi_busy_buffers_size 256k;fastcgi_temp_file_write_size 256k;fastcgi_intercept_errors on;### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case “$1″ in
start)
echo -n “Starting $DESC: “
start-stop-daemon –start –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
stop)
echo -n “Stopping $DESC: “
start-stop-daemon –stop –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON
echo “$NAME.”
;;
restart|force-reload)
echo -n “Restarting $DESC: “
start-stop-daemon –stop –quiet –pidfile \
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON
sleep 1
start-stop-daemon –start –quiet –pidfile \
/usr/local/nginx/logs/$NAME.pid –exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
reload)
echo -n “Reloading $DESC configuration: “
start-stop-daemon –stop –signal HUP –quiet –pidfile /usr/local/nginx/logs/$NAME.pid \
–exec $DAEMON
echo “$NAME.”
;;
*)
N=/etc/init.d/$NAME
#echo “Usage: $N {start|stop|restart|force-reload}” >&2
exit 1
;;
esac
exit 0
#——————This is the end of the file ————————————-#
mkdir /usr/local/nginx/sites-enabled
sudo ln -s /usr/local/nginx/sites-enabled /etc/sites#And now let’s add a conf file for our default site at /etc/sites/default.conf. The contents:,note that this some times this is in different file .
server { listen *:80; location / { root /var/www/default/pub; index index.php; # if file exists return it right away if (-f $request_filename) { break; } # otherwise rewrite the fucker if (!-e $request_filename) { rewrite ^(.+)$ /index.php$1 last; break; } } # if the request starts with our frontcontroller, pass it on to fastcgi location ~ ^/index.php { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/default/pub$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include /usr/local/nginx/conf/fastcgi_params; }}php-fm start
/etc/init.d/nginx startcase “$1″ in
“start”)inadyn –username zakishan –password master77 –update_period_sec 600 –alias zakishan.dnsalias.net &
;;
“stop”)
x=`pgrep inadyn`
kill -9 $x
;;
*)echo enter valid start/stop
esac
And now let’s add a conf file for our default site at /etc/sites/default.conf. The contents:
01.server {02. listen *:80;03. 04. location / {05. root /var/www/default/pub;06. index index.php;07. 08. # if file exists return it right away09. if (-f $request_filename) {10. break;11. }12. 13. # otherwise rewrite the fucker14. if (!-e $request_filename) {15. rewrite ^(.+)$ /index.php$1 last;16. break;17. }18. 19. }20. 21. # if the request starts with our frontcontroller, pass it on to fastcgi22. location ~ ^/index.php23. {24. fastcgi_pass 127.0.0.1:9000;25. fastcgi_param SCRIPT_FILENAME /var/www/default/pub$fastcgi_script_name;26. fastcgi_param PATH_INFO $fastcgi_script_name;27. include /usr/local/nginx/conf/fastcgi_params;28. }29.}
June 30, 2010 at 5:20 am |
thanks for ur tutorial
June 30, 2010 at 10:01 am |
Welcomed ,hope u enjoyed