If wordpress site is hacked then how to fix issue

Recently one of my wordpress site is hacked which is on wordpress. There is something wrong happening on server. We fixed issue with some steps, we given full steps for fixing issue. Due to disk I/O notification and CPU usages notification email I got to know.

If wordpress site is hacked then how to fix issue

There is something wrong happening on server.

First thing I did which is checking the apache access logs and error logs. I was getting per second 100 request from some IP addresses.

I stoped apache server and I took my database and filesystem backup. Deleted my admin username and added new administrator with new username.

You should use the Better WP Security wordpress plugin. This is very useful plugin.

iThemes Security (formerly Better WP Security)

I added following code in my .htaccess file

 # BLOCK BAD IPS
 <limit GET POST PUT>
 Order Allow,Deny
 Allow from all
 # uncomment/edit/repeat next line to block IPs
 # Deny from 123.456.789
 Deny from 192.111.152.122
 Deny from 192.111.144.233
 Deny from 110.85.90.123
 </limit>

If wordpress site is hacked then how to fix issue
If wordpress site is hacked then how to fix issue

But above code was still not helpful to me because disk I/O and apache process was taking time to sending the request to 403.

Then I blocked the IP Address on My Linux server using following commands.

 iptables -A INPUT -s 192.111.144.789 -j DROP
 iptables -A INPUT -s 192.111.152.122 -j DROP
 iptables -A INPUT -s 192.119.144.123 -j DROP

This solved my issue.

solved: unable to upload images in wordpress

This is very common issue with wordpress websites. Many times we solved (unable to upload images in wordpress) same issue So we written detailed article on same topic. This is very common issue with linux or windows server or computer. When you do the wordpress setup you need to give the write able permission to your wp-content/uploads folder.

If you got the following error: when you upload the image.

“Screen Shot 2013-01-28 at 13.53.32 PM.png” has failed to upload due to an error: Unable to create directory wp-content/uploads/2013/01. Is its parent directory writable by the server?

if you are using windows then right-click the uploads folder and uncheck the is read checkbox. Change ownership of uploads folder. Change owner to apache.

solved: unable to upload images in wordpress

if you are using the linux then use following command:


chown apache:apache -R wp-content/uploads

solved: unable to upload images in wordpress
solved: unable to upload images in wordpress

 

Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

One day I faced issue with mysql.sock file. I found Can’t connect to local MySQL error. I solved the issue with following commands.

[root@localhost ~]# mysqladmin -u root shutdown
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock’ exists!

Using following command I checked the mysql directory.
[root@localhost ~]# ll /var/lib/mysql/

I did not find the mysql.sock file there.

[root@localhost ~]# cd /var/lib/mysql/
Created file in that location.
[root@localhost mysql]# touch mysql.sock
Gave the executabe permission the sock file.
[root@localhost mysql]# chmod +x mysql.sock
Changed the permission to mysql user
[root@localhost mysql]# chown mysql:mysql -R *

After that restarted the machine
[root@localhost mysql]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@localhost mysql]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;

How to remove the AuthType Basic

For putting the web authentication we always use the .htaccess or apache configuration file. For removing the web auth from folder you need put following code in .htaccess file.

 

How to remove the AuthType Basic

<Directory /var/www/html/>
#AuthType Basic
#AuthName "By Invitation Only"
#AuthUserFile /etc/httpd/passwd/passwords
#Require user wpapi
#Require valid-user
</Directory>

<Directory /var/www/html/>
AuthType None
Require all granted
Satisfy Any
</Directory>

without directory use the following code.

#AuthType Basic
#AuthName “By Invitation Only”
#AuthUserFile /etc/httpd/passwd/passwords
#Require user wpapi
#Require valid-user

AuthType None
Require all granted
Satisfy Any

Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

[root@localhost ~]# mysqladmin -u root shutdown
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock’ exists!

Solved issue: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock

Using following command I checked the mysql directory.
[root@localhost ~]# ll /var/lib/mysql/

I did not found the mysql.sock file there.

