Administration
Articles related to Server Administration
OpenSSL loading openssl.cnf
Feb 8th
since the openssl.cnf path is hardcoded in binaries. to alter it on windows set environmental variable (as written):
OPENSSLDIR=C:\PATH\TO\OpenSSL\bin OPENSSL_CONF=C:\PATH\TO\OpenSSL\bin\openssl.cnf
OPENSSL_CONF doesn’t work without OPENSSLDIR even if it is set.
settings these options will allow you to use your custom configuration files when creating certificates.
batch file i use to create certificate
GenCERT.bat [save this file to OpenSSL bin directory]
@echo off md %1 openssl genrsa -des3 -out %1/%1.key 1024 openssl req -new -key %1/%1.key -out %1/%1.csr copy %1/%1.key %1/%1.key.org openssl rsa -in %1/%1.key.org -out %1/%1.key openssl x509 -req -days 365 -in %1/%1.csr -signkey %1/%1.key -out %1/%1.crt openssl x509 -outform der -in %1/%1.crt -out %1/%1.der
Sample
:: Start command line and cd to C:\PATH\TO\OpenSSL\bin :: :: usage: GenCERT.bat domain.com :: GenCERT.bat teknober.com
Batch file I use to create SSL certificate for Web etc server
GenPEM.bat [save this file to OpenSSL bin directory]
@echo off mkdir %1 openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout %1/%1.pem -out %1/%1.pem -config "%1/%1.cfg"
Sample
:: Start command line and cd to C:\PATH\TO\OpenSSL\bin :: :: usage: GenPEM.bat domain.com :: GenPEM.bat teknober.com
for sample ssl configuration file see the bottom of the page: http://www.openssl.org/docs/apps/ca.html
VMWare on Debian 6 with Linux-Kernel-2.6.32-5
Jan 7th
Installing VMware WorkStation 8 on Debian 6 with Linux-Kernel-2.6.32-5 AMD64
error log: Can’t locate linux headers
apt-get install linux-headers-2.6.32-5-all apt-get install linux-headers-2.6.32-5-all-amd64 apt-get install linux-headers-2.6.32-5-common
error log: Can’t get required utilities make, tar, echo, grep, rmmod, insmod
apt-get install dpkg-dev
Compile vmware modules before running.
PHP PDO using Transactions with TModel::GenerateStatement functions
Sep 9th
Only have an example to show using the TModel::GenerateInsertStatement, TModel::GenerateUpdateStatement, TModel::GenerateReplaceStatement
In database driver settings for mysql innodb engine, mariadb aria engine: SET AUTOCOMMIT=0;
sample:
public function panel_set_category_enabled($id_category) {
/* start a transaction */
$this->model->beginTransaction();
/* set: populate related columns */
$columns = array();
$columns[] = new TModelColumn("enabled", 1, PDO::PARAM_INT);
$columns[] = new TModelColumn("date_update", TDate::getDATE_MYSQL(time()), PDO::PARAM_STR);
/* execute and return result */
$result = TModel::generateUpdateSet("tc_category", $columns, new TModelWhere("id", $id_category, PDO::PARAM_INT, null, "="), true);
if ($result) {
$this->model->commit();
return $result;
} else {
$this->model->rollBack();
return $result;
}
}
related articles on this blog:
PHP PDO Generate Insert Statement:
http://blog.teknober.com/2011/03/06/php-pdo-generate-insert-statement/
PHP PDO Generate Update Statement:
http://blog.teknober.com/2011/03/06/php-pdo-generate-update-statement/
PHP PDO Generate Replace Statement:
http://blog.teknober.com/2011/04/13/php-pdo-generate-replace-statement/
MySQL Dump using Command Line
May 16th
Simple Batch File taking database name as argument:
Ref manual: http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
dump.bat [fixed for time 0-30-32.sql was breaking the file name.]
:: Date [yy:mm:dd]
For /f "tokens=1-3 delims=/. " %%a in ('date /t') do (
set tws_date_yy=%%c
set tws_date_mm=%%b
set tws_date_dd=%%a
)
:: Time [hh:mm]
For /f "tokens=1-8 delims=/:." %%a in ('time /t') do (
set tws_time_hh=%%a
set tws_time_mm=%%b
)
:: Time [ss]
For /f "tokens=1-3 delims=/:," %%a in ("%TIME%") do (
set tws_time_ss=%%c
)
:: DateTime format
set tws_form=%tws_date_yy%-%tws_date_mm%-%tws_date_dd%_%tws_time_hh%-%tws_time_mm%-%tws_time_ss%
mysqldump.exe --skip-compact --skip-extended-insert --skip-quote-names --skip-add-locks --comments --routines --triggers --events -h 127.0.0.1 -P 3306 -u root %1 -p > %1_%tws_form%.sql
execute
dump.bat dbname
output (file): dbname-YYYY-MM-DD_HH-MM-SS.sql
modify given options for your need
HTML remove cookies from static files, images etc
Mar 24th
If you have not configured your application and server, it might send them to browser with cookie information.
that’s costing you as extra traffic and slow load times.
<FilesMatch "\.(css|js|jpg|jpeg|png|gif)$">
<IfModule mod_headers.c>
Header set cookie ""
</IfModule>
</FilesMatch>
Apache Configuration for Multiple Domains
Feb 2nd
Here is a sample configuration for Apache on Windows.
Configuration files are loaded separately. You can download all configuration here.
httpd.conf
#------------------------------------------------------------------------------
# ServerRoot
#------------------------------------------------------------------------------
ServerRoot "D:/Httpd"
#------------------------------------------------------------------------------
# HTTP
#------------------------------------------------------------------------------
Listen 192.168.1.30:80
#------------------------------------------------------------------------------
# SVN
#------------------------------------------------------------------------------
Listen 192.168.1.20:8443
Listen 192.168.1.30:8443
#------------------------------------------------------------------------------
# Modules
#------------------------------------------------------------------------------
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
#LoadModule authn_alias_module modules/mod_authn_alias.so
#LoadModule authn_anon_module modules/mod_authn_anon.so
#LoadModule authn_dbd_module modules/mod_authn_dbd.so
#LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authn_file_module modules/mod_authn_file.so
#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
#LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
#LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cache_module modules/mod_cache.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule charset_lite_module modules/mod_charset_lite.so
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dav_lock_module modules/mod_dav_lock.so
#LoadModule dbd_module modules/mod_dbd.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule disk_cache_module modules/mod_disk_cache.so
#LoadModule dumpio_module modules/mod_dumpio.so
LoadModule env_module modules/mod_env.so
LoadModule expires_module modules/mod_expires.so
#LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
#LoadModule ident_module modules/mod_ident.so
#LoadModule imagemap_module modules/mod_imagemap.so
LoadModule include_module modules/mod_include.so
LoadModule info_module modules/mod_info.so
LoadModule isapi_module modules/mod_isapi.so
#LoadModule ldap_module modules/mod_ldap.so
LoadModule logio_module modules/mod_logio.so
LoadModule log_config_module modules/mod_log_config.so
#LoadModule log_forensic_module modules/mod_log_forensic.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so
#LoadModule substitute_module modules/mod_substitute.so
#LoadModule unique_id_module modules/mod_unique_id.so
#LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule version_module modules/mod_version.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
#------------------------------------------------------------------------------
# User - Group
#------------------------------------------------------------------------------
<IfModule !mpm_netware_module>
<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>
</IfModule>
#------------------------------------------------------------------------------
# Main Server Configuration
#------------------------------------------------------------------------------
ServerAdmin catch-all@mydomain.com
ServerName 192.168.1.30:80
#------------------------------------------------------------------------------
# Document Root
#------------------------------------------------------------------------------
DocumentRoot "D:/WorkSpace"
#------------------------------------------------------------------------------
# Default Directory Settings
#------------------------------------------------------------------------------
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
#------------------------------------------------------------------------------
# Default Directory
#------------------------------------------------------------------------------
<Directory "D:/WorkSpace">
#--------------------------------------------------------------------------
# Options Directive
# All ExecCGI FollowSymLinks Includes IncludesNOEXEC Indexes
# MultiViews SymLinksIfOwnerMatch
#--------------------------------------------------------------------------
Options Indexes FollowSymLinks ExecCGI
#--------------------------------------------------------------------------
# Allow Override Directive
# All AuthConfig FileInfo Indexes Limit None
#--------------------------------------------------------------------------
AllowOverride All
#--------------------------------------------------------------------------
# Controls who can get stuff from this server.
#--------------------------------------------------------------------------
Order allow,deny
Allow from all
</Directory>
#------------------------------------------------------------------------------
# Directory Index
#------------------------------------------------------------------------------
<IfModule dir_module>
DirectoryIndex index.html index.php index.cgi
</IfModule>
#------------------------------------------------------------------------------
# Protect .htaccess and .htpasswd
#------------------------------------------------------------------------------
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
#------------------------------------------------------------------------------
# Error Logging
#------------------------------------------------------------------------------
ErrorLog "D:/WebTemp/Apache-Logs/error.log"
#------------------------------------------------------------------------------
# Error Logging Level
# debug, info, notice, warn, error, crit, alert, emerg
#------------------------------------------------------------------------------
LogLevel crit
#------------------------------------------------------------------------------
# Error Logging Configuration
#------------------------------------------------------------------------------
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{User-Agent}i\"" mydomain
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
</IfModule>
<IfModule alias_module>
#--------------------------------------------------------------------------
# Redirect
# Allows you to tell clients about documents that used to exist in your
# server's namespace, but do not anymore. The client will make a new
# request for the document at its new location.
#--------------------------------------------------------------------------
# Redirect permanent /foo http://mydomain.com/bar
#--------------------------------------------------------------------------
# Alias
# Maps web paths into filesystem paths and is used to access content that
# does not live under the DocumentRoot.
#--------------------------------------------------------------------------
# Alias /webpath /full/filesystem/path
#--------------------------------------------------------------------------
# ScriptAlias: This controls which directories contain server scripts.
#--------------------------------------------------------------------------
# ScriptAlias /cgi-bin/ "D:/Httpd/cgi-bin/"
</IfModule>
<IfModule cgid_module>
#--------------------------------------------------------------------------
# ScriptSock
# On threaded servers, designate the path to the UNIX socket used to
# communicate with the CGI daemon of mod_cgid
#--------------------------------------------------------------------------
# Scriptsock logs/cgisock
</IfModule>
#------------------------------------------------------------------------------
# "D:/Httpd/cgi-bin" should be changed to whatever your ScriptAliased CGI
# directory exists, if you have that configured.
#------------------------------------------------------------------------------
<Directory "D:/Httpd/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
#------------------------------------------------------------------------------
# Default MIME Type
#------------------------------------------------------------------------------
DefaultType text/plain
<IfModule mime_module>
#--------------------------------------------------------------------------
# Mime Type Configuration
#--------------------------------------------------------------------------
TypesConfig conf/mime.types
#--------------------------------------------------------------------------
# AddType
# Allows you to add to or override the MIME configuration file specified
# in TypesConfig for specific file types.
#--------------------------------------------------------------------------
#AddType application/x-gzip .tgz
#--------------------------------------------------------------------------
# Add Encoding
# Allows you to have certain browsers uncompress information on the fly.
# Note: Not all browsers support this.
#--------------------------------------------------------------------------
# AddEncoding x-compress .Z
# AddEncoding x-gzip .gz .tgz
#--------------------------------------------------------------------------
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#--------------------------------------------------------------------------
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#--------------------------------------------------------------------------
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi .pl
# For type maps (negotiated resources):
#AddHandler type-map var
#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
#AddType text/html .shtml
#AddOutputFilter INCLUDES .shtml
</IfModule>
#------------------------------------------------------------------------------
# The mod_mime_magic module allows the server to use various hints from the
# contents of the file itself to determine its type. The MIMEMagicFile
# directive tells the module where the hint definitions are located.
#------------------------------------------------------------------------------
#MIMEMagicFile conf/magic
#------------------------------------------------------------------------------
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#------------------------------------------------------------------------------
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://mydomain.com/subscription_info.html
#------------------------------------------------------------------------------
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall is used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
#------------------------------------------------------------------------------
#EnableMMAP off
#EnableSendfile off
#------------------------------------------------------------------------------
# Supplemental configuration
#------------------------------------------------------------------------------
Include conf/extra/enabled.*.conf
# Virtual Hosts
<IfModule vhost_alias_module>
Include conf/vhost/enabled.*.conf
</IfModule>
# Secure (SSL/TLS) connections
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
SSLPassPhraseDialog builtin
SSLSessionCache "shm:D:/WebTemp/SSL-Cache"
SSLSessionCacheTimeout 300
SSLMutex default
</IfModule>
#------------------------------------------------------------------------------
# PHP Module (Optional)
#------------------------------------------------------------------------------
#PHP 5.3.3
#PHPIniDir "D:/PHP/PHP-5.3.3-VC6/"
#LoadModule php5_module "D:/PHP/PHP-5.3.3-VC6/php5apache2_2.dll"
#PHP 5.3.1
#PHPIniDir "D:/PHP/PHP-5.3.1-VC6/"
#LoadModule php5_module "D:/PHP/PHP-5.3.1-VC6/php5apache2_2.dll"
#PHP 5.2.12
#PHPIniDir "D:/PHP/PHP-5.2.12_VC6/"
#LoadModule php5_module "D:/PHP/PHP-5.2.12-VC6/php5apache2_2.dll"
# PHP MimeType
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
#------------------------------------------------------------------------------
# Perl Module (Optional)
#------------------------------------------------------------------------------
#LoadFile "D:/Perl/bin/perl512.dll"
#LoadModule perl_module modules/mod_perl.so
# Perl Handler
#AddHandler cgi-script .cgi pl
#ScriptInterpreterSource Registry-Strict
DNS SPF and DomainKey record
Jan 30th
This script helps you to generate DNS SPF records and DKIM Keys.
Requires: openssl installed and configured
How to execute
GenDKIM.bat selector mydomain.com
GenDKIM.bat
@echo off openssl genrsa -out %2.private 1024 openssl rsa -in %2.private -out %2.public -pubout -outform PEM GenDKIM.vbs %1 %2
GenDKIM.vbs
' Generate DKIM for DNS
If (Wscript.Arguments.Count < 2) Then
Wscript.Echo "missing arguments" & vbCrLf & "usage: GenDKIM.vbs selector domain.com"
Wscript.Quit(-1)
End If
Const ForReading = 1
Const ForWriting = 2
' create file object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' open public key file
Set objPublic = objFSO.GetFile(Wscript.Arguments(1) & ".public")
' check file has content
If objPublic.Size > 0 Then
' open file for reading
Set objReadFile = objFSO.OpenTextFile(Wscript.Arguments(1) & ".public", ForReading)
' create output file
Set ojbWrteFile = objFSO.OpenTextFile(Wscript.Arguments(1) & ".public.dns", ForWriting, TRUE)
' replace content
strContents = Trim(objReadFile.ReadAll)
srtContents = ReplaceTest(strContents, "-----BEGIN PUBLIC KEY-----", "")
srtContents = ReplaceTest(strContents, "-----END PUBLIC KEY-----", "")
srtContents = ReplaceTest(strContents, "\n", "")
' write SPF (You can add IPV4|IPV6)
ojbWrteFile.Write "_domainkey @ 86400 TXT ( ""v=spf1 a mx ptr ?all"" )"
' write DomainKey
ojbWrteFile.Write "_domainkey @ 86400 TXT ( ""t=y; o=~;"" )"
ojbWrteFile.Write Wscript.Arguments(0) & "._domainkey @86400 TXT ""k=rsa; p=" & srtContents & """"
' close files
objReadFile.Close
ojbWrteFile.Close
Else
Wscript.Echo "The file is empty."
End If
' success
WScript.Quit(0)
' regex function
Function ReplaceTest(str, patrn, replStr)
Dim regEx
' Create regular expression.
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
' Make replacement.
While regEx.Test(str)
str = regEx.Replace(str, replStr)
Wend
ReplaceTest = str
End Function
SVN Install on Apache on Windows
Jan 30th
Download apache 2.2.x.zip [or msi package] extract it to C:/SVN
Download and install Subversion 1.6.x C:/Subversion and copy svn modules for apache into SVN/modules directory
Append Subversion/bin directory to Windows PATH
Configure your Apache-SVN Server referring to following configuration sample [uses SSL]
And don’t forget to read SVN Administration Guide
ASP.Net Temporary Files Path
Jan 28th
To change “Temporary ASP.NET Files”:
go to %WINDIR%\Microsoft.NET\Framework\v2.0.50727\CONFIG\
-> open machine.config
-> add the following line to section
<system.web>
<compilation tempDirectory="C:\WebTemp\" />
</system.web>
-> save and close the file
-> restart IIS.


LinkedIn
Twitter
Skype