Thursday 2 March 2017

Hosting Angular website using S3 maintaining routes, without s3 access denied error

Hi,

So you hosted your Angular website in s3

Application work fine but in middle of any page if user hit Ctrl+ F5 or Reload angular app , S3 respond it with 403 forbidden.


Below are the step to fix the access denied error with S3 hosting Angular App.

  1. Navigate to Edit Distribution
  2. Navigate to Error Pages Pane
  3. Add new "Create Custom Error Response"
  4. Select Error code to 403 forbidden 
  5. Caching Minimum TTL to 0
  6. Customize Error Response to Yes
  7. Response Page path "/Index.html"  {Entry page for angular including '/'}
  8. HTTP Response Code to 200:OK
  9. Invalidate the Cloudfront Cache
  10. Wait for some time and reload in browse to test it :)





















Hope this will help



Wednesday 16 November 2016

NginX and Aungular js : Manully type url or page refresh then throw 404 error but routing works

Problem : We have website www.xyz.com - when we hit this browser redirect to www.xyz.com/login but if we refresh page or manully type url www.xyz.com/login  server throw 404 error.
or  say
page refresh give 404 error


Solution: Nigix conf  just above the close curly bracket add
error_page 404 =200 /index.html;

Sample
server {
    listen       80;
        root   /var/www;
    location / {
    }
    error_page 404 =200 /index.html;
}


We are changing response code to 200 ok and redirecting user to index.html which is our default home page :)

Source
http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page

Wednesday 17 August 2016

How To : AWS RDS Mysql Query cache

In this post we learn how Mysql Query cache work , There is lot of information is available on net but basic info is not shared (or may be i am not able to find) on net which might help beginner users like how much query_cache_size .

The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again. The query cache is shared among sessions, so a result set generated by one client can be sent in response to the same query issued by another client. 
The query cache can be useful in an environment where you have tables that do not change very often and for which the server receives many identical queries. This is a typical situation for many Web servers that generate many dynamic pages based on database content. 
The query cache does not return stale data. When tables are modified, any relevant entries in the query cache are flushed.


Query cache :

  • Only cache the select statement
  • Do not cache if select statement used as subquery,inline views or parts of the UNION or stored procedure using select.
  • Invalidate cache if data is modified 
  • Do not cache Non-deterministic functions such as UUID(), RAND(), CONNECTION_ID() etc 


Lets say you have query which takes approx 20 sec to display 1 million data so 1st time it take 20 sec and 2nd time it take 0.20 ms to display 1 million data but if data is changed the again in 3rd time it take 20 sec.
So database should be properly normalized to make use of this feature ,

Let say you are running article site then you also storing number of hits on same table then every time after selecting data you are updating the hit counter too in that situation Query cache is no use and mysql always return updated data.

As per net any non zero value should work for query_cache_size and no clear info is found in net what should be ideal minimum size in Mysql forum and RDS forums.
If you define too low value then  qcache_hits is always 0 with RDS, So it should be minimum 65 kb (65536)  to work

For 8 GB Instance  1000 MB of DB size

query_cache_size : 24000000  this means 24 MB Approx

For 16 GB Instance  1000 MB of DB size

query_cache_size : 64000000  this means 64 MB Approx

In RDS You cant define like 24M so you need to convert it to bytes and put that value.



Parameter Variable16 GB8 GB
query_alloc_block_size
(Allocation size of memory blocks that are allocated for objects,
increase this parameter to deal with memory fragmentation)
81928192
query_cache_limit
(Do not cache results/record-set /result-set that are larger than this
number of bytes.
Default is 1MB [1048576])
10485761048576
query_cache_min_res_unit  (4kb Default,Minimum allocation size)40964096
query_cache_size
(This is the RAM or memory which need to be allocated) , 0 to disable it
In RDS when we set it to 65536 it start caching the queries
3355443225165824
query_cache_type
0 : Don't cache results in or retrieve results from the query cache.
1 : Cache all query results except for those that begin with SELECT S_NO_CACHE.
2 : Cache results only for queries that begin with SELECT SQL_CACHE
11
query_cache_wlock_invalidate
0 : Client will get old data when table is locked for write
1 : Client will wait untill loack is opened and recive latest data
OFFOFF
query_prealloc_size
(
persistent buffer for memory allocation)
81928192



