Thursday, November 7, 2013

Update oracle java on debian linux

i recently ran into a situation where i needed to update java on my debian linux system. this update needed to include the java plugin for my firefox browser, which is a security vector, but is required for some work tasks. my setup is NOT using the default openjdk package that debian provides. i prefer to use oracle java. i wrote a bash script to make all the required calls to update-alternatives to complete the update. below are the steps i followed.

i downloaded the necessary jdk linux tarball from http://www.oracle.com/technetwork/java/javase/downloads/index.html to /share.


>su -
>mkdir /usr/local/src/java
>cp /share/jdk-7u##-linux-i586.tar.gz /usr/local/src/java
>cd /usr/local/src/java
>tar -xvzf jdk-7u##-linux-i586.tar.gz
>bash /share/updateJava.sh
>exit



below are the contents of the script updateJava.sh :


# this script uses debian's update-alternatives to update
# to the latest version of java

javaRoot="/usr/local/src/java/jdk1.7.0_45/"

update-alternatives --install /usr/bin/java java "$javaRoot""bin/java" 1
update-alternatives --install /usr/bin/javac javac "$javaRoot""bin/javac" 1
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so "$javaRoot""jre/lib/i386/libnpjp2.so" 1

update-alternatives --set java "$javaRoot""bin/java"
update-alternatives --set javac "$javaRoot""bin/javac"
update-alternatives --set mozilla-javaplugin.so "$javaRoot""jre/lib/i386/libnpjp2.so"


 



below is the output of my system:

>java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)
 

>bash /share/updateJava.sh
update-alternatives: using /usr/local/src/java/jdk1.7.0_45/bin/java to provide /usr/bin/java (java) in manual mode
update-alternatives: using /usr/local/src/java/jdk1.7.0_45/bin/javac to provide /usr/bin/javac (javac) in manual mode
update-alternatives: using /usr/local/src/java/jdk1.7.0_45/jre/lib/i386/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in manual mode
 

>java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)


info taken from:
http://www.redirecttonull.com/?p=250

Tuesday, November 5, 2013

Update flash plugin in firefox on debian linux

i had an issue where i couldn't watch videos on youtube. i got a message about upgrading the flashplayer in my firefox browser on my debian linux system. after some googling i found the debian wiki page that details how to upgrade the flash plugin for the browser. i executed the following command as root:

update-flashplugin-nonfree --install

if you are behind a proxy like i am the command looks like:

http_proxy=http://myproxy:port update-flashplugin-nonfree --install


info taken from :
https://wiki.debian.org/FlashPlayer

also see:
http://tuxmark.blogspot.com/2013/10/flash-not-working-in-firefox-on-linux.html

Monday, October 28, 2013

event reminder from the command line

i needed a way to set a reminder on my debian system so that i don't forget to attend meetings, since i don't have access to my online calendar. so after some googling, i've found a solution using the at command and zenity dialog.

"at" lets one execute a command at a specific date and time in the future. there are quite a few options.

zenity is a package that provides and easy way to pop-up a custom dialog box. there are quite a few options for zenity as well.


open a terminal, for an event at 9:00am on October 29 enter the following:

at 0900 Oct 29

a "at>" prompt will appear. enter the command to execute:

at> env DISPLAY=:0.0 zenity --info --title "my title" --text "my custom message"

when finished with the command hit the enter key, then press CTRL-D. a job number with date and time for the job will appear.

specify the display device to use for the zenity dialog
env DISPLAY=:0.0

specify a zenity info dialog box
--info

specify the zenity dialog box title
--title "my title"

specify the zenity dialog box message text
--text "my custom message"


info take from:

man page for at command
man page for X
http://www.brunolinux.com/02-The_Terminal/The_at_Command.html
http://lowfatlinux.com/linux-task-scheduler-at.html?ModPagespeed=noscript
http://linux-commands-examples.com/zenity
http://ubuntuforums.org/showthread.php?t=759389&page=2
https://help.ubuntu.com/community/CronHowto
http://www.linuxquestions.org/questions/linux-newbie-8/export-display%3D-0-0-a-682926/

Thursday, October 24, 2013

Flash not working in Firefox on linux

i recently had an issue with successful playing youtube videos in my firefox browser on my debian linux machine. i previously installed the flashplugin-nonfree package to use as the flash plugin and everything worked fine for a while.

after googling around i came to the realization that the following packages

browser-plugin-gnash
gnash
gnash-common

were installed at some point and prevented the correct rendering of flash videos. so i removed the gnash packages with the following command.

aptitude purge browser-plugin-gnash gnash gnash-common


after removing the gnash packages, youtube and other flash videos began working again as expected.

so, how do i prevent gnash from being installed again and causing future problems. i found several interesting solutions, a few are listed at the bottom of this post. i decided to place a hold on the gnash packages (while uninstalled). below is the command i used.

aptitude hold browser-plugin-gnash gnash gnash-common


i've never used hold with apt before, so hopefully this will prevent any future installs of gnash. if anyone has a successful experience preventing specific packages from being installed, i would definitely like to hear your solution.

