Thursday 27 August 2015

Simple photo upload and share code in php

Features:
-Upload, compress, share
-Album, blog, hash tag
-Search

Live code: http://photo.initedit.com 



more opensource code: http://opensource.initedit.com

Installation steps:
Now get started with how to install photo.initedit.com .

- First you need to have an server which support php and mysql(LAMP).
- Now Unzip the downloaded folder.(downlaod)
- Go to "mysql" directory inside the extracted directory.
- Now After confirming table.sql file go to phpmyadmin panel(or import using mysql console).
- Create a new database using phpmyadmin
- Now Click on import to import tables.sql file from our "mysql" directory.
- Now go to extracted folder inside php/class/ folder.
- Open common.php file in text editor.
- Change username ,password, and databases accordingly .
- Done.

Note : You also have to install Imagick for optimizing image loading
(http://php.net/manual/en/imagick.installation.php)

Tuesday 11 August 2015

simple Load balancer using Nginx web server

Nginx Load balancing on linux ubuntu 14.04

Loadbalancer(lb):192.168.0.10(Nginx)
webserver(web1):192.168.0.11(apache)
webserver(web2):192.168.0.12(apache)
webserver(web3):192.168.0.13(apache)
database server(db):192.168.0.14(mysql)

note:we can increase web server for load balancing.

1.Install nginx webserver on Loadbalancer(lb)

apt-get install nginx

2.Edit the nginx default file.

 nano /etc/nginx/nginx.conf

note:you can use any text editor vi or pico.

events {
        worker_connections  1024;
        use                 epoll;
        multi_accept        on;
}

upstream backend  {
  server 192.168.0.11;
  server 192.168.0.12;
  server 192.168.0.13;
}

server {
  location / {
    proxy_pass  http://backend;
  }
}

3.Restart nginx webserver

sudo service nginx restart

4.Install apache webserver on web1, web2 and web3.

apt-get install apache2


5.Goto var/www/html folder of webserver respectively and remove index.html .
add new index.html and write web1 for web1 apache server.

6.Install mysql server on db

apt-get install mysql-server


7.To allow mysql accessible to all webserver run bellow command.


$ mysql -u root -p
Enter password:


mysql> GRANT ALL ON *.* to root@'192.168.0.11' IDENTIFIED BY 'your-root-password';


mysql> GRANT ALL ON *.* to root@'192.168.0.12' IDENTIFIED BY 'your-root-password';


mysql> GRANT ALL ON *.* to root@'192.168.0.13' IDENTIFIED BY 'your-root-password';


Note:I didnot add mysql server in above example but you can add .


8.Open your browser goto url http://192.168.0.10 and refresh the page.

you will see whenever you refresh the page it will show you from which webserver your page is loaded.(because we have added html file in step 5). It will distribute web request equally across the apache Webserver.


Nginx also have diffrent type of load balancing:

1.Session persistence

2.Weighted load balancing

3.Max Fails, etc.


for more:http://nginx.org/en/docs/http/load_balancing.html