Permission denied /home/.htaccess pcfg_openfile unable to check htaccess file

While migrating my server data to anther server, Permission denied /home/.htaccess pcfg_openfile unable, I got this error. while restarting apache server I got following error.

[Mon Apr 25 12:15:41 2016] [crit] [client 115.117.45.10] (13)Permission denied: /home/purab/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

Background, I am using centos (Linux) for hosting my sites and I am using user defined directory and apache 2.4 version for server.

I was not using .htaccess file in that location, still I was getting this error. Easy solution will be disable .htaccess setting httpd.conf file If we are planning not to use the htaccess file in our project. I found many solutions but that didn’t solved my issue. above issue is specific to file permission.

Permission denied /home/.htaccess pcfg_openfile unable

If it isn’t obvious that .htaccess cannot be read by the server (either 0755 or .htacess and the rest of the tree is in www-data group), search for a higher directory root only onwer:group which does *not* have world execute access.
In order for apache to find a file, it has to search down the tree. It cannot do this if a directory which is root:root does not have global execute access.

I executed following command to change ownership of public_html folder.

chown apache -R /home/purab
usermod -a -G /home/purab apache

After this I restarted my apache server using following command.

/etc/init.d/httpd restart

Using above command, it solved my issue. But purab user cannot edit the files in purab folder. So I used setfacl command.

What is setfacl command?

This utility sets Access Control Lists (ACLs) of files and directories. On the command line, a sequence of commands is followed by a sequence of files (which in turn can be followed by another sequence of commands, …).

The options -m, and -x expect an ACL on the command line. Multiple ACL entries are separated by comma characters (‘,’). The options -M, and -X read an ACL from a file or from standard input. The ACL entry format is described in Section ACL ENTRIES.

Finally I executed following command which solved my issue.

chown purab: /home/purab -R
setfacl -R -m apache:rwx /home/purab

Using above command I kept purab directory permission to purab user again so purab user has all permission of directory. Using setfacl command I given permission to apache user for read, write and execute permission. It worked for me and solved my issue.

Install skpye 4.3 on Lunix

Skepe is Open source application for calling over internet. In this article we will guide you to Install skpye 4.3 on Lunix.

Skype calls & messages are completely FREE. Skype to Landlines and mobile phones low calling rate compare with mobile phones due to this skype is really popular among the internet user and corporate offices.

Skype announced new release of Skype 4.3 for Linux on June 18th 2014. It can be installed on any windows, linux, mac OS. Skype is acquired by Microsoft Corporation now and they are doing new development for skype application.

New 4.3 skype has following features:

  • An updated UI
  • Our new cloud-based Group Chat experience
  • More reliable file transfer support when using multiple devices at once
  • Greater accessibility by blind and visually impaired users
  • PulseAudio 3.0 and 4.0 support
  • Lot of bug fixes

Install skpye 4.3 on Lunix

Install Required Repositories

# For CentOS, RHEL, SL & Fedora 21 & other linux Systems #
# yum install qtwebkit

Following list of packages should be install on your OS.

# Install the necessary packages #
# yum install alsa-lib libXv libXScrnSaver gtk2-engines PackageKit-gtk-module libcanberra libcanberra-gtk2

# Install the necessary audio packages #
# yum install pulseaudio-libs alsa-plugins-pulseaudio<

# Install the necessary video package #
# yum install libv4l

Download skype ZIP file

Use the below command to download the skype 4.3 archive file.

# wget http://download.skype.com/linux/skype-4.3.0.37.tar.bz2
# tar -jxvf skype-4.3.0.37.tar.bz2

Create Launcher

For accessing the installed software on your system globally, you need to create the launcher file to /usr/bin/skyp and give executable permission then add the below script in that file. Save + Exit.

# touch /usr/bin/skype
# chmod 755 /usr/bin/skype

# Add Launcher script #
# nano /usr/bin/skype

#!/bin/sh
export SKYPE_HOME="/opt/skype-4.3.0.37"
$SKYPE_HOME/skype --resources=$SKYPE_HOME $*

We need to create below list of Symbolic Links.

# ln -s /opt/skype-4.3.0.37/icons/SkypeBlue_48x48.png /usr/share/icons/skype.png
# ln -s /opt/skype-4.3.0.37/icons/SkypeBlue_48x48.png /usr/share/pixmaps/skype.png
# ln -s /opt/skype-4.3.0.37/skype.desktop /usr/share/applications/skype.desktop
# ln -s /opt/skype-4.3.0.37/sounds/ /usr/share/sounds/
# ln -s /opt/skype-4.3.0.37/lang/ /usr/share/lang/

