CentOS 6 minimal install on VM – network connection

Just installed CentOS 6 and by default the eth0 is not connected in the VM, even if the VM configuration indicates it is connected. You’ll see this when you cat /etc/sysconfig/network-scripts/ifcfg-eth0. Note all these actions are executed as the root user.


So you need to do the following to correct the issue.

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Edit the contents of that file to end up having this:


Then save (CTRL + x, yes and enter, enter) and then reboot:


CentOS will do the rest for you.


Vnc Server on CentOS 6.x

Thank to: http://wiki.centos.org/HowTos/VNC-Server#head-86a610f73b0fa6b5ecf2fe40f0bb301ea0038a26 for the incredible tutorial and reference material!

1. Installing the software packages

The server package is called ‘vnc-server’. Starting for a clean slate, install it with the command: yum install vnc-server.

Make sure to install a window manager in order to get a full-featured GUI desktop. Gnome, Mate, KDE or XFCE.

2. Create the VNC user accounts

If you want to have it just for your user, meaning the regular desktop user that you use for the desktop, you can skip this.

As a root user:

$ su root
# useradd userOne
# passwd PssswdOn

3. Edit the server configuration

Edit /etc/sysconfig/vncservers, and add the following to the end of the file.

[root@localhost]# cat /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own).  You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.  
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted!  For a secure way of using VNC, see this URL:
# http://kbase.redhat.com/faq/docs/DOC-7028

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel.  See the "-via" option in the
# `man vncviewer' manual page.

# VNCSERVERS="2:userOne"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

4. Set your users’ VNC passwords

Switch user into the account for each user, and as noted below, run: vncpasswd This will create the .vnc directory for that userid:

[~]# su - userOne
[~]$ vncpasswd
[~]$ cd .vnc
[.vnc]$ ls
[.vnc]$ exit

 5. Confirm that the vncserver will start and stop cleanly

We will create the xstartup scripts by starting and stopping the vncserver as root. We also enable the vncserver service to be automatically started. You can always do this through the services gui application in system ->administration.

# /sbin/service   vncserver start
# /sbin/service   vncserver stop
# /sbin/chkconfig vncserver on

6. The iptables

The iptables rules in /etc/sysconfig/ need to be modified to open the VNC ports; as needed, if a local ipv6 setup is being used, those need to be amended as well. first check with NIC you use to go to the internet with the server/pc.

You need to add something similar to this: -A INPUT -i eth1 -j ACCEPT where eth0 is your NIC. Don’t skip this step or you’ll never be able to access your server!

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth1 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 5901:5903,6001:6003 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
[root@xen-221 sysconfig]#         

… and then restart the iptables:
# /sbin/service iptables restart

7. Start the VNC server

Start the vncserver as root. if you get an error with “display configuration” then you don’t have the .vnc directory for the user executing the start command!

# /sbin/service vncserver start

Now You need to test and everything should work as planned!


Phalcon php, a serious replacement for Yii framework

I’ve been using Yii a lot, in various projects that I have been writing the past three years and up until now it has always delivered. However, recently I have been looking at the version 2 of the Yii Framework, while still a very nice framework, I don’t think it will be to my liking. The structure for projects is just to different en the use of composer is not my favorite thing so I have been looking for high performance frameworks written for PHP.

Obviously all the frameworks pass through on the screen an non where really good for me. That was until I read something about frameworks in 2014 end one of them was Yii but another was Phalcon a PHP framework written in C and added to the PHP parser in the .ini file.

Obviously this means that you’ll have to have administrative privileges on the webhost, ask the hoster to accommodate or use like Amazon aws services. In any I’ll be experimenting with the framework and see how it functions, my experiences and tutorials will be posted!


Yii retain speed when using Javascript

CClientScript can be useful for including css files and javscript files, while avoiding duplication, you only need to learn and control the darn thing right.

Before we begin or if you tried it already and have come searching for this:

1. Yii writes the code for css files just above thetag in the html document. So, if you want to override, put your
or (preferred) AFTER the

2. I recommend putting all your
and in theand all your just before . are blocking, so your page will load faster if the are at the bottom. use:

  1. Yii::app()->getClientScript()->coreScriptPosition = CClientScript::POS_END;