also check out:
http://tuxmark.blogspot.com/2013/11/update-flash-plugin-in-firefox-on.html


below are a few links i found while researching this issue.

http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html
http://askubuntu.com/questions/75895/how-to-forbid-a-specific-package-to-be-installed
http://serverfault.com/questions/17046/preventing-specific-packages-from-getting-installed-in-debian

Wednesday, October 23, 2013

How to post json with curl

i needed to test a php script by posting a json body in the request with curl from the debian linux command line. below is the solution i found.

curl -X POST -H "Content-Type: application/json" -d '{"key": "value"}' http://localhost/myscript.php


info taken from:
http://stackoverflow.com/questions/7172784/how-to-post-json-data-with-curl-from-terminal-commandline-to-test-spring-rest

Tuesday, October 22, 2013

Building Mysql 5.5 from source

following are the steps I used to build from source and install mysql 5.5 on my debian system

download the Mysql 5.5 tarball from mysql.com . become the root user and move the downloaded tarball to /usr/local/src. unpack the mysql tarball with:
tar -xvzf mysql-5.5.xx.tar.gz

add specific user and group to run mysql as:
groupadd mysql
useradd -r -g mysql mysql 

change directory to be inside source tree
cd /usr/local/src/mysql-5.5.xx

execute make commands
cmake .
make
make install

change to install directory
cd /usr/local/mysql

execute post installation setup commands
chown -R mysql .
chgrp -R mysql .
scripts/mysql_install_db --user=mysql
chown -R root .
chwon -R mysql data
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server

login to mysql command line client and set passwords
mysql -u root -p
enter root password when prompted

display existing users
SELECT User, Host, Password FROM mysql.user;

assign password to the root user
UPDATE mysql.user SET Password = PASSWORD('newpassword') 
    WHERE User = 'root';
FLUSH PRIVILEGES;

assign password to the anonymous user
UPDATE mysql.user SET Password = PASSWORD('newpassword')  
    WHERE User = '';
FLUSH PRIVILEGES;

display existing users to verify passwords have been set
SELECT User, Host, Password FROM mysql.user;


exit mysql command line client
quit

add non-root user to mysql group
usermod -a -G mysql myUsername

add symlink to access mysql and mysqladmin
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqladming /usr/bin/mysqladmin



info taken from:
http://dev.mysql.com/doc/refman/5.5/en/installing-source-distribution.html

Friday, October 18, 2013

bash regex to get json value

i needed a bash regex to get the value for a given key in a json file. below is my solution.

json.sh

getJsonValue()
{
    grep -Po '"'"$2"'"\s*:\s*"\K([^"]*)' $1
}

# example usage
# getJsonValue "json_file" "json_key"

 

Building Apache 2 and Php 5 with mysql support from source on Debian

following are the steps I used to build from source and install apache 2.2 and php 5.4 with mysql support on my debian system

i had to install additional packages from using apt:
libxml2-dev
libtool
autoconf


add specific user and group to run apache httpd as:
groupadd www-data
useradd -g www-data www-data 


download the Apache HTTP server from apache.org. become the root user and mv the downloaded tarball to /usr/local/src. unpack the apache tarball with:
tar -xvzf httpd-2_x_NN.tar.gz


download the PHP source from php.net. become the root user and move the downloaded tarball to /usr/local/src. unpack the PHP tarball with:
tar -xvzf php-NN.tar.gz


build and install Apache. reference the Apache install documentation for more details on building Apache.
cd httpd-2_x_NN
./configure --prefix=/usr/local/apache2 --with-included-apr 
    --enable-cgi --enable-cgid --enable-modules=all 
    --enable-mods-shared=all --enable-so 
    --enable-mime-magic --enable-deflate
make
make install


apache 2.2 is available at /usr/local/apache2. to test the installation use the normal procedure for starting the Apache server, e.g.:
/usr/local/apache2/bin/apachectl start
and stop the server to go on with the configuration for PHP:
/usr/local/apache2/bin/apachectl stop


configure and build PHP. configure with Apache 2 and MySQL support.
since apache was built from source, the steps below will match the path for apxs.
cd ../php-NN
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
make
make test
make install

setup your php.ini
cp php.ini-development /usr/local/lib/php.ini
edit your .ini file to set PHP options

verify/edit the apache httpd.conf to load the PHP module. make install from above may have already added this, but check.
LoadModule php5_module modules/libphp5.so


configure Apache to parse certain extensions as PHP. have Apache parse .php files as PHP.
 
    SetHandler application/x-httpd-php
 

to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP use:

    SetHandler application/x-httpd-php

to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use:

    SetHandler application/x-httpd-php-source
 

other apache 2.2 httpd.conf configuration changes that I made:

changed the specific user and group to run httpd as
changed the document root
changed access configuration for different directories
changed errorlog
changed loglevel to debug
changed customlog path
changed scriptalias for cgi-bin
configured access for cgi-bin



use the normal procedure for starting the Apache server, e.g.:

/usr/local/apache2/bin/apachectl start


info taken from:
http://httpd.apache.org/docs/2.2/install.html
http://php.net/manual/en/install.unix.apache2.php