Use the below command to launch the skype from command line.

# skype

Congratulations, you installed skype 4.3 version to your linux OS. Now we can start using skype on our linux systems.

install php mysql apache on centos 7

In this tutorial we are going to tell you how to install php mysql apache on centos 7 with very easy and simple steps and guide.
LAMP is becoming more popular these day. Many people are using LAMP for server solutions.

Add EPEL-7 to your linux os with latest phpMyadmin.

rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Now install mysql-server and client. first became root user and execute following command
yum install mysql-server mysql
mysql_secure_installation

Install Apache2

CentOS 7.0 ships with apache 2.4. Apache2 is directly available as a CentOS 7.0 package, therefore we can install it like this:

yum -y install httpd

By default apache will be installed, but it is not installed then install apache using above command

Start apache and start apache at boot time using following command

systemctl start httpd.service
systemctl enable httpd.service

In CentOS 7.0 uses Firewall-cmd command, so I will customize it to allow external access to port 80 (http) and 443 (https).

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Now direct your browser to http://192.168.0.109.

Install PHP5

yum -y install php php-common phpmyadmin

We must restart Apache afterwards:

systemctl restart httpd.service

Now time to test php and apache version.
The document root of the default website is /var/www/html. We can create info.php file and put in document root folder

vi /var/www/html/info.php

put following code in that file

<?php echo phpinfo(); ?>

Now we call that file in a browser (e.g. http://192.168.0.109/info.php):

Now we can install some useful PHP moduels which can be required for CMS Systems like WordPress, Joomla and Drupal:

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

Now restart Apache2:

systemctl restart httpd.service

congrats! now you installed apache, php and mysql on your system. Now you are able to execute any php application on your server.

install apache 2.4, php 5.5 and mysql on centos 6/7

In the article we will tell you to install apache 2.4, php 5.5 and mysql on centos 6/7 with this we will guide you about installing phpmyadmin and related php and mysql modules.

LMAP is becoming more and more popular these days. People are using more vps and dedicated servers for their sites and applications. PHP backend is became more popular so here in this post we will tell you about installation on linux system’s.

Here I am using centos 6 for installation. From sept 2015 php 5.4 is no longer supported by PHP team so people are trying to install PHP 5.5+ version for good security and performance purpose on their linux servers.

install apache 2.4, php 5.5 and mysql on centos 6/7

Install Remi Repository

Remi is a repository where you can find the latest versions of the PHP  in this repository we can find latest programs and dependencies.

# yum update && yum install epel-release
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Enable Remi Repository

Open following remi.repo file and change enabled=0 to 1 for php55 tag. Here we want to install PHP 5.5 version on centos machine.

# vim /etc/yum.repos.d/remi.repo

After opening this file just edit this file and change enabled flag to 1 for php55 section
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-php55]
name=Remi's PHP 5.5 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php55/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php55/mirror
# NOTICE: common dependencies are in "remi-safe"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
 

Afer enabling remi repository. Now it is time to install PHP and apche and mysql

# yum --enablerepo=remi install httpd mysql mysql-server php php-common mod_php phpmyadmin

Step 4: Installing PHP Modules

Do not forget to accept installation and type Y when you asked while installation.     After installation run following command which will be useful while rebooting server(linux). After rebooting server following service will automatically started.   —— Enable Apache and MySQL on Boot ——

# chkconfig --levels 235 httpd on
# chkconfig --levels 235 mysqld on

—— Start Apache and MySQL ——

# /etc/init.d/httpd start
# /etc/init.d/mysqld start

Verify PHP 5.5

Go to /var/www/html directoy and create file called phpinfo.php using following command.

#vi phpinfo.php

put following code in that file.

<?php echo phpinfo(); ?>

Execute php.info file on your web browser

You can check your installation on command prompt also. For checking php modules use following command.

#Php -m

above command will list all php modules which are installed on your centos machine

Congratulations! Just now you completed your php 5.5, apache and mysql installation on your linux box.

 

how to install varnish with wordpress and apache

There are many caching solution available in open source. But Varnish is best in among. In this article, We given full steps to use and install varnish with wordpress and apache server . varnish setup with your wordpress site. Many website webmasters installed Varnish on their production servers to handle millions of requests without delay in response. There are many caching plugin like W3 Total Cache, WP Super Cache, Hyper Cache and so many..

