PHP System timezone setting Warning

If you are trying to set the system time zone within your php script and your requirement is that you must use the server side time/date rather than using javascript client side you can continue to read. I was asked this question in reference to php but this can obviously be done in any language. The file that you should be concerned with is /etc/sysconfig/clock.

1. The php warning;

Warning:  date [function.date]: It is not safe to rely on the system's 
timezone settings. You are *required* to use the date.timezone setting
or the date_default_timezone_set() function.

2. Place the below code within your php script/applicatoin in the header or some logical place that will be included once. You can also integrate and store the information within a session variable etc so you would only need to call the function once per login. The below only works on linux.

/* Grab the file as an array */
$timeString = file("/etc/sysconfig/clock");

/* Perform some regex goodness to grab the match */
preg_match('#^ZONE="([a-zA-Z0-9\/ _]+)"#i',$timeString[0],$matches);

/* Attempt to set the timezone */
if(!date_default_timezone_set($matches[1])) {

/* If for some reason the timezone doesn't get set use UTC */
date_default_timezone_set("UTC");

}

Parallels Network Error When Deploying Template Based VM’s

Received the below from Parallels support to resolve the problem with the network interface on a vm deployed from a template being switched from eth0 to eth1. Its a pain having to do this on each and every vm that you deploy from a template but its easily scripted. Not sure if it was located in their knowledge base. If it was I may not of hit the exact search terms required.

Note: One thing that was not mentioned below is the need to change the “HWADDR=” configuration line within your interface config file (ifcfg-eth0) to the new mac address or simply remove it.

During the deployment the MAC address of VM network adapter changes. The new ethernet network device (eth1) is created on Ubuntu and new MAC address is assigned to eth1. eth0 has the old MAC address, eth1 has the new valid MAC address. The system refers to eth0 adapter which has the obsolete MAC address.

We need to disable eth0 with obsolete MAC address and rename the eth1 with valid MAC address into eth0.

Backup the config:

$cp /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.backup

Edit /etc/udev/rules.d/70-persistent-net.rules in vim editor under root permissions.
If you open it:

$vim /etc/udev/rules.d/70-persistent-net.rules

you will see

# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# PCI device 0x10ec:0×8029 (ne2k-pci)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:1c:42:cc:ee:c0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

# PCI device 0x10ec:0×8029 (prl_eth)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:1c:42:d2:8e:8e”, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″

The MAC addresses can differ in your case, in the example above the last record has the valid MAC address “00:1c:42:d2:8e:8e”. You can also check the valid MAC address in the configuration of the virtual machine

Top mac menu bar > Virtual machine > Configure > Hardware > Network 1 >

comment the eth0 device and change the name of eth1 into eth0:

# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.

# PCI device 0x10ec:0×8029 (ne2k-pci)
#SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:1c:42:cc:ee:c0″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

# PCI device 0x10ec:0×8029 (prl_eth)
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”00:1c:42:d2:8e:8e”, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″

Reboot the virtual machine.

svn more corruption fix goodies

Bad day for subversion, sigh. Method to resolve the below error.

svnadmin: Revision file lacks trailing newline

First, backup your repository. If your repo isn’t excessively large you can just use a “cp -a” as I did. It took a minute or so on my 6GB repo. Once you have backed up your repo go into your repos db directory and it should look similar to the below.

[svn@svn-quake db]$ ls
current  format  fs-type  revprops  revs  transactions  uuid  write-lock

Next open the file named current within this directory and increment the first number in the top of the file down 1. Inside of the file the first line looked like “546 ear 3h” so I changed it to reach “545 ear 3h”.

[svn@svn-quake db]$ cat current
546 ear 3h
[svn@svn-quake db]$ echo "545 ear 3h" > current; cat current
545 ear 3h

Now copy out the files in the revs directory and the revprops directory that correspond to the original version number above that you changed which was “546″.I created a directory called copy in my base directory to store these files.

[svn@svn-quake db]$ mkdir -p ~/copy/{revs,revprops}
[svn@svn-quake db]$ mv revs/546 ~/copy/revs
[svn@svn-quake db]$ mv revprops/546 ~/copy/revprops/546

Once completed with the above check your svn checkout and if you get the same error repeat the steps again incrementing the number down again from 545 to 544. Be sure that you move the corresponding files out of the revs and revprops directories as well. Keep repeating the steps until you are error free.

Git migration post coming soon. ;-)

Svn mismatch checksum error upon commit

Still haven’t moved to git? Nope, to much junk to move and to little time. ;-) When dealing with repository corruption similar to the below first backup your original file and then delete it from the svn.

Transmitting file data .svn: Commit failed (details follow):
svn: Checksum mismatch for '/home/dev/crypto/.svn/
text-base/header.svn-base';
expected '77d9b849d5dd1c848c1fd77b6c74c976',
actual: 'c7b4690c8c46625ef0f328cd7a24a0a3'
svn: Your commit message was left in a temporary file:
svn: '/home/dev/crypto/svn-commit.tmp'

The below should solve your issues.

mv  corruptFile.txt corruptFile.txt~
svn del corruptFile.txt
svn commit -m "temporary delete to fix corruption"
mv corruptFile.txt~ corruptFile.txt
svn add corruptFile.txt
svn commit -m "Adding the cause of the corruption back"

WordPress error ob_start() [ref.outcontrol]: or blank admin screen

