{"id":313,"date":"2012-12-27T14:19:00","date_gmt":"2012-12-27T06:19:00","guid":{"rendered":"http:\/\/blog.yaojun.sg\/?p=313"},"modified":"2012-12-27T14:19:00","modified_gmt":"2012-12-27T06:19:00","slug":"setting-up-a-freebsd9-1-server","status":"publish","type":"post","link":"https:\/\/blog.yaojun.sg\/?p=313","title":{"rendered":"Setting up a FreeBSD9.1 Server"},"content":{"rendered":"<p>It&#8217;s been a while since I last posted something here.<\/p>\n<p>Recently got interested in the &#8220;beastie&#8221; aka BSD one\u00a0flavor\u00a0of UNIX, not say I&#8217;m no longer loving the penguin but then it&#8217;s good to know more systems out there and FreeBSD is one of the most well know systems for stability and uptime of like 5 years without restarting. So here is how to get it up with Nginx, PHP and MySQL, running inside a VMware environment.<\/p>\n<hr \/>\n<p>The first thing to do is to get portsnap to do a update from the port tree.<\/p>\n<pre>portsnap fetch extract update<\/pre>\n<p>Most of the popular applications will be in the ports tree so most of these installation can be automated without much issues.<\/p>\n<h2>Installing VMware Tools<\/h2>\n<h3>Installing Perl5.16<\/h3>\n<pre>\/usr\/ports\/lang\/perl5.16\/\r\nmake config-recursive\r\nmake install clean<\/pre>\n<h3>Install compat6x<\/h3>\n<pre>\/usr\/ports\/misc\/compat6x\/\r\nmake config-recursive\r\nmake install clean<\/pre>\n<h3>Manual installation of 2 VMware modules<\/h3>\n<p>&#8220;Insert&#8221; the vmware tools disc, and mount using type cd9660 as such<\/p>\n<pre>mount -t cd9600 \/dev\/cd0 \/mnt<\/pre>\n<p>then access the mounted disc and copy the tool file to somewhere locally for extraction.<\/p>\n<pre>&lt;DIR&gt;vmware-tools-distrib\/lib\/modules\/source\/<\/pre>\n<p>Untar the following, make and make install them before installing the main perl script<\/p>\n<pre>vmmemctl.tar\r\nvmblock.tar<\/pre>\n<hr \/>\n<h2>Installing Bash-completion<\/h2>\n<p>Firstly will be the installation of \u00a0&#8220;bash-completion&#8221;\u00a0as I find &#8220;csh&#8221; not that friendly, plus tab-ing is the way to go&#8230; \ud83d\ude42<\/p>\n<pre>cd \/usr\/ports\/shells\/bash-completion\r\nmake config-recursive<\/pre>\n<p>No additional selections is necessary (defaults are alright)<\/p>\n<pre>make install clean<\/pre>\n<p>Then you have to change the default shell of the user by using<\/p>\n<pre>chpass<\/pre>\n<p>and change the Shell to<\/p>\n<pre>\/usr\/local\/bin\/bash<\/pre>\n<hr \/>\n<h2>Installing VIM<\/h2>\n<p>And how can we go about a Unix\/Linux system without VIM? vi is just quite painful to use. And since I&#8217;m using this machine as a server, I don&#8217;t need gvim so vim-lite is suffice.<\/p>\n<pre>cd \/usr\/ports\/editors\/vim-lite\r\nmake config-recursive\r\nmake install clean<\/pre>\n<p>Do remember to configure your own ~\/.vimrc<\/p>\n<pre>syntax on\r\nset background=dark\r\nset shiftwidth=2\r\nset tabstop=2\r\nset nocompatible\r\nset expandtab\r\nset autoindent\r\nset ruler\r\nif has(\"autocmd\")\r\n filetype plugin indent on\r\nendif\r\nset showcmd \" Show (partial) command in status line.\r\nset showmatch \" Show matching brackets.\r\nset ignorecase \" Do case insensitive matching\r\nset smartcase \" Do smart case matching\r\nset incsearch \" Incremental search\r\nset hidden \" Hide buffers when they are abandoned\r\nset backspace=indent,eol,start\r\nset mouse=<\/pre>\n<hr \/>\n<h2>Installing wget<\/h2>\n<pre>cd \/usr\/ports\/ftp\/wget\r\nmake config-recursive\r\nmake install clean<\/pre>\n<hr \/>\n<h2>Installing PHP<\/h2>\n<pre>cd \/usr\/ports\/lang\/php5\r\nmake config-recursive\r\nmake install clean<\/pre>\n<p>You will also have to install php extenstions for things like session, mbstring, mycrypt, mysql, mysqli and etc.<\/p>\n<pre>cd \/usr\/ports\/lang\/php5-extensions\r\nmake config-recursive\r\nmake install clean<\/pre>\n<h3>Configuring PHP-FPM<\/h3>\n<pre>vim \/usr\/local\/etc\/php-fpm.conf<\/pre>\n<pre>events.mechanism = kqueue<\/pre>\n<pre>listen = \/var\/run\/php-fpm.sock\r\n\r\nlisten.owner = www\r\nlisten.group = www\r\nlisten.mode = 0666<\/pre>\n<p>You will also have to configure the php.ini for your needs, I need to set my local timezone<\/p>\n<pre>cp \/usr\/local\/etc\/php.ini-production \/usr\/local\/etc\/php.ini<\/pre>\n<pre>vim \/usr\/local\/etc\/php.ini<\/pre>\n<pre>date.timezone = Asia\/Singapore<\/pre>\n<p>You will have to add the following line into the rc.conf.<\/p>\n<pre>vim \/etc\/rc.conf<\/pre>\n<pre>php_fpm_enable=\"YES\"<\/pre>\n<hr \/>\n<h2>Installing nginx<\/h2>\n<pre>cd \/usr\/ports\/www\/nginx\r\nmake config-recursive\r\nmake install clean<\/pre>\n<h3>Configuring nginx<\/h3>\n<pre>vim \/usr\/local\/etc\/nginx\/nginx.conf<\/pre>\n<p>Some things that needs to be included are the use of kqueue which is used in BSD.<\/p>\n<pre>events {\r\n worker_connections 1024;\r\n use kqueue;\r\n}<\/pre>\n<pre>location ~ .php$ {\r\n #root html;\r\n #fastcgi_pass 127.0.0.1:9000;\r\n fastcgi_pass unix:\/var\/run\/php-fpm.sock;\r\n #fastcgi_index index.php;\r\n fastcgi_param SCRIPT_FILENAME \/usr\/local\/www$fastcgi_script_name;\r\n fastcgi_param PATH_INFO $fastcgi_script_name;\r\n include fastcgi_params;\r\n}<\/pre>\n<p>You will have to add the following line into the rc.conf.<\/p>\n<pre>vim \/etc\/rc.conf<\/pre>\n<pre>nginx_enable=\"YES\"<\/pre>\n<hr \/>\n<h2>Installing MySQL<\/h2>\n<p>Depending on requirements, the choice of MySQL configuration will be different, pick the most suitable one and copy it.<\/p>\n<pre>cp \/usr\/local\/share\/mysql\/my-small.cnf\u00a0\/usr\/local\/etc\/my.cnf<\/pre>\n<p>Manually start MySQL server to install and configure it.<\/p>\n<pre dir=\"ltr\">\/usr\/local\/etc\/rc.d\/mysql-server start<\/pre>\n<p>Follow the guide from the secure installation script.<\/p>\n<pre>mysql_secure_installation<\/pre>\n<p>You will have to add the following line into the rc.conf.<\/p>\n<pre>vim \/etc\/rc.conf<\/pre>\n<pre>mysql_enable=\"YES\"<\/pre>\n<hr \/>\n<h2>Installing Web-apps<\/h2>\n<p>After completing the above installation, it should be a breeze to install the rest of the web-apps like phpMyAdmin and WordPress, just place them at the correct place \/usr\/local\/www \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s been a while since I last posted something here. Recently got interested in the &#8220;beastie&#8221; aka BSD one\u00a0flavor\u00a0of UNIX, not say I&#8217;m no longer loving the penguin but then it&#8217;s good to know more systems out there and FreeBSD is one of the most well know systems for stability and uptime of like 5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,10,16,19,23],"class_list":["post-313","post","type-post","status-publish","format-standard","hentry","category-tech","tag-bsd","tag-freebsd","tag-nginx","tag-php","tag-unix"],"_links":{"self":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=313"}],"version-history":[{"count":0,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/313\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}