[viral-lock message=”Solution is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

[root@localhost ~]# cd /var/lib/mysql/
Created file in that location.
[root@localhost mysql]# touch mysql.sock
Gave the executabe permission the sock file.
[root@localhost mysql]# chmod +x mysql.sock
Changed the permission to mysql user
[root@localhost mysql]# chown mysql:mysql -R *

[/viral-lock]

After that restarted the machine
[root@localhost mysql]# /etc/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
[root@localhost mysql]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;

Can't connect to local MySQL server through socket
Can’t connect to local MySQL server through socket

domain search through Linux command and PHP

tutorial for PHP, domain search through Linux command and PHP. Searching the domain information through command line. You can search the domain using the Linux command.

domain search through Linux command and PHP

#whois google.com

using the following command you can find the all domain information.

If you want check when domain created then use following command.

#whois google.com | grep “Created | Creation”

If you want to create PHP script for domain search then use following code


$domain_info = exec("whois google.com | grep 'Created |Creation'");

if($domain_info =''){

echo "Domain is not yet registered";

} else {

echo $domain_info = exec("whois google.com");

}

Above script will only work in Linux server.

deleting all one day old files from folder through php

If you want to find the old files from your system or server then you can use the following code. I used the following code for deleting the old files from system.

deleting all one day old files from folder through php


/*****************Get the path to Extension ****************/
$array_path = explode("/",$_SERVER['SCRIPT_FILENAME']);
<div id=":2e">$dynamic_path = "";
for ($i=0;$i
 if($array_path[$i]!="")
$dynamic_path =$dynamic_path."/".$array_path[$i];

// This linux command will delete the one day older from specific folder.
exec("find ".$dynamic_path."* -mtime +1 -exec rm {} \;");</pre>
<div>
For deleting the old files from system I used the Linux command. You can execute the command using the exec function.
If you want to use the Linux command then use the following command
# find /home/user/test/ -m

deleting all one day old files from folder through php
deleting all one day old files from folder through php

time +1 exec rm {}

Above code will only work in Linux server.

how to convert video to flv using php

Tutorial for how to convert video to flv using php. Most of video upload sites are using the ffmpeg and php for uploading and converting the video files.  For converting you need to install the ffmpeg on your server. you can download and install ffmpeg from following location.

how to convert video to flv using php

how to convert video to flv using php
how to convert video to flv using php

http://www.ffmpeg.org/download.html

For installting the ffmpeg on linux box I found following article very helpful

http://mysql-apache-php.com/ffmpeg-install.htm

After installing the ffmpeg on your system you can use following commands for converting the video files to flv format.

avi to flv convert through ffmpeg

ffmpeg -i 00138.avi  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv final.flv

For creating the thumbnail the from video file you can use the folowing command.

create thubnail from movie file
ffmpeg -y -i moviefile.avi -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110×90 new.png

In PHP you can use the following code easily.


$video_file = '/pathtovideo/test.avi';

$flvfile ='/pathtoflv/test.flv';

$png_path ='/pathtopng/test.png';

exec("ffmpeg -i ".$video_file."  -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv ".$flvfile.");

//for thumbnail

exec("ffmpeg -y -i ".$video_file." -vframes 1 -ss 00:01:60 -an -vcodec png -f rawvideo -s 110x90 ".$png_path.");

Above code with convert the video file to flv format but my suggestion is convertion of video files will take so much bandwidth on server so use cronjob for converting the video files in night time.

deleting one day old files from folder using php

We given php  code for Checking directory and deleting one day old files from folder using php, from folder in windows or linux through php language. For deleting the files from folder in any system (windows or linux). I created the PHP script for deleting the old files from system.

Earlier I created the script for deleting files from folder but that was for only linux. Then I created script which will work independently. Following script will work in mac or windows or linux.

deleting one day old files from folder using php

 /***************** Delete one day old files ****************/
 $dir = "C://Inetpub/vhosts/yourdomain/tmpfiles";

 if (is_dir($dir)) {
 if ($dh = opendir($dir)) {
 while ($file = readdir($dh)) {
 if(!is_dir($dir.$file)) {
 if (filemtime($dir.DIRECTORY_SEPARATOR.$file) <     strtotime('-1 days')) { //if 1 days old, delete
<div id=":1o">echo "Deleting $dir.$file (old)\n";
 unlink($dir.$file);
 }
 }
 }
 } else {
echo "ERROR. Could not open directory: $dir\n";
 }
 } else {
 echo "ERROR. Specified path is not a directory: $dir\n";
 }
 closedir($dh);

// Above script is platform independent.</div>

How to install ec2-api-tools for fedora

When we want to connect to amazon server instance through linux terminal then you need to install ec2-api-tools for fedora. We given full detailed information.

How to install ec2-api-tools for fedora

For installing the ec2-api-tools in linux box follow the steps.

You will find the rpm package in following URL:

http://www.rpmfind.net/linux/rpm2html/search.php?query=ec2-api-tools&submit=Search+…&system=&arch=

Use following commands for installing the api-tools.
[root@localhost www]# cd /tmp/
[root@localhost tmp]# wget ftp://195.220.108.108/linux/rpmfusion/nonfree/fedora/releases/12/Everything/i386/os/ec2-api-tools-1.3.36506-1.fc12.noarch.rpm
After this when I started to connect my amazon server instance then I got following error message.

Permissions 0755 for ‘ec2-project.pem’ are too open.

It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ec2-project.pem

For solving the issue you need to change the key file permission to 700. For that use following command

[root@localhost EC2key]$ chmod 700 -R ec2-project.pem
[root@localhost EC2key]$ ssh -i ec2-project.pem root@ec2-59-16-79-85.compute-1.amazonaws.com
Last login: Mon Jan 10 01:08:27 2011 from 158.162.131.50
[root@domU-18-33-35-0B-D5-02 ~]#

 

How to install ec2-api-tools for fedora
How to install ec2-api-tools for fedora

If you are still facing issue then write to me.