Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

List IP Addresses Connected and Number of Connections (plain)

1
netstat -plan | grep :80 | awk {'print $5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1
comments (1) flag fork

List Processes Listening on Port 443 (plain)

1
lsof -nPi :443
comments (1) flag fork

Display PHP-FPM pools / processes (plain)

1
ps aux | grep -i fpm
comments (0) flag fork

PHP-FPM Sample Pool Config (say for Nginx Vhost mail.domain.com) (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[www-mail]
listen = /tmpfpm/prod/mail/php-fpm.sock
;listen.allowed_clients = 127.0.0.1
listen.owner = nobody
listen.group = nobody
listen.mode = 0666
user = nobody
group = nobody
pm = dynamic
pm.max_children = 39
pm.start_servers = 11
pm.min_spare_servers = 9
pm.max_spare_servers = 13
pm.max_requests = 130
;access.log = /var/log/php/fpm-mail-access.log
;access.format = %R - %u %t "%m %r%Q%q" %s %f %{mili}d %{kilo}M %C%%

; --- Enable the value below for debugging. Otherwise leave it off.
;catch_workers_output = yes

; --- Notice these php values that are normally set in PHP.INI
; --- These values below override the php.ini global values
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/php/fpm-mail-error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 64M
[+] (22) more...
comments (1) flag fork

Hide index.php in URL (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# --- Perform 301 canonical redirect to remove index.php
    location ^~ /index.php {
        rewrite ^/index.php(.*)$ $scheme://$server_name$1 permanent;
    }

# --- catch-all location block for all other URLs
    location / {

# --- note: do not add "$uri/" before @handler, if you have an "index index.php" directive, it will auto redirect to "index.php" and cause an infinite loop due to the location block above
        try_files $uri @handler;

# --- The 2 lines below are for htaccess
        auth_basic            "Restricted";
        auth_basic_user_file  /etc/nginx/web/htpasswd;
    }

# --- internally add index.php back to the request
    location @handler {
        rewrite ^ /index.php$uri break;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/tmpfpm/staging/php-fpm.sock;
        fastcgi_read_timeout 5m;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/web/public_html$fastcgi_script_name;
    }
[+] (21) more...
comments (0) flag fork

Nginx VHost Example (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ----------------------------------------------------------- #
# This config redirects mail.domain.com to www.domain.com
# The rewrite rule can be taken out and actually server mail.domain.com
# Notice a socket connection is used for fastcgi ... this is better than using a TCP connection for performance. However PHP-FPM needs to be configured first so that those socket connections exist!!
# ----------------------------------------------------------- #
server {
    listen 0.0.0.0:80;
    server_name mail.domain.com;
    access_log off;
    error_log /var/log/nginx/mail-error.log debug;
    root /home/mail/public_html;

    location / {
        index index.php;
        rewrite ^/ http://www.domain.com/;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/tmpfpm/prod/mail/php-fpm.sock;
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_read_timeout 5m;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/mail/public_html$fastcgi_script_name;
    }
        location ~ /\.ht* {
                deny  all;
        }
}
[+] (25) more...
comments (0) flag fork

Display Nginx Process and Workers (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
ps aux | grep nginx

# should show you something like this:
# root      5151  0.0  0.2 100128 58392 ?        Ss   Feb22   0:05 nginx: master process
# /usr/local/sbin/nginx -c /etc/nginx/nginx.conf
# nobody   19980  0.0  0.2 102828 62492 ? S    May03   6:12 nginx: worker process                        
# nobody   19981  0.0  0.2 102316 61908 ? S    May03   6:17 nginx: worker process                        
# nobody   19982  0.0  0.2 106484 64968 ? S    May03   6:30 nginx: worker process                        
# nobody   19983  0.0  0.2 102828 62012 ? S    May03   6:05 nginx: worker process                        
# nobody   19984  0.0  0.2 102572 62016 ? S    May03   6:18 nginx: worker process                        
# nobody   19985  0.0  0.2 102060 61876 ? S    May03   6:31 nginx: worker process

Notice there's 6 worker processes. The number of workers is set in nginx.conf
[+] (9) more...
comments (0) flag fork

Reload Nginx (plain)

1
2
3
4
5
6
7
8
9
# Test your config changes first before reloading the config with: nginx -t
# Reload Nginx Config:
nginx -s reload
# OR
/etc/init.d/nginx reload
# OR get the process id of the NginX Master process:
ps aux | grep nginx
# And lets say in this case, the Master PID = 15465, then reload the NginX process like so:
kill -HUP 15465
[+] (5) more...
comments (1) flag fork

Nginx CLI (plain)

1
2
3
4
5
6
# Display Nginx Command Line Options
nginx -h
# Display Nginx installed version
nginx -v
# TEST nginx config... ALWAYS do this before applying any config changes!!!
nginx -t
[+] (2) more...
comments (1) flag fork

Change BinLog Format on Live Master DB (plain)

1
2
3
4
5
6
FLUSH TABLES WITH READ LOCK;
FLUSH LOGS;
SET GLOBAL binlog_format = 'MIXED'; /*possible values: STATEMENT, ROW, MIXED*/
FLUSH LOGS;
UNLOCK TABLES;
RESET MASTER; /*This starts the Master over again with new bin log format*/
[+] (2) more...
comments (2) flag fork

Show Locked Tables (plain)

1
2
3
4
/* Display all locked / unlocked tables */
SHOW OPEN TABLES;
/* Display table locks in specific DB */
SHOW OPEN TABLES FROM databaseName WHERE In_use <> 0;
comments (1) flag fork

Generate OPTIMIZE statements for any Fragmented tables (plain)

1
2
3
SELECT CONCAT('optimize table ', table_schema, '.', table_name, ';')
FROM information_schema.tables WHERE table_schema
NOT IN ('information_schema','mysql') AND data_free > 0 ORDER BY table_schema, data_free DESC;
comments (1) flag fork

Find MyISAM tables larger than 4 Gigs (plain)

1
2
3
4
5
SELECT table_schema,table_name,table_type,engine,table_rows,data_length/1024/1024/1024 as "size - Gigs"
FROM information_schema.tables
WHERE engine='MyISAM'
AND data_length > 536870912
ORDER BY table_schema,table_rows DESC;
[+] (1) more...
comments (1) flag fork

Redirect All Unserveable Requests to Index (plain)

1
2
3
4
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
comments (1) flag fork

Redirect to HTTPS (plain)

1
2
3
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
comments (1) flag fork

Capture enter key on input elements (plain)

1
2
3
4
5
6
7
$("#login_email, #login_password").keyup(function(e)
{
    var code = e.keyCode || e.which;
    e.preventDefault();

    if(code == 13) login();
});
[+] (3) more...
comments (0) flag fork

ORDER BY with custom (plain)

1
2
3
4
/* place at bottom */
SELECT * FROM categories ORDER BY name='Other', name ASC;
/* place at top */
ORDER BY FIELD(name, 'English/US', 'English/UK', name), name ASC;
comments (0) flag fork