Status16 GB8GB
Qcache_free_blocks251984
Qcache_free_memory7707763766104
Qcache_hits
Number of select served by cache
181587136941
Qcache_inserts 
Number of cache Queries
3824584376
Qcache_lowmem_prunes
Queries that were deleted from
the cache because of low memory
Tip : Increase cache_size
2539143258
Qcache_not_cached
Number of Queires which are excluded due to query_cache_type setting
6105878150
Qcache_queries_in_cache
Number of queries active in cache
7393197
Qcache_total_blocks19857781



Source
http://dev.mysql.com/doc/refman/5.7/en/query-cache.html
https://www.percona.com/blog/2006/07/27/mysql-query-cache/

Thursday 23 June 2016

550 CHMOD 666 *.php: Operation not permitted - proftpd

ProFTPd version 1.34 - Giving write permission to certain folder /directory in Linux centos 6.7


Issue : Allow write access to one user and Deny for all.

<Directory /var/www/uploads/*>
<Limit WRITE>
DenyAll
AllowUser FtpUserName
</Limit>
<Limit SITE_CHMOD>
DenyAll
AllowUser FtpUserName
</Limit>
</Directory>


If we do not define DenyAll and Deny ftpusername it will throw the error like

550 CHMOD 666 *.php: Operation not permitted if file permission is tried to change
or
Critical file transfer error  if file upload or transfer is initiated

Note : Deny Clause need to define else setting is not work (I do not find this on google but change only reflect once i added DENY)

Monday 20 June 2016

AWS CLI in Cent OS 6.7 with Python 2.6.6 , Python 2.7 not required for aws cli

After searching in AWS doc it says upgrade your python to 2.7 before installing aws.

However we are stuck with centos 6.7 and if we upgrade to newer version it might impact other area of our application.

So we tried to install it without upgrading

Below are the commands to install aws cli without 2.7 python as root login


  • cd /opt
  • curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
  • unzip awscli-bundle.zip  
  • sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
  • aws --version
version output

aws-cli/1.10.38 Python/2.6.6 Linux/2.6.32-573.22.1.el6.centos.plus.x86_64 botocore/1.4.28


Saturday 18 June 2016

Httpd apache Server-status via location match

Httpd Server-status via location match not working in Centos or Ubuntu 

For Server Monitoring Apache Server-status is very useful thing

However there are situation due to rewrite rules location match for Apache is not triggers or not working correctly

Spot the problem 

Confirm that in httpd.conf 

mod_status.so  should not be commented

Incorrect
#LoadModule status_module modules/mod_status.so

Correct (remove the # to uncomment)
LoadModule status_module modules/mod_status.so

If its already un-commented then check your rewrite rule if they overriding the location setting ?

How to check : You can check by simply http://yourip/server-status if it not display some stat regarding Apache and redirect to your website then rewrite rules are overriding 


Solution ?

Update your location path in your conf it might be httpd.conf or any other location
Note : This can be placed in last line of the conf file out of any <VirtualHost></VirtualHost> tags

<Location "/server-status.monitor">
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from <your pubic ip>
</Location>

Find the section where css,js and images are excluded from rewrite rule this rule can be found in httpd.cof or  .htaccess of your website

RewriteCond %{REQUEST_URI} !^(.*).(css|js|gif|png|jpg|jpeg|swf|monitor)$

Add |monitor in the end

Restart the httpd 

Now try http://yourip/server-status.monitor






Tuesday 31 May 2016

MS Sql Server LocalDB connectivity via classic asp [Correct Connection String]

In this post I will show how to make connection string for LocalDB to use with Classic ASP ( Might also work with PHP)


After googling and visiting connection string websites I am still stuck with error like

Microsoft OLE DB Provider for SQL Server error '80040e4d'
Invalid authorization specification
/login.asp, line 19

or

Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/login.asp, line 19

or

ADODB.Connection Microsoft OLE DB Provider for ODBC Drivers error '80004005'
Microsoft OLE DB Provider for ODBC Drivers error '80004005' 
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 


Here is the list of Possible correct connection string

DSN Based  -While setup ODBC DSN I supplied Sql server authentication 




#1 Driver={SQL Server};Data Source=localsqldb;

#2 DSN=localsqldb;Uid=sa;Pwd=urpassword;

Why DNS based : I do not know but all tries were failed until i setup and made 1 successful connectivity with asp application using DSN after that other methods are also start working 

SQLOLEDB Based

#1 Windows authentication , I setup application pool and site identity to  computers username and password
 Provider=SQLOLEDB;Integrated Security=SSPI;Server=np:\\.\pipe\LOCALDB#SH5E512B\tsql\query;  


#2 Sql server authentication 

Provider=SQLOLEDB;Persist Security Info=False;Initial Catalog=urDBName;Data Source=np:\\.\pipe\LOCALDB#SH5E512\tsql\query;User Id=sa;Password=urpassword


To Setup SA for your localdb 

1. Start Navicat and login to DB via Windows authentication as i mention in my last post and run these queries


ALTER LOGIN sa ENABLE ;
GO
ALTER LOGIN sa WITH PASSWORD = 'urpassword' ;
GO


Ref -> http://stackoverflow.com/questions/26403000/how-can-i-setup-my-sql-server-localdb-to-be-as-close-to-a-normal-sql-server

Note : We have navicat so other steps shown on ref page is not required.

Regards

Tuesday 24 May 2016

LinWin - Heidisql Navicat connectivity with Microsofts' Sql server LocalDB

In this post I will show how to retrieve connection string for LocalDB to use with Database admin tools

Navicat to  LocalDB Connectivity
Heidisql  to  LocalDB Connectivity

locate SqlLocalDB.exe in win 10 64 bit its located at \Program Files\Microsoft SQL Server\120\Tools\Binn


Start cmd (open command prompt)
Navigate to ->  cd \Program Files\Microsoft SQL Server\120\Tools\Binn

If you want to create new DB then run

> SqlLocalDB create "localsql"  -- here localsql is the name for new instance

After creating DB you need to start it

> SqlLocalDB start "localsql"  -- here localsql is the name for instance which needed to be started

To get the connection string for Navicat or Heidisql

> SqlLocalDB info "localsql"

C:\Program Files\Microsoft SQL Server\120\Tools\Binn>SqlLocalDB info "localsql"
Name:               localsql
Version:            12.0.2000.8
Shared name:
Owner:              Home\DELL
Auto-create:        No
State:              Running
Last start time:    24-05-2016 01:03:05 PM
Instance pipe name: np:\\.\pipe\LOCALDB#03AD832F\tsql\query

we need to put
Instance pipe name: np:\\.\pipe\LOCALDB#03AD832F\tsql\query
to hostname in navicat or Heidisql



Enjoy :)

LinWin - The First Post Discuss as newbie

Hi Friends,

I started this blog , because i found that lots of knowledge to fix server related issue is still missing and i am bored to create account on lots of site and posting the solution which worked for me.

In this blog i will only post the solution which worked for me and my analysis As i working with E-commerce company i believe these information will beneficial to every one

Techs which is going to be covered are

  • AWS
  • Azure
  • Linux - Centos
  • Monitoring Tools 
  • Security Tools
  • SSL
  • CDN
  • Mysql
  • Ms-Sql
  • Oracle
  • DB Management Tools
  • Caching
  • Reporting
  • Development tools
In my site no registration is required for posting but i will moderate all the comments , so that we can discuss all the aspects.
Please post all the comment so that even a newbie can just copy paste the solution.

With Regards
LinWin