Table of Content

download nginx+php+mysql zip package and unzip without installation

config nginx

nginx.conf

  • change doc root from html to www, create www folder under nginx
  • place all app site in conf/conf.d folder and include them

nginx.conf sample

    server {
        listen       80;
        server_name  localhost;

        charset utf-8;

        access_log  logs/host.access.log  main;

        location / {
            root   www;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   www;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            root           www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi.conf;
        }
        
        include conf/conf.d/*.conf;

    }

app site sample

# conf/conf.d/site1.conf

server {
    listen 80;
    server_name locahost;
    root www/site1/;
    index index.php index.html index.htm;
    access_log logs/site1.access.log main;
    error_log logs/site1.error.log error;
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000; 
        fastcgi_index  index.php;
        include        fastcgi.conf;
    }
}   

config php

  • copy php.ini-xxx to php.ini
  • enable below extension for mysql
    extension=php_curl.dll
    extension=php_gd2.dll
    extension=php_mbstring.dll
    extension=php_mysqli.dll
    extension=php_openssl.dll
    extension=php_pdo_mysql.dll
    extension=php_pgsql.dll
    

    portable nmp stack on msys

adding portable nmp stack setting in portabledevops

# portable nginx 
if [ -d $PORTABLEPATH/nginx ]; then
	export PATH=$PORTABLEPATH/nginx:$PATH
	alias nginxstart='cd $PORTABLEPATH/nginx; ./nginx'
	alias nginxstop='cd $PORTABLEPATH/nginx; ./nginx -s stop'
fi

# portable php
if [ -d $PORTABLEPATH/php ]; then
	export PATH=$PORTABLEPATH/php:$PATH
	alias phpcgi='cd $PORTABLEPATH/php; ./php-cgi -b 127.0.0.1:9000 -c ./php.ini'
fi

# portable mysql
if [ -d $PORTABLEPATH/mysql ]; then
	export PATH=$PORTABLEPATH/mysql/bin:$PATH
	alias mysqldstart='cd $PORTABLEPATH/mysql/bin; ./mysqld --console'
	alias mysqldstop='mysqladmin shutdown -u root -p'
fi

alias nmpstart='source $PORTABLEPATH/nginx/nmp_start.sh'
alias nmpstop='source $PORTABLEPATH/nginx/nmp_stop.sh'

nmp start batch

nmp_start.sh 

#!/usr/bash
# nginx + php + mysql start script

echo 'starting nginx 1.11 ...'
nginxstart &

echo 'starting php-cgi 7 ...'
phpcgi &

echo 'starting mysql 5.7 ...'
mysqldstart &

nmp stop batch

nmp_stop.sh 

#!/usr/bash
# nginx + php + mysql stop script

echo 'stopping nginx 1.11 ...'

npid=$(ps -ef|grep -i "nginx"|awk '{print $2}')
if [ -z "$npid" ]; then 
	echo 'nginx is not running!'
else
	nginxstop
fi 

echo 'stopping php-cgi 7 ...'

ppid=$(ps -ef|grep -i "php-cgi"|awk '{print $2}')
if [ -z "$ppid" ]; then 
	echo 'php-cgi is not running!'
else
	kill $ppid
fi

echo 'stopping mysqld 5.7 ...'

mpid=$(ps -ef|grep -i "mysqld"|awk '{print $2}')
if [ -z "$mpid" ]; then 
	echo 'mysqld is not running!'
else
	mysqldstop
fi 

portable nmp verification test

nmp stack startup

$ nmpstart
starting nginx 1.11 ...
starting php-cgi 7 ...
starting mysql 5.7 ...

verify running process

$ tasklist |egrep -i "nginx|php-cgi|mysqld"
mysqld.exe                   13496 Console                    1    148,840 K
php-cgi.exe                  11744 Console                    1     34,152 K
nginx.exe                     8200 Console                    1     10,636 K
nginx.exe                    13744 Console                    1      8,584 K

$ ps -ef|egrep -i "nginx|php|mysqld"
 user   14284   13120 cons0    07:19:40 /l/portabledevops/php/php-cgi
 user   13304   13120 cons0    07:19:41 /l/portabledevops/mysql/bin/mysqld
 user   12420   13120 cons0    07:19:40 /l/portabledevops/nginx/nginx
 

verify web Server

$ curl http://localhost/site1/                                   
<!DOCTYPE html>                                                  
<html>                                                           
<head>                                                           
<title>Welcome to nginx site1.com!</title>                       
<style>                                                          
    body {                                                       
        width: 35em;                                             
        margin: 0 auto;                                          
        font-family: Tahoma, Verdana, Arial, sans-serif;         
    }                                                            
</style>                                                         
</head>                                                          
<body>                                                           
<h1>Welcome to nginx site1.com!</h1>                             
</body>                                                          
</html>                                                          

verify mysql connection

www/site1/dbtest.php
<?php
$servername = "localhost";
$username = "root";
$password = "shroot";
$myDB = "joke";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$myDB", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

$conn = null;
?>

$ curl http://localhost/site1/dbtest.php
Connected successfully

stop nmp stack

$ nmpstop 
stopping nginx 1.11 ...
stopping php-cgi 7 ...
stopping mysqld 5.7 ...
Enter password: ******
2016-10-31T13:42:47.669123Z 0 [Note] L:\portabledevops\mysql\bin\mysqld.exe: Normal shutdown
...
2016-10-31T13:42:49.949123Z 0 [Note] L:\portabledevops\mysql\bin\mysqld.exe: Shutdown complete