3. If you want to include some inline javascript in a view, but make it load at the bottom, after say jquery, use the registerScript() method.

  1. /* load some formatted js into a php variable: */
  2. $js = <<<EOF
  3. var = 'some javascript here!';
  4.     function() { return 'you can format it as you like, and include php $variables'; };
  5. EOF;
  6. /* write the script at the bottom of the document  */
  7. Yii::app()->getClientScript()->registerScript("some id", $js, CClientScript::POS_END);


Yii dropdownlist treestructure

A possible solution to having an tree type display of a nestled structure in a dropDownlist or activeDropDownList.


  1. public static function getListModulesTreeView() {
  2.         return self::visualTree(SystemModules::model()->findAll('moduleIdFk is NULL'), 0);
  3.     }
  4.     private static function visualTree($moduleTree, $level) {
  5.         //resultset to be returned -------------------------------------------//
  6.         $results = array(0=>Yii::t('gui', 'noSubmodules'));
  7.         // looping the data --------------------------------------------------//
  8.         if ($moduleTree) {
  9.             // looping the results -------------------------------------------//
  10.             foreach ($moduleTree as $module) {
  11.                 // adding to mail array --------------------------------------//
  12.                 $results[$module['moduleId']] = str_pad('', $level * 2, '-')  . $module['moduleName'];
  13.                 // do we have children? --------------------------------------//
  14.                 if ($module->systemModules) {
  15.                     $temp = self::visualTree($module->systemModules, $level + 1);
  16.                     // moduleId : $key ---------------------------------------//
  17.                     foreach ($temp as $key => $val) {
  18.                         $results[$key] = $val;
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.         return $results;
  24.     }


MAMP Pro & MySQL workbench

I’ve been looking for a few hours for a quick and easy solution to my connection problem between MySQL workbench and the database itself using MAMP Pro. In itself it isn’t a real problem because you have phpMyAdmin readily available but for ERD models and reverse engineering options. I found my answer on stackoverflow without a lot of trouble but it was a hasty answer and I like to explain a bit complete. So here goes.

First open MAMP Pro on your Mac and you’ll see the following image


See to it that your ports are the same as mine or adjust accordingly if you want to keep them.

Next you will need to open workbench, I Presume you have it already installed in your Mac. The first thing you’ll have, is the possibility to create a connection or edit one if you have tried and failed as I have before. open or create the connection that you want to establish but can’t. You’ll get something along these lines, if not, please search for it.


When you have the first form filled out correctly go to ‘Advanced’ in the same window!


In the ‘Others’ section you will have to add a line and you’ll be good to go. You have to add: socket=/Applications/MAMP/tmp/mysql/mysql.sock and go back to the ‘Parameters’ and use ‘test connection’, normally this should have you up and running. If not, is MAMP started? Are your ports correctly configured? User/password? ….


Module and submodule in Yii framework

Yii framework is a very fast and usable framework, within you can create modules to house some sort of sub-applications, link a forum for example but how do you make use of sub-modules?

First you need to create the top most modules, in my case ‘main’. You can do this by using the Gii tool to generate it. After this you need to add the created module to the config/main.php

 PHP |  copy code |? 
  1. 'modules' => array(
  2.         'gii' => array(
  3.             'class' => 'system.gii.GiiModule',
  4.             'password' => 'admin',
  5.             'generatorPaths' => array(
  6.                 'bootstrap.gii'
  7.             ),
  8.         ),
  9.         // main application components
  10.         'main',
  11.     ),

After this you can create the submodules by using Gii, don’t forget to do it like this main/NewModuleName, the system then knows where to place them.

And now we go back to the config/main.php

 PHP |  copy code |? 
  1. 'modules' => array(
  2. 'gii' => array(
  3. 'class' => 'system.gii.GiiModule',
  4. 'password' => 'admin',
  5. 'generatorPaths' => array(
  6. 'bootstrap.gii'
  7. ),
  8. ),
  9. // main application components
  10. 'main'=>array('NewModuleName1','...'),
  11. ),