Install and uninstall LAMP packages on CentOS

Install LAMP packages:
# yum install httpd -y
# service httpd start
# chkconfig httpd on
# yum install mysql mysql-server -y
# service mysqld start
# chkconfig mysqld on
# mysql_secure_installation
# yum install php -y
# service httpd restart
yum install php-mysql -y
# service httpd restart
# vi /var/www/html/test.php > phpinfo();

Uninstall LAMP packages:
service httpd stop
service mysqld stop
yum erase httpd httpd-tools apr apr-util
yum remove php
yum remove php-common
yum remove mysql-server
yum remove mysql


mysql create user and grant permissions to a database

Here is the syntax for creating a new user in mysql, via command console:

Grant privileges for the ‘testusername’ user to the ‘wordpress’ database:

Finally flush the privileges:


github create project

I am sure most of the web developers would have heard about the famous repository service, Github. I have been using github for my projects lately and would like to share some quick and useful info on how to setup a project in github, and how to sync it with your local project.

I assume that you are using a windows machine, have xampp/wampp installed on it, along with GIT GUI/Git Bash softwares (you can download from: Here), and you have a github account online. So lets begin with creating a new project on github.


1. Login to Github and create a new repository. Do not initialize the new repository with README, license, or gitignore files for now. You can add them later.
Create project on Github
2. Create a new php project in your localhost, with a couple php/html files.
3. Now right click inside your local project folder and select “Git Bash Here”. You will get a Git command prompt.
4. Initialize the local project directory as a Git repository, by typing: git init
5. Add all the files in your new local repository, in order to make them ready to be pushed to remote git repository: git add .
6. Commit the files that you have added above: git commit -m ‘First commit’
7. Copy the HTTPS clone URL of your remote repository on github.
8. In the Command prompt, add the URL for the remote repository where your local repository will be pushed: git remote add origin
9. You can verify the new remote URL, by typing: git remote -v
10. Push the changes in your local repository to GitHub repository: git push origin master

At this stage, you can check your remote github repository, and it should contain all the files of your local repository.

Done :)

Below are some of the tips for using Git:

> Clone Git repo to local folder:
1. Go to htdocs folder
2. Right click and select ‘Git Bash Here’
3. Type: git clone HTTPS_clone_URL_of_your_GIT_repository
4. Enter github credentials and you get GIT repo folder in htdocs
> Force GIT to override all remote files:
git push -f origin master
> Set git author & email:
git config –global Tester
git config –global
> Upload all changes from local repo to github repo:
1. From the local repository folder, right click and select ‘Git GUI Here/Git Commit Tool’.
2. There, select the files you want to upload, under ‘Unstaged Changes’ and click ‘Stage Changed’ button. (You can initially click on ‘Rescan’ button to check what files are modified and not uploaded yet.)
3. Then write a Commit Message and click the ‘Commit’ button.
4. Now right click in the folder again and select ‘Git Bash Here’.
5. Type: git push origin master and enter your credentials. Done.
Note: You may need to do a ‘git pull origin master’ prior to push.


php convert time from one timezone to another

I have cloned a git repository recently, which contains a php class with a function to convert the time between 2 different timezones.

So if you belong to India and want to know the time at Melbourne now (18:10, when i am writing this post in India), just substitute the 3 variables in the example file at: github.

Such an easy way to get the time at other timezone.
Note: You can define the timezone constants and the time differences in the file: Dates.php :)


could not create directory during wordpress plugin install

It is sometimes a big challenge for most of the wordpress developers or admins to update the plugins or themes or the core wordpress version of their site.

There are many forums and discussion threads out there, that address this issue, and most of the solutions do not work for everyone. Here i am listing a solution that worked for me when trying to update plugins of a wordpress site, for which i have root access.

Note that you either need to setup ftp server for your wordpress site and configure its credentials in the wp-config.php file, or enable proper permissions for the folders inside wp-content and ensure apache user ownership on them.

Method 1:

  • Login as root to your wordpress server.
  • Check that vsftpd (ftp server) is installed and running.
  • Configure the ftp user credentials on the server
  • Open wp-config.php file and mention the ftp settings:
  • Method 2:

  • Ensure that the directories inside wp-content have 755 permissions set. This can be achieved by running the following commands from putty, navigating to wp-content folder:
  • Ensure that the apache user has proper ownership of the directories inside wp-content.
    This can be achieved by running the following commands from putty, navigating to wp-content folder:
  • You may also need to include the below line in wp-config.php file:
  • So i have tried both the above methods and they worked for me. Hope it helps someone in the future.


    php pdo mysql example

    Connecting to a mysql database through the standard mysql_connect() function and querying the database with mysql_query() statements is not recommended any more. It is prone to sql injections. Hence the better way to connect to a database and query the results is through the PDO extension of php.
    The advantage of PDO is that it can connect to a major variety of database drivers, not just mysql. Also it can escape the user input with the help of prepared statements.

    Here is a Reference.


    wordpress include custom files


    wordpress add custom form in a page

    Have you ever wished to include a custom form inside a page of your wordpress site ?
    Well, its pretty simple.

    In this tutorial, we will try to include a small contact form in a page, that when submitted, sends out an email to the administrator of the site. The form contains 2 fields, address and phone number, which are filled by the end user.

    To proceed, create or edit a page in your site, and add the below form code to it. Assuming that jquery support is available for your site.

    Now create a new page in your backend, that maps to a custom php template file. Make sure that the slug for the page is same as the one defined as the action for our form (custom_contact_form).
    The idea is that, when the form in the page is submitted, it will be processed by our custom php template page.

    Below is the sample code of the custom php template file, that parses the form fields and sends out an email to the site admin:

    Done :)