Quick VPS Configuration with Minstall
Backup 32MB.ORG to Dropbox
pre tag here, meanwhile you can download the script here.
Save the script as DropboxBackup.sh chmod +x and run it as root. If you want to automate it, create new Crontab as follow:
$ crontab -e # m h dom mon dow command 0 0 1 * * /bin/bash /path/to/DropboxBackup.shThat will auto backup-ing your specified folder once in a month.
Building 32MB.ORG Pt. 3: Setting Up Virtual Host for Your Domain
Now we have a working web server with PHP-CGI and SQLite installed, and it's running pretty well with less than 20 MB RAM used. Don't know how to squeeze more RAM usage, but I think less than 32 MB is enough. We need to add a domain, so we can have a fully working blog. I don't think DNS server will fit this VPS, so I'm using another VPS as my DNS server and point the A record to my IP. Lighttpd supports both Name-based and IP-based virtual hosts. Here's how I add a virtual host to Lighttpd:
1. After login to your VPS and becoming root, create a directory for your domain. I'm using 32mb.org for example, so I created 32mb.
mkdir -p /home/lighttpd/32mb mkdir -p /home/lighttpd/32mb/public2. Setup a public directory owner to web server user, lighttpd or www-data.
chown lighttpd:lighttpd /home/lighttpd/32mb/public3. In case you forgot, allow a web server user to access our logs.
chown -R lighttpd:lighttpd /var/log/lighttpd4. Open Lighttpd Configuration file.
nano /etc/lighttpd/lighttpd.conf5. Add support for your domain, put it at the end of the file.
$HTTP["host"] =~ "(^|\.)32mb\.org$" {
server.document-root = "/home/lighttpd/32mb/public"
accesslog.filename = "/var/log/lighttpd/32mb/access.log"
server.error-handler-404 = "/e404.php"
}
That's means:
- $HTTP["host"] =~ "(^|\.)32mb\.org$" - It will match request for both www.32mb.org and 32mb.org
- server.document-root = "/home/lighttpd/32mb/public" - Server document root. You must set ftp/ssh user home directory to this root only
- accesslog.filename = "/var/log/lighttpd/32mb/access.log" - Server error log file
- server.error-handler-404 = "/e404.php" - Web server error 404 handler file
/etc/init.d/lighttpd restart7. Remember to point your domain A record to your VPS IP. Test. 8. Done. Now we have a fully working domain pointed to our VPS.
Building 32MB.ORG Pt. 2: Installing Lighttpd, SQLite, and PHP
andri@32mb:~$ pstree
init-+-cron
|-dropbear---dropbear---sh---pstree
|-kthreadd/708---khelper/708
|-lighttpd---php5-cgi---4*[php5-cgi]
`-sendmail-mta
After preparing my new box, next step is installing SQLite:
apt-get install sqlitethen Lighttpd:
apt-get install lighttpdinstall the PHP scripting language and its supporting files:
apt-get install php5-cgi php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsledit the
php.ini file:
nano /etc/php5/cgi/php.iniscroll down through the text of the php.ini file until you come to a line beginning with
cgi.fix_pathinfo (use ctrl+w for search), uncomment the line so it look like this:
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. $ ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not $ ; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Se$ ; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A sett$ ; of zero causes PHP to behave as before. Default is 1. You should fix your s$ ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED. ; http://php.net/cgi.fix-pathinfo cgi.fix_pathinfo = 1Next step is add a user to the system which the Lighttpd server can use. This is performed as a standard UNIX useradd procedure as follows:
useradd -d /home/lighttpd -m -s /bin/bash lighttpdnow, open the
lighttpd.conf configuration file:
nano /etc/lighttpd/lighttpd.confAdd
mod_fastcgi and uncomment mod_rewrite in case we need it. File will look like this:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
"mod_fastcgi",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "lighttpd"
server.groupname = "lighttpd"
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
" index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
include_shell "/usr/share/lighttpd/use-ipv6.pl"
dir-listing.encoding = "utf-8"
server.dir-listing = "enable"
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/bin/php5-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "4",
"PHP_FCGI_MAX_REQUESTS" => "1000"
),
)))
Save ctrl+o and close ctrl+x, and then change the lighttpd log folder owner to lighttpd:
chown -R lighttpd:lighttpd /var/log/lighttpdcheck if Lighttpd process with
pidof lighttpd, if a number, or series of numbers show up, then it means Lighttpd is currently running. In this case, restart Lighttpd for the new configurations to take effect:
/etc/init.d/lighttpd restartIf Lighttpd isn't running already, start it by entering the following:
/etc/init.d/lighttpd startpoint your browser to your VPS IP, see if its working.
That should be it, now we need a working domain for our blog id. Will talk about it on the next post.
Building 32MB.ORG Pt. 1: Preparing the Box
apt-get update && apt-get -y upgrade and installing Nano, Localpurge and Dropbear apt-get -y install nano localepurge dropbear I removed following process:
/etc/init.d/saslauthd stop /etc/init.d/apache2 stop /etc/init.d/xinetd stop /etc/init.d/samba stop /etc/init.d/bind9 stop /etc/init.d/ssh stopand prevent them to run on restart/start-up:
update-rc.d saslauthd remove update-rc.d apache2 remove update-rc.d xinetd remove update-rc.d samba remove update-rc.d bind9 remove update-rc.d ssh removeStart Dropbear as a replacement for OpenSSH, make it running by default by changing its config:
nano /etc/default/dropbearset NO_START=1 to NO_START=0 and add some config for security, change the port and prevent root login:
# disabled because OpenSSH is installed change to NO_START=0 to enable Dropbear NO_START=1 ;change to 0 # the TCP port that Dropbear listens on DROPBEAR_PORT=22 ;change to whatever port you want # any additional arguments for Dropbear DROPBEAR_EXTRA_ARGS="" ;add -w to prevent root loginYou can also replace Syslog by Syslog-ng:
/etc/init.d/syslog stop update-rc.d syslog remove apt-get install -y syslog-ng
After reboot you will have a box running by (not more than) 10MB RAM.
Done for now, next post will be installing Lighttpd, PHP, and SQLite, and then Blite! itself.