Varnish is open source software

Varnish is free open source software licensed under a two-clause BSD licence aimed to really super boost server performance. In short, it will work as web accelerator between any server that speaks with HTTP (Apache or any other).

how to install varnish with wordpress and apache
how to install varnish with wordpress and apache

Why Apache or Nginx is Enough to Handle Huge Traffic
Many system administrator do many tricks with Apache because it performs really bad when the server is getting very high requests. Some people started using other servers like Ngnix and LiteSpeed. WordPress itself are using Ngnix server for many years for production environment. But still performance and response time of website is not that much fast with these plugins. So Best solution is Varnich Cache.

Varnish Explained Here

Vanish server started working on top of Apache server. When HTTP request comes to server first it will go the varnish server, If Vanish server has the response in memory cache then it will give response immediately, If Varnish server does not has cache for that request then it will go to apache server and get the response and keep in cache. Next request will delivered by Varinish cache, which will be so fast. Using varnish cache you can increase your server performance and response time by 300 to 900x. I personally checked response time difference. Before installing varnish cache my server response time was 3.46 second. After installing Varnish Cache, my server response time was 0.3, Means My server response increased by 1000x.

In following diagram, we explained, how varnish server process request.

varnish processing request compressed, how to install varnish with wordpress and apache
varnish processing request compressed, how to install varnish with wordpress and apache

Why install varnish with wordpress

  1. It will reduce server load , by reducing CPU work
  2. It will load your load your WordPress website very fast, because vanish cache stored in RAM.
  3. Your wordpress site SEO will increase, Because your site will load so fast
  4. Response time will reduce by 1000x
  5. Google page speed response score improves by at-least 20%

how to install varnish with wordpress and apache

Note: You can use this tutorial for setup varnish with any apache website. If you used HTML, ROR, JAVA, PHP for your website than you can set up varinish as we shown in this article. Here, we are assuming you already installed wordpress with apache server on linux server.

We are using dedicated Linux (centos) server for hosting our sites. So here we given steps can be applicable for Red Hat, Centos, Fedora, ubuntu server. But for ubuntu server you need use “apt-get install” instead of yum install.

So now Just follow my steps to install the varnish server. For latest version of Linux, you don’t need to install repository. But for older linux version you need to install the Varnish server repository. For that use following command to install varnish repository.

rpm -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm

Than you will be ready for install varnish server. Use following command for installing varnish server. You need to run following command as root. So first became root.

yum install varnish

Configure Varnish to work on port 80

usually Apache run on port 80 and your all sites will run on port 80. So as I told you earlier in this article. (check Varnish Explained section) Varnish work on top of apache server So you need to set up varnish on port 80. In CentOS, RedHat, Fedora, and Ubuntu server, Varnish configuration file located in “/etc/sysconfig/varnish”. You can edit file using vim or vi editor or you can download file to your PC and edit it then upload to server.

I am using vim here.


vim /etc/sysconfig/varnish

Please change files first part code as per I shown in image. OR you can download setting file from here:

[viral-lock message=”Download Link 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.”]

https://github.com/purab/varnish/blob/master/varnish
 

[/viral-lock]

  • Change Default Varnish Config file

Got to “Alternative 2” section and change setting as I shown in image. Un-comment all the lines after “Alternative 2” as I shown.

By default -s setting will be pointed to filesystem, change that to memory. This is important, because we want, varnish give response from memory.

you need to change “-a : 6081 \” to “-a : 80 \” as we shown here in image. You can change “256m” to higher number, which is depends on your server configuration. If you have higher memory server then you can 512mb or 1GB for Varnish server. Many websites are using 4gb for varinsh servers. But they have a huge amount of traffic.

varnish configuration, install varnish with wordpress and apache
varnish configuration, install varnish with wordpress and apache

 Second Part of configuration – go to end of file, using “shit+g” key. Change configuration as per I shown.

Got to “Alternative 3” section and change setting as I shown in image. Comment all the lines after “Alternative 3”

varnish default config , install varnish with wordpress and apache
varnish default config , install varnish with wordpress and apache
  •  Change server config of Varnish

Like Apache server, Varnish server VCL file found in “/etc/varnish/default.vcl” location. Varnish VCL file is configuration for looking for apache(server) response data(content). You can edit this file using vim editor as per shown in following image OR you can download file from following location.

