Installing php on windows
Installing php:-
- Download the zip archive of php from this site.
- Extract the archive to a c:\php or any name that you like but in the entire explanation c:\php is assumed to be the path where php is installed so replace it with the path to your directory in case you choose to install it in another directory .
- Rename the php-ini-dist to php.ini because it is the configuration file for php.
- This completes the basic install and now you can change the configuration parameters in the php.ini like the timezone, displaying errors etc.
- Then you will have to configure apache web server and that's the tricky part because there are compatibility issues between the apache web server version and the php installation.
- If you have the php version 5.2.10 then you can configure it for apache web server 2.0.x but the php version 5.3.0 comes with support only for the apache web server 2.2 or greater so you should check the version of apache that you have before downloading php or vice versa.
- Configuring Apache 2.0.x :-
- If you have apache 2.0.x then you should download php version lower than 5.30 as it only supports the apache web server 2.2.x
- Open the apache configuration file httpd.conf and search for "LoadModule" and after the last LoadModule directives just copy and past the following code.
#php5 module for apache 2.0.x web server
LoadModule php5_module "c:/php/php5apache2.dll"
#Tell apache web server to recognize the .php extension
AddType application/x-httpd-php .php
#The php.ini directory assuming it to be the same as c:/php
PHPIniDir "c:/php"
#end of php5 module - Note that we are loading php as a module into the apache web server but you can also load it as a cgi binary. Also note that the dll that was loaded is php5apache2.dll which supports apache 2.0 web server.
- If you have apache 2.0.x then you should download php version lower than 5.30 as it only supports the apache web server 2.2.x
- Configuring Apache 2.2.x :-
- The steps remain the same but in this case you have the option to download the php 5.3.0 version but lower versions of php also support the apache 2.2.x web server because they contain the php5apache2_2.dll required for the apache 2.2.x server.
- Just copy and paste the following code at the end of LoadModule directives in the httpd.conf file and i am assuming the installation directory of php is c:\php.
#php5 module for apache 2.2.x web server
LoadModule php5_module "c:/php/php5apache2_2.dll"
#Tell apache web server to recognize the .php extension
AddType application/x-httpd-php .php
#The php.ini directory assuming it to be the same as c:/php
PHPIniDir "c:/php"
#end of php5 module - In this case note that only change is in the LoadModule directive which loads the php5apache2_2.dll which is loaded by the apache 2.2.x web server.
- The steps remain the same but in this case you have the option to download the php 5.3.0 version but lower versions of php also support the apache 2.2.x web server because they contain the php5apache2_2.dll required for the apache 2.2.x server.
- Save the http.conf file, restart the apache web server and create a simple test script and place it in the apache htdocs directory. In the test script type and save it as test.php in the apache htdocs directory. Open the browser and type http://localhost/test.php, the installation if successful will show the page containing details about php installation and apache web server.
Activating mysql support for php:-
- Open the installation directory of php i.e c:\php and then open the php.ini file and search for ;extension=php_mysqli.dll and remove the semicolon in front of it if you have mysql version 4.1 or greater because the mysqli(improved) dll file is for mysql version 4.1 or greater but if you have an older version (although it is highly unlikely) then remove the semicolon from the line that says ;extension=php_mysql.dll .
- Open the ext directory under the directory where php is installed and if your mysql version is 4.1 or newer then copy and paste the php_mysqli.dll file from it to the main directory i.e directly under the c:\php directory or else copy and paste the file php_mysql.dll.
- Note that there should also be a libmysql.dll file directly under the main directory,if not then copy and paste that file from the directory similar to the "C:\Program Files\MySQL\MySQL Server 5.0\bin" directory.
- Now you have to set the path variable by appending c:\php directory path into it so that php can find the 2 above mentioned dlls required for mysql support. To see how to set the path variable see this link.
- Reboot the pc and start the apache webserver, open browser and type the url to the file we created earlier i.e http://localhost/test.php and if everything goes fine you should see the output similar to the image shown below. This completes the installation of mysql support for php.
Friday, July 31, 2009 |
Dynamic Dns:Host your website on pc
The dynamic dns service can be used by any person with a non-static ip address to host a website on pc. Non- static ip address means that a person who is using services of an isp and so generally every time he resets his router or modem a new ip address is assigned, so the binding of a domain name to the ip address just cannot happen. The dynamic dns service can be used for this purpose to bind the non-static ip-address to a domain name by constantly updating the ip-address with the domain name provider thus a normal user can host his/her website on pc.
To get the dynamic-dns service up and running for no cost, follow these steps:-
- Register yourself at this site: http://www.dyndns.com/
- Get a free or paid dynamic domain name registered with the site.
- Download and install the tool dynamic dns updater from this link.
- Launch the tool and open the groups tab, then click on the add button, choose a name for the group, enter the user-name and password for the account that you had earlier established with the site (dyndns.com) and finally click on the download button.
- After clicking on the download button it will download the details of the domains that have been registered for that user account after which it will update the domain name with your ip-address.
- If you want to host your website on your own pc and want complete configuration for it then check the following link, where i have explained all the topics like configuring modem, apache, php, etc on your pc.
Host Website on Pc
Thursday, July 23, 2009 |
Using Timer class in java swing
The first thing that you should know is that Timer class is available both in java.util and javax.swing packages and they both are different from each other.
I will be discussing code example about the Timer class in javax.Swing package which you can use to make a countdown timer, JprogressBar or do other operations.
Below is the code example and then the explanation follows:-
import java.awt.event.*;
import javax.swing.Timer;
/**
*
* @author morph
*/
public class timer_Example extends javax.swing.JFrame implements ActionListener {
Timer timer=null;
javax.swing.JLabel label=null;
static int counter=0;
/** Creates new form timer_Example */
public timer_Example(){
//your code goes here
label=new javax.swing.JLabel("The time is 0 seconds");
this.getContentPane().add(label);
this.pack();
timer=new Timer(1000,this);/*create a timer that generates an event after 1 second and pass it the frame object which handles the action event by implementing the ActionListener interface*/
timer.start();
}
public void actionPerformed(ActionEvent e){
if(counter==100)
{
timer.stop();
}
javax.swing.SwingUtilities.invokeLater(new updateCount());
}
public class updateCount implements Runnable{
public void run(){
counter=counter+1;//update the counter value
label.setText("the time is "+counter+" seconds");
//your JProgressBar code can go here
//or any other code that you may like
}
}
public static void main(String args[]) {
timer_Example form=new timer_Example();
form.setVisible(true);
form.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
}
The code is pretty basic but this code can be used to perform various tasks. In the code we initialize the counter to 0 and then create the timer object by calling its constructor and passing it 2 arguments the time in milliseconds after which the timer shall generate an event (timer generates an ActionEvent) and second parameter is an event handler for the action event which in this case is the form object itself.
The actionPerformed function just simply checks whether the count has reached 100 or not and if it has it stops the timer. Otherwise it creates a new runnable object of a nested class updateCount which updates the count value and displays the count value through the JLabel. Here you can do other things like updating the JProgressBar or any other event that you may wish to implement. I have used SwingUtilities.invokeLater() function because it is always recommended that you should place the call to some other class on an event queue and not directly call the class.
I have used a similar concept to develop a simple application in java that performs various operations like Shutdown, Hibernate, Standby, lock etc but in that case the counter is countdown counter. You can also create beautiful application launcher windows with changing backgrounds and updating progress bar with it.
Tuesday, July 21, 2009 |
phpMyAdmin log in error
In case you change the password for root account using phpMyAdmin and then try to login into mysql database using phpmyadmin you will receive a log in error and you won't be able to login, this happens because phpmyadmin has no way of knowing what's the root password that you have set.
The phpmyadmin uses it's config.inc.php file for storing mysql user related information and that is where you should enter the root password so that on next log in it can successfully log in to the mysql database.
The solutions to update the password are explained below:-
- For Wamp Server:- If you have installed wamp server then follow these instructions
- Open the apps directory under the directory of wamp server. i.e /wamp/apps
- Now open the phpmyadmin directory and then open the config.inc.php file
- Navigate to the line that says "$cfg['Servers'][$i]['password'] = 'xxxx '" and replace the xxxx with the password for the root user and save changes.
- Now log into the mysql database using phpmyadmin and your login will be successful
- For Standalone installation:- In case you have installed phpmyadmin as a standalone version then just navigate to the directory of phpmyadmin and then you can follow the aforementioned solution steps.
Monday, July 20, 2009 |
Linux hack: Symbolic and Hard links
This is a issue that most admins take care off and so if you are a admin and don't know about this threat then pay attention.
What are Symbolic links and Hard links in linux file system?
- Symbolic/Soft links:- These links can be created by executing the following command.
ln -s original-file symbolic-file
Here the -s option specifies that the link is symbolic. and when we invoke the ls -il command on it we can see that the inode numbers on the files will be different and the symbolic file would be pointing to the original file like this.
symbolic-file->original-file
When we delete the original file and try to do a read operation on the symbolic file it will raise an error because the original file does not exist but if we try to write to the symbolic-file this leads to recreation of the original file (this is what you don't want). - Hard links :- This type of link can be created by using the following command.
ln original-file new-file
In this case if you execute the ls -il command you will see that the inode numbers of both the files are same which shows that the file names are both references to the same location and in case you delete the original file only the original reference is destroyed but still the file name new-file points to that location and the file can still be accessed.
The hard link trouble :- When someone obtains a hard link to your file then he/she gets the same access rights to the file as the file itself has. So if the file has read, write and executable rights then you get to have those rights to.
Generating Soft link's is a fatuous mistake:- when somebody is able to make a soft link to your file, then he/she gets all the access rights to the file (all means all) , even those rights which are not set for the file which effectively means that they have more access rights to the file than the file has.
Scenario 1 :- the user creates a symbolic link to your /etc/passwd or /etc/shadow file . Hmm, considering the case with soft link's that implies the user can edit, delete entries or make new ones into the file, the user can take both your /etc/passwd and /etc/shadow file and can then use a cracking tool like John the ripper to crack the password's in it and hence the user will be able to own the system.
Solution:-
The basic solution is that if you are a power user then don't create symbolic link's to the sensitive files and even if you do want to create them, you should use the chmod command to change the default permissions of the symbolic link files to somewhat more restrictive permissions.
Secondly you can make sure that an average user does not have rights to access the directories like etc (containing most of the configuration files including the passwd and shadow files). So that they cannot create soft links on them.
"Linux is a safe platform but just requires the configuration's to make it safe"
Monday, July 06, 2009 |
java.lang.NoClassDefFoundError on executing jar file
Problem:-You encounter this error while executing your jar file then it is likely due to missing library files that your jar file needs to run.
Solutions:-
For applications made using NetBeans Ide:-
- Netbeans while making your jar file adds the classpath of the libraries needed for your application to the manifest.mf file and creates the folder lib in the dist folder containing the jar files that your application needs to execute.
- If you copy and paste just the jar file and try to execute it it will raise an error, so instead of just copying the jar file copy the entire dist folder and then execute the jar. It will work.
- To add the path of class libraries that are missing just create a plaint text file and then add the class path of the libraries to it. for example if you are getting error for the missing class file org.apache.tools.bzip2.jar located under the xyz directory then you should add the variable as it is shown Class-Path: xyz/org.apache.tools.bzip2.jar and save the text file. Then you should execute the following command.
jar cfm "Your jar File" "The text file you edited" "the files to add into the jar" - Now run the application using the command "java -jar application_name.jar" and it should work fine.
Monday, July 06, 2009 |
Automated shutdown utility/Tool java based
In case you want to schedule or automate tasks like shutting down, restarting, hibernating , Standby and Locking then you can use this simple application made by me. It utilizes the psshutdown application and has a automated counter for planning the aforementioned tasks.
Installation:-
- Just extract the rar file and after you extract there will be two folders, one will be install and the other one will be the application (under the dist directory) and there will also be an executable psshutdown utility.
- Run the installer application by using the command "java -jar Installer.jar"(without the quotes) on the install folder and click on the "Select extracted file psshutdown" button, select the extracted psshutdown file, click on the install button and the application will be ready to use.
- Now just navigate to the application directory execute the command java -jar Shutdown.jar from command prompt to launch the application.
- Just launch the application by opening command prompt at the application folder and invoking "java -jar Shutdown.jar" (without the quotes) command .
- Specify the time in hours:minutes:seconds format. For example if you want to automate the task 36 hours from now then enter 36 in the field. The field is auto correcting so you can enter values like 23:78:65 and it will correct those values to proper format.
- Select the operation from the drop down box that you want to execute and click on the submit button.
- One can always abort the current operation in between by clicking on the abort button.
- The label at the bottom will display the time left for the execution of the operation.

Following are the snapshots of the application:-
Monday, July 06, 2009 |







