Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linux Network Servers nginx, PHP-FPM, MySQL Rostislav Skudnov, Timo Jääskeläinen.

Similar presentations


Presentation on theme: "Linux Network Servers nginx, PHP-FPM, MySQL Rostislav Skudnov, Timo Jääskeläinen."— Presentation transcript:

1 Linux Network Servers nginx, PHP-FPM, MySQL Rostislav Skudnov, Timo Jääskeläinen

2 What is nginx? This Russian guy has created the 3rd most popular Web server Used on WordPress, Hulu, SourceForge, and many more... Source: http://news.netcraft.com/archives/2010/04/15/april_2010_we b_server_survey.html Igor Sysoev

3 What is PHP-FPM? FastCGI Process Manager for PHP Another Russian guy, who wasn't satisfied with existing PHP FastCGI, and has created FPM in his spare time In PHP core since 5.5.3 Andrei Nigmatulin

4 Classic LAMP vs nginx + PHP-FPM LAMP One Apache process per each connection PHP is compiled into Apache and launches again on every request High memory and CPU consumption in a high load environment nginx + PHP-FPM A few nginx processes handle thousands of connections PHP processes are spawned when necessary; already spawned ones are reused Low memory and CPU consumption

5 Installing nginx wget http://nginx.org/download/nginx-0.9.4.tar.gz tar -xzf nginx-0.9.4.tar.gz cd nginx-0.9.4./configure --with-http_ssl_module... make make install Create init script in /etc/init.d/nginx

6 Installing PHP-FPM wget http://www.php.net/get/php-5.3.5.tar.gz tar -xzf php-5.3.5.tar.gz cd php-5.3.5./configure --enable-fpm --with-mysql --with-mcrypt --with-curl --with- mysqli --with-mysql-sock --with-pdo-mysql --with-gd --with-zlib make make install Create init script in /etc/init.d/php-fpm

7 Configuring nginx less /usr/local/nginx/conf/nginx.conf user www-data; worker_processes 1; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; gzip on; include /usr/local/nginx/sites-enabled/*; }

8 The add and remove PHP scripts addclient.php: Creates Linux user with auto generated password Writes Nginx configuration file Writes FPM configuration file Creates a placeholder web page for the new user Creates MySQL user and database remclient.php: Reverse action – removes everything including user dir

9 Creating Linux user The PHP script: Generates a random password Makes sure that user name and domain names are correct (RegEx) Sends command to create the user // Creating Unix user, default group www-data passthru("useradd -m -K UMASK=027 -s /bin/bash -c '$domain' -p $passwordCrypted $username", $res); passthru("usermod -a -G $username www-data"); In the end script checks whether the user was created successfully or not

10 Generating Nginx and FPM configs The PHP script: Uses pre-written templates for both configs, replacing username and domain info Copies the config files into nginx available-sites and fpm config directory Creates a link into Nginx sites-enabled

11 Configuring nginx - vhost template less ~/hostadmin/nginx_tpl.txt server { listen 80; server_name [[domain]]; root /home/[[user]]/www/; access_log /home/[[user]]/logs/access.log; error_log /home/[[user]]/logs/error.log; location / { try_files $uri $uri/ @rewr; index index.html index.php; } location ~ \.php$ { include /usr/local/nginx/conf/fastcgi.conf; fastcgi_pass unix:/tmp/[[user]].sock; fastcgi_index index.php; } location @rewr { rewrite ^/(.*)$ /index.php?q=$1 last; }

12 Configuring PHP-FPM - vhost template less ~/hostadmin/fpm_tpl.txt [[[user]]] listen = /tmp/[[user]].sock user = [[user]] group = [[user]] pm = dynamic pm.max_children = 50 pm.start_servers = 1 pm.min_spare_servers = 1 pm.max_spare_servers = 35 php_admin_value[error_log] = /home/[[user]]/logs/fpm-php.log

13 Creating a placeholder web page The PHP script: Uses pre-written HTML and replacing user name and domain name Copies the new HTML file into user’s www directory Sets permissions

14 Creating the MySQL database The PHP script uses three simple MySQL: Create database: mysql_query("create database $user") Create user with generated password and all privileges to his/her database: mysql_query("grant all privileges on $user.* to $user@localhost identified by '$pass'")


Download ppt "Linux Network Servers nginx, PHP-FPM, MySQL Rostislav Skudnov, Timo Jääskeläinen."

Similar presentations


Ads by Google