[viral-lock message=”Download Link 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.”]

https://github.com/purab/varnish/blob/master/default.vcl
 

[/viral-lock]

 

varnish server config, install varnish with wordpress and apache
varnish server config, install varnish with wordpress and apache

Change the port 80 to 8080 port as We shown in image. Means Varnish server will generate cache from port 8080 so you need configure your apache server on port 8080.


backend default {
.host = "127.0.0.1";
.port = "8080";
}

Now Varnish configuration is complete. Now we need to configure apache server to send apache in back of varnish server.

You need to change following setting of your apache server. By default apache config file is htttpd.conf or apache.conf file. You will find this file in “/etc/httpd/conf/httpd.conf” location. For ubuntu that will be other location. Open your apache config file.

You can download apache configuration file from here. You can refer only “custom.conf” file. it has all changed configuration.

https://github.com/purab/varnish/blob/master/custom.conf
https://github.com/purab/varnish/blob/master/httpd.conf

We created custom.conf file and added under “/etc/httpd/conf.d/” folder. So that file will be automatically loaded in apache config.

You can add following code in your apache configuration file as we shown in following image. You need to change the NameVirtualHost 80 to 8080. So your apache server will run on port 8080.

apache server config with varnish,  install varnish with wordpress and apache
apache server config with varnish, install varnish with wordpress and apache

You need to change VirtualHost entries for each of your domain. This is very important, If you do not change this properly then your apache server will through error while restarting.


NameVirtualHost *:8080

#Browser cache code
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
BrowserMatch \bOpera !no-gzip
Header append Vary User-Agent

#purabtech.in
<VirtualHost *:8080>
ServerAdmin purabdk@gmail.com
DocumentRoot /home/siwan/purabtech.in
ServerName purabtech.in
ServerAlias www.purabtech.in
ErrorLog logs/wordpressapi-error_log
CustomLog logs/wordpressapi-access_log common
</VirtualHost>

 

  •  Now your Varnish and Apache configuration are done. So time to restart both servers.

First Stop the Apache server and start the Varnish server. After starting Varnish server. Again start the apache server. You can use following commands step by step. Use commands in following order.


service httpd stop

service varnish start

service httpd start

Note: If you try to start varnish server without stopping apache server then it will never start because it will try to start using port 80.

  • Test Website performance and response time

How can you test your site pages speed and response time. Go to following “Google pagespeed” URL to test the website response time.

PageSpeed Insights 

Check Varnish service is running for your site. go to following URL and add your website URL in inputbox and select “service scan” checkbox and click on go button.

http://centralops.net/co/domaindossier.aspx

You will get response as shown in following image.

varnish-detection-response

As per explained in this article. After varnish configuration, your website will perform much faster then earlier and server CPU will not be consumed by apache server. We are using small dedicated server so we used only 256mb memory. If you have 1gb RAM of our server then use 256mb means one-fourth of memory for varnish server. When you have all code and database of same server.

Varnish Useful commands

# varnishlog : Provides detailed information on requests.
# varnishtop : It reads varnishd shared memory logs and presents a most commonly occurring log entries.
# varnishadm : Command-line varnish administration used to reload vcl and purge urls.
# varnishstat : Provides all the info you need to spot cache misses and errors.
# varnishhist : Provides a histogram view of cache hits/misses.

By “varnishstat” command you can check real-time statistics of varnish server. You can see following items

  • Client connection
  • Hit rate ration
  • Hit rate average
  • Number of client connections accepted

Following is screenshot of my production site. There are a lot of useful data provided by varnish stats

varnish varnishstat, install varnish with wordpress and apache
varnish varnishstat, install varnish with wordpress and apache

 

Create Varnish Log File

Using following command you can create varnish request log file as per apache log file. In this file you will get similar information like apache access log.


varnishncsa -c -a -d -w /var/log/varnish/varnish.log

For more varnish commands you can go to varnish site using following URL.

https://www.varnish-software.com/static/book/Getting_started.html#the-management-interface

Now you are set with varnish server and wordpress site. Above article can be used for any linux distribution like, Fedora, Ubuntu, Centos, RedHat and Suse. Commands will be same and configuration will be same.

In wordpress configuration you do not need to change anything. With Varnish server .htaccess file will not break because still main webserver is  apache.

If you still need assistance to install Varnish server and configure production server then contact to me.

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.