A good place to start looking if you get an error similar to the below after a WordPress upgrade and/or add-on install is your SEO add-on. Disable the SEO add-on first and then continue to disable add ons until the issue is resolved.

Fatal error: ob_start() [ref.outcontrol]: Cannot use output buffering
in output buffering display handlers in
/home/mr-yuck/www/wp-content/plugins/directory/core/core.php
on line 804"

If your admin screen is blank rename your add ons folder, manually disable your add ons or call a professional. ;-)

MagicWand PHP module install Centos

Use the post HERE to install PHP and Apache from source then follow the instructions below. Works on CentOS 5 or 6. The instructions located within the INSTALL file work fine. The only difference I saw was that I had to set the “PKG_CONFIG_PATH” environment variable. Be sure to grab the latest versions of the below source code. These installation instructions should also work on binary package installs of apache and php.

Grab your source code.

mkdir -p /usr/src/{src,ext}
wget -P /usr/src/src \
http://www.magickwand.org/download/php/legacy/ \
MagickWandForPHP-1.0.8.tar.gz
wget -P /usr/src/src \

http://www.imagemagick.org/download/ImageMagick.tar.gz

Untar your packages

tar xzf  /usr/src/src/MagickWandForPHP-1.0.8.tar.gz -C /usr/src/ext
tar xzf  /usr/src/src/ImageMagick.tar.gz -C /usr/src/ext

Build and configure ImageMagick your packages

cd /usr/src/ext/ImageMagick-6.7.4-10/
./configure; make; make install

Build and configure MagickWand

cd /usr/src/ext/MagickWandForPHP-1.0.8
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
phpize
./configure ;make ;make test; make install

If everything builds correctly copy your shared object file into the php directory tree

cp /usr/src/ext/MagickWandForPHP-1.0.8/modules/magickwand.so /usr/lib/php/extensions/

Modify the php.ini file using the full path for the shared object file for clarity.

vi /usr/lib/php.ini
extension=/usr/lib/php/extensions/magickwand.so

After you have completed the above simply run your php -v to be sure there are no errors
If you are error free restart apache and create your phpinfo page in order to see that the module.

Create MySQL/MariaDB database and User

Quick little reference to add a mysql database and user. The below should also work on MariaDB.

Be sure to also run the command below on your production servers to lock down mysql.

/usr/bin/mysql_secure_installation

Create a database

mysql> create database new_database;
Query OK, 1 row affected (0.00 sec)

create a user

mysql> create user 'remote_user'@'remote.server.com' identified by 'SoMePaSsWoRd';
Query OK, 0 rows affected (0.00 sec)

Grant access to the database

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,
ALTER, LOCK TABLES,CREATE TEMPORARY TABLES ON new_database.* TO
'remote_user'@'remote.server.com';
Query OK, 0 rows affected (0.00 sec)

Determine if your hardware provides vt support

Run the below command to determine if your hardware (processor/mb) offers vt support in terms of virtualization. Hardware with vt support allows you to run 64bit and 32bit versions of windows and linux within a virtual environment.

[woof@bigdog someplace]# sudo cat /proc/cpuinfo | grep vmx
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx tm2 ssse3 cx16 xtpr lahf_lm
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc pni monitor ds_cpl vmx tm2 ssse3 cx16 xtpr lahf_lm

If you get output similar to the above your processor does indeed have vt support.

[meoww@non-vt-server ~] cat /proc/cpuinfo | grep vmx
[meoww@non-vt-server ~]

If vt support does not exist the command returns nothing as does the above. Note that you go right back to the command prompt without any output from the command.

3ware card REBUILD-PAUSED displayed in tw_cli info

If you run the “tw_cli info c0″ command and you get something similar to the below after 
replacing a drive it is most likely caused by a rebuild delay that is present just after 
you boot your machine. If you get the “REBUILD-PAUSED” after replacing a hot swappable drive 
or it simply hangs around for a long time after the reboot then run the command below. The
“c0″ should be replaced with your controllers identifier. 

[throat@biggin ~]#sudo tw_cli sched rebuild c0 enable
Unit     UnitType  Status         %Cmpl  Port  Stripe  Size(GB)  Blocks
-----------------------------------------------------------------------
u0       RAID-5    REBUILD-PAUSED 0      -     64K     1862.62   3906207744
u0-0     DISK      OK             -      p1    -       931.312   1953103872
u0-1     DISK      DEGRADED       -      p2    -       931.312   1953103872
u0-2     DISK      OK             -      p3    -       931.312   1953103872
[throat@biggin ~]#sudo tw_cli info c0 u0
Unit     UnitType  Status         %Cmpl  Port  Stripe  Size(GB)  Blocks
-----------------------------------------------------------------------
u0       RAID-5    REBUILDING     3      -     64K     1862.62   3906207744
u0-0     DISK      OK             -      p1    -       931.312   1953103872
u0-1     DISK      DEGRADED       -      p2    -       931.312   1953103872
u0-2     DISK      OK             -      p3    -       931.312   1953103872

Install gnome via yum post install

Use the below commands to install an X-window environment on a pre-existing installation of Centos 5. I suggest just rebooting afterwards so that you don’t have to mess around with gnome sessions etc. This should work on Centos 6 but i didn’t have the time to fire up an instance to test.

sudo yum -y groupinstall "X Window System"
sudo yum -y groupinstall "GNOME Desktop Environment"