Friday, 22 April 2016
Update your repo list with below command
$ sudo apt-get update
-- > Install Apache 2.4.18
$ sudo apt-get install apache2
-- > Install PHP 7.0
$ sudo apt-get install php7.0 libapache2-mod-php7.0 php7.0-mysql php7.0-curl php7.0-json
-- > Install MySQL 5.7
$ sudo apt-get install mysql-server
Create info.php file at /var/www/html/info.php with your favorite editor and paste below mentioned code in that file and check php7 with apache2 is running.
<?php
phpinfo();
?>
-- > Once finish with info.php open http://localhost/info.php or http://127.0.0.1/info.php then you can able to see page like below.
Its done Enjoy !!!! :)
Thursday, 20 August 2015
PHP Warning: shell_exec() has been disabled for security reasons
PHP Warning: shell_exec() has been disabled for security reasons
To start shell command execution in php code you need to edit php.ini and remove "shell_exec" from disable_functions line. below is the example of line
disable_functions = show_source,system,shell_exec,proc_open
to
disable_functions = show_source,system,proc_open
After remove the "shell_exec" save the php.ini file and Restart webserver.
Its done Enjoy !!!! :)
Wednesday, 6 May 2015
Creating a Redhat package repository
# yum repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repolist: 0
Run below command to check your CD or ISO file mounted on you machine.
# mount | grep iso9660
/dev/sr0 on /media/RHEL_6.4 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)
Now You can make repo file to listen repo management.
# nano /etc/yum.repos.d/RHEL64.repo
and paste below mentioned lines.
[RHEL64]
name=RHEL64
baseurl="file:///media/RHEL_6.4 x86_64 Disc 1/"
gpgcheck=0
Once created repo file check with below.
# yum repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id repo name status
RHEL_6.4_Disc RHEL_6.4_x86_64_Disc 3,648
repolist: 3,648
Now You can able to install default packages which is stored in you Disk like below.
[root@vm ~]# yum install httpd
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-26.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.2.15-26.el6 RHEL64 821 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 821 k
Installed size: 2.9 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : httpd-2.2.15-26.el6.x86_64 1/1
Verifying : httpd-2.2.15-26.el6.x86_64 1/1
Installed:
httpd.x86_64 0:2.2.15-26.el6
Complete!
Monday, 4 May 2015
PDOException: SQLSTATE[42000]: 1148 The used command is not allowed with this MySQL version in AWS RDS
To Resolve this error you have to connect mysql with below command then you can able to run LOCAL INFILE command in mysql console or drupal.
# mysql --local-infile=1 -h rds-amazon-url.com -uroot -p
Now you can able to run LOCAL INFILE command in RDS.
#mysql>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE foo
COLUMNS TERMINATED BY '\t';
# mysql --local-infile=1 -h rds-amazon-url.com -uroot -p
Now you can able to run LOCAL INFILE command in RDS.
#mysql>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE foo
COLUMNS TERMINATED BY '\t';
Thursday, 30 April 2015
How to run a simple PHP web server
# php -S localhost:8000 -t /path/to/folder/directory
Above command give output like below
PHP 5.6.4-4ubuntu6 Development Server started at Thu Apr 30 15:10:00 2015
Listening on http://localhost:8000
Document root is /var/www/html
Press Ctrl-C to quit.
Now you can open the localhost:8000 in your browser to check the webpage.
Above command give output like below
PHP 5.6.4-4ubuntu6 Development Server started at Thu Apr 30 15:10:00 2015
Listening on http://localhost:8000
Document root is /var/www/html
Press Ctrl-C to quit.
Now you can open the localhost:8000 in your browser to check the webpage.
Wednesday, 22 April 2015
Install apache2 Webserver, php5 and php module with script for beginner
Install apache2 Webserver with script for beginner
Find the script to install apache2 Webserver and php5 with php modules like cgi php5-mcrypt php5-mysql php-pear php5-gd php5-curl php5-cgi php5-cli php5-common php5-json php5-memcache php5-memcached
Click to Download Script
Find the script to install apache2 Webserver and php5 with php modules like cgi php5-mcrypt php5-mysql php-pear php5-gd php5-curl php5-cgi php5-cli php5-common php5-json php5-memcache php5-memcached
Click to Download Script
Tuesday, 21 April 2015
Use PHP5-FPM with Apache 2 on Ubuntu 14.04
Install Apache by following command
#sudo apt-get update
#sudo apt-get install apache2-mpm-event
To use PHP5-FPM with Apache, we need to install libapache2-mod-fastcgi module. The libapache2-mod-fastcgi module is not available in the Ubuntu package. Therefore, we need to update the apt sources. Follow these steps.
Run the following command to edit the source list:
#sudo nano /etc/apt/sources.list
Add the following lines at the end of the file:
deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
Save and Close this file.
Install libapache2-mod-fastcgi Module
#sudo apt-get update
#sudo apt-get install libapache2-mod-fastcgi
Install PHP5-FPM with the following command
#sudo apt-get install php5-fpm
Create the PHP5-FPM configuration file for Apache
#sudo nano /etc/apache2/conf-available/php5-fpm.conf
... then add the following lines
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -idle-timeout 900 -socket /var/run/php5-fpm.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
Save and Close this file.
Enable the new modules and configuration for Apache
#sudo a2enmod actions fastcgi alias
#sudo a2enconf php5-fpm
Finally, restart Apache
#sudo service apache2 restart
Use PHP5-FPM with Apache 2 on Ubuntu 14.04
#sudo nano /var/www/html/info.php
Add the following content to the file
<?php phpinfo(); ?>
Save and Close this file.
Now open the http://localhost/info.php in browser. Upon success, you will see information about PHP and your server. Your setup is now complete.
#sudo apt-get update
#sudo apt-get install apache2-mpm-event
To use PHP5-FPM with Apache, we need to install libapache2-mod-fastcgi module. The libapache2-mod-fastcgi module is not available in the Ubuntu package. Therefore, we need to update the apt sources. Follow these steps.
Run the following command to edit the source list:
#sudo nano /etc/apt/sources.list
Add the following lines at the end of the file:
deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
Save and Close this file.
Install libapache2-mod-fastcgi Module
#sudo apt-get update
#sudo apt-get install libapache2-mod-fastcgi
Install PHP5-FPM with the following command
#sudo apt-get install php5-fpm
Create the PHP5-FPM configuration file for Apache
#sudo nano /etc/apache2/conf-available/php5-fpm.conf
... then add the following lines
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -idle-timeout 900 -socket /var/run/php5-fpm.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
Save and Close this file.
Enable the new modules and configuration for Apache
#sudo a2enmod actions fastcgi alias
#sudo a2enconf php5-fpm
Finally, restart Apache
#sudo service apache2 restart
Use PHP5-FPM with Apache 2 on Ubuntu 14.04
#sudo nano /var/www/html/info.php
Add the following content to the file
<?php phpinfo(); ?>
Save and Close this file.
Now open the http://localhost/info.php in browser. Upon success, you will see information about PHP and your server. Your setup is now complete.
Tuesday, 7 April 2015
Give permission yo users to run command with SUDO
All linux user got this error while run command with restricted user.
"User not in the sudoers file. This incident will be reported"
To provide permission to user to run command with SUDO, Do as followed
#sudo /usr/sbin/visudo or visudo
Find below line,
"# Allow members of group sudo to execute any command"
Then add below line without quote.
"username ALL=(ALL) ALL"
"User not in the sudoers file. This incident will be reported"
To provide permission to user to run command with SUDO, Do as followed
#sudo /usr/sbin/visudo or visudo
Find below line,
"# Allow members of group sudo to execute any command"
Then add below line without quote.
"username ALL=(ALL) ALL"
Create SFTP User with chroot in AWS EC2
Create User with below command
#adduser --shell=/bin/false theitideas
Provide permission of home directory
#chown root:theitideas /home/theitideas/
#chmod 755 /home/theitideas/
Create Folder to be access via sftp and provide permission
#mkdir /home/theitideas/workspace
#chown theitideas:theitideas /home/theitideas/workspace/
#chmod 755 /home/theitideas/workspace/
Generate ssh key to access instance via sftp
#cd /home/theitideas
#mkdir .ssh
#cd .ssh
#ssh-keygen -t rsa -f theitideas
#touch authorized_keys
#cat theitideas.pub > authorized_keys
#cd ..
#ssh-keygen -A
Change the permission of generated key and .ssh folder
#chmod go-w /home/theitideas/
#chown -R theitideas:theitideas .ssh/
#chmod 700 .ssh/
#chmod 600 .ssh/authorized_keys
Open ssh config file and make below mentioned changes.
#nano /etc/ssh/sshd_config
find "Subsystem sftp /usr/lib/openssh/sftp-server" line in opened file and add "#" on first to comment out the line
#Subsystem sftp /usr/lib/openssh/sftp-server
and add the following at the bottom of the file:
Subsystem sftp internal-sftp
Match User theitideas
ChrootDirectory %h
ForceCommand internal-sftp
X11Forwarding no
AllowTCPForwarding no
Once close the file restart the ssh service with below command
#service ssh restart
You can download (theitideas) private key from server then you can able to access sftp connection with private key (theitideas).
command to connect sftp with private key
#sftp -i theitideas theitideas@12.34.56.67
Hurray !!! :)
#adduser --shell=/bin/false theitideas
Provide permission of home directory
#chown root:theitideas /home/theitideas/
#chmod 755 /home/theitideas/
Create Folder to be access via sftp and provide permission
#mkdir /home/theitideas/workspace
#chown theitideas:theitideas /home/theitideas/workspace/
#chmod 755 /home/theitideas/workspace/
Generate ssh key to access instance via sftp
#cd /home/theitideas
#mkdir .ssh
#cd .ssh
#ssh-keygen -t rsa -f theitideas
#touch authorized_keys
#cat theitideas.pub > authorized_keys
#cd ..
#ssh-keygen -A
Change the permission of generated key and .ssh folder
#chmod go-w /home/theitideas/
#chown -R theitideas:theitideas .ssh/
#chmod 700 .ssh/
#chmod 600 .ssh/authorized_keys
Open ssh config file and make below mentioned changes.
#nano /etc/ssh/sshd_config
find "Subsystem sftp /usr/lib/openssh/sftp-server" line in opened file and add "#" on first to comment out the line
#Subsystem sftp /usr/lib/openssh/sftp-server
and add the following at the bottom of the file:
Subsystem sftp internal-sftp
Match User theitideas
ChrootDirectory %h
ForceCommand internal-sftp
X11Forwarding no
AllowTCPForwarding no
Once close the file restart the ssh service with below command
#service ssh restart
You can download (theitideas) private key from server then you can able to access sftp connection with private key (theitideas).
command to connect sftp with private key
#sftp -i theitideas theitideas@12.34.56.67
Hurray !!! :)
Saturday, 4 April 2015
How to Delete ElasticBeanstalk bucket
How to Delete ElasticBeanstalk bucket.
If you can’t delete Elastic Beanstalk created bucket, first remove all files inside the bucket then remove the bucket policy.
Go to the bucket’s policy (bucket –> properties –> permissions –> edit bucket policy)
Save the change to the Bucket Policy.
Now right click on the bucket and press delete.
If you can’t delete Elastic Beanstalk created bucket, first remove all files inside the bucket then remove the bucket policy.
Go to the bucket’s policy (bucket –> properties –> permissions –> edit bucket policy)
Save the change to the Bucket Policy.
Now right click on the bucket and press delete.
Wednesday, 1 April 2015
How to Use Python ‘SimpleHTTPServer’ to Serve Files Instantly
How to Use Python ‘SimpleHTTPServer’ to Serve Files Instantly
first check is python available or not.
#python –V
If command return version means you have python installed.
Now reach to your source folder which you wants to serve via http to others. like below
#cd theitideas <---- folder
Then enter below command to start serve your source folder.
#python -m SimpleHTTPServer
Now you can able to view and download your folder items via http protocol with browser. eg. localhost:8000 or 12.34.56.78:8000
first check is python available or not.
#python –V
If command return version means you have python installed.
Now reach to your source folder which you wants to serve via http to others. like below
#cd theitideas <---- folder
Then enter below command to start serve your source folder.
#python -m SimpleHTTPServer
Now you can able to view and download your folder items via http protocol with browser. eg. localhost:8000 or 12.34.56.78:8000
Tuesday, 31 March 2015
Create new user in AWS EC2
Create new user in AWS EC2
First of all user in your Instance
#sudo su
#adduser theitideas <-- keep password with you to fire command with sudo
Login with new user
#su theitideas
Generate private and public key for new user.
#ssh-keygen -t rsa
#cd /home/theitideas/.ssh/
#touch authorized_keys
#cat id_rsa.pub > authorized_keys
#exit
Make entry to your to access command with sudo in visudo file
#visudo <-- once this file open find "Allow members of group sudo to execute any command" and enter below mentioned line in that file then save and close.
theitideas ALL=(ALL:ALL) ALL
Provide below permissios
#chmod go-w /home/theitideas
#chmod 700 /home/theitideas/.ssh
#chmod 600 /home/theitideas/.ssh/authorized_keys
Now copy or download private (id_rsa)key from server to your local machine to login.
#cat id_rsa
All done now you can login with your private key (id_rsa) like below from your machine.
#ssh -i id_rsa theitideas@12.34.45.56
Hurray !!!! :)
First of all user in your Instance
#sudo su
#adduser theitideas <-- keep password with you to fire command with sudo
Login with new user
#su theitideas
Generate private and public key for new user.
#ssh-keygen -t rsa
#cd /home/theitideas/.ssh/
#touch authorized_keys
#cat id_rsa.pub > authorized_keys
#exit
Make entry to your to access command with sudo in visudo file
#visudo <-- once this file open find "Allow members of group sudo to execute any command" and enter below mentioned line in that file then save and close.
theitideas ALL=(ALL:ALL) ALL
Provide below permissios
#chmod go-w /home/theitideas
#chmod 700 /home/theitideas/.ssh
#chmod 600 /home/theitideas/.ssh/authorized_keys
Now copy or download private (id_rsa)key from server to your local machine to login.
#cat id_rsa
All done now you can login with your private key (id_rsa) like below from your machine.
#ssh -i id_rsa theitideas@12.34.45.56
Hurray !!!! :)
Tuesday, 16 December 2014
How to resolve mcrypt extension missing error.
Error Message
"The mcrypt extension is missing. Please check your PHP configuration"
#apt-get install php5-mcrypt
#ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available or If this command not work fire below one for latest apache.
#ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/mods-available/
#php5enmod mcrypt
#service apache2 restart
Reload and check error message gone.
"The mcrypt extension is missing. Please check your PHP configuration"
#apt-get install php5-mcrypt
#ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available or If this command not work fire below one for latest apache.
#ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/mods-available/
#php5enmod mcrypt
#service apache2 restart
Reload and check error message gone.
How to upload EC2 Data to S3 Bucket with s3cmd
Install s3cmd third party software in EC2 Instance.
#apt-get install s3cmd
Configure s3cmd to access your S3 Bucket with below prodecure.
#s3cmd --configure
Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.
Access key and Secret key are your identifiers for Amazon S3
Access Key : PASTE YOUR ACCESS KEY
Secret Key : PASTE YOUR SECRET KEY
Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: ENTER
Path to GPG program [/usr/bin/gpg]: ENTER
When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]: ENTER
On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't conect to S3 directly
HTTP Proxy server name: If your your are using internet proxy to connect internet provide details here or just press ENTER
New settings:
Access Key: YOUR ACCESS KEY
Secret Key: YOUR SERCET KEY
Encryption password:
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0
Test access with supplied credentials? [Y/n] Y
Please wait, attempting to list all buckets...
Success. Your access key and secret key worked fine :-)
Now verifying that encryption works...
Not configured. Never mind.
Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
s3cmd Setup is completed.
#s3cmd ls <--- This command will show your Buckets in your account.
2014-12-16 08:33 s3://bucketwork
<--- Now setup your Source folder and Destination S3 Bucket. --->
#s3cmd sync /home/ubuntu/backup/ s3://bucketwork/
WARNING: Redirected to: bucketwork.s3-ap-southeast-1.amazonaws.com
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
/home/ubuntu/backup/2014-12-16/mysql.gz -> s3://bucketwork/2014-12-16/mysql.gz [1 of 1]
375 of 375 100% in 0s 5.43 kB/s done
Done. Uploaded 375 bytes in 0.1 seconds, 5.19 kB/s
Its Done you can set this command as Cron to run whenever you need.
#apt-get install s3cmd
Configure s3cmd to access your S3 Bucket with below prodecure.
#s3cmd --configure
Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.
Access key and Secret key are your identifiers for Amazon S3
Access Key : PASTE YOUR ACCESS KEY
Secret Key : PASTE YOUR SECRET KEY
Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password: ENTER
Path to GPG program [/usr/bin/gpg]: ENTER
When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP and can't be used if you're behind a proxy
Use HTTPS protocol [No]: ENTER
On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't conect to S3 directly
HTTP Proxy server name: If your your are using internet proxy to connect internet provide details here or just press ENTER
New settings:
Access Key: YOUR ACCESS KEY
Secret Key: YOUR SERCET KEY
Encryption password:
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0
Test access with supplied credentials? [Y/n] Y
Please wait, attempting to list all buckets...
Success. Your access key and secret key worked fine :-)
Now verifying that encryption works...
Not configured. Never mind.
Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
s3cmd Setup is completed.
#s3cmd ls <--- This command will show your Buckets in your account.
2014-12-16 08:33 s3://bucketwork
<--- Now setup your Source folder and Destination S3 Bucket. --->
#s3cmd sync /home/ubuntu/backup/ s3://bucketwork/
WARNING: Redirected to: bucketwork.s3-ap-southeast-1.amazonaws.com
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
/home/ubuntu/backup/2014-12-16/mysql.gz -> s3://bucketwork/2014-12-16/mysql.gz [1 of 1]
375 of 375 100% in 0s 5.43 kB/s done
Done. Uploaded 375 bytes in 0.1 seconds, 5.19 kB/s
Its Done you can set this command as Cron to run whenever you need.
Friday, 12 December 2014
How to move github local folder to another location.
Open your GitHub Clone folder and move ".git" folder to your destination folder.
Eg. Clone folder :: /var/www/html/htmwebsite
Destination folder :: /var/www/html
#cd /var/www/html/htmlwebsite
#mv .git ../ or mv .git /var/www/html
Then you can move your all files and folder from htmlwebsite to destination folder
#cd /var/www/html/htmlwebsite
#mv * ../ or mv * /var/www/html
Thats It !! Now run status command to check git is recognise your destination folder or not.
#cd /var/www/html
#git status <--- If GitHub is recognize folder it will showing message like below ...
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
All Done !!!
Eg. Clone folder :: /var/www/html/htmwebsite
Destination folder :: /var/www/html
#cd /var/www/html/htmlwebsite
#mv .git ../ or mv .git /var/www/html
Then you can move your all files and folder from htmlwebsite to destination folder
#cd /var/www/html/htmlwebsite
#mv * ../ or mv * /var/www/html
Thats It !! Now run status command to check git is recognise your destination folder or not.
#cd /var/www/html
#git status <--- If GitHub is recognize folder it will showing message like below ...
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
All Done !!!
Basic GitHub Commands
Clone remote github repository.
#git clone https://github.com/accountnameexample/example.git
After modify files or folder commit your changes on github repository.
#git add filename
#git commit -a <-- Once you fire this command it will open nano editor to make note of this changes. Just write your note and save the file.
#git push https://github.com/accountnameexample/example.git <-- This command will upload all your changes to github repo.
To Receive changes from github Repo.
#git pull https://github.com/accountnameexample/example.git <-- This commnad will receive all changes from github repo to local repo.
#git clone https://github.com/accountnameexample/example.git
After modify files or folder commit your changes on github repository.
#git add filename
#git commit -a <-- Once you fire this command it will open nano editor to make note of this changes. Just write your note and save the file.
#git push https://github.com/accountnameexample/example.git <-- This command will upload all your changes to github repo.
To Receive changes from github Repo.
#git pull https://github.com/accountnameexample/example.git <-- This commnad will receive all changes from github repo to local repo.
Thursday, 11 December 2014
Installation and configuration of GeoIP module in php
After installation of Apache2 and php follow below step to achive country wise redirection.
#apt-get install libapache2-mod-geoip
Edit geoip.conf file and uncomment mentioned line.
#nano /etc/apache2/mods-available/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat <-- uncomment this line with remove # from starting of line.
</IfModule>
save and exit. Once restart apache server
#/etc/init.d/apache2 restart
Now, Make one file to test.
#nano /var/www/html/example.php
Enable mod rewrite module in php
#a2enmod rewrite
Again restart the apache server.
#service apache2 restart
Edit default apache host file and add below mentioned lines before </VirtualHost> tag to redirect url country wise.
#nano /etc/apache2/sites-available/000-default.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.yahoo.com$1 [R,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Save and exit. Once restart apache server.
#service apache2 restart
Brief Information about the lines.
1) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
Above line will redirect your default page to example.php in your root directory (html folder) If opened with INDIAN IP.
2) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
Above line will redirect your default page to 2.php in your root directory (html folder) If opened with GERMANY IP.
3) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.example.co.us$1 [R,L]
Above line will redirect your default page to another URL. If opened with US IP.
4) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Above line will redirect your default page to another URL. If opened with CANADA IP.
Use your desire setting to achive your goal !!
#apt-get install libapache2-mod-geoip
Edit geoip.conf file and uncomment mentioned line.
#nano /etc/apache2/mods-available/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat <-- uncomment this line with remove # from starting of line.
</IfModule>
save and exit. Once restart apache server
#/etc/init.d/apache2 restart
Now, Make one file to test.
#nano /var/www/html/example.php
Enable mod rewrite module in php
#a2enmod rewrite
Again restart the apache server.
#service apache2 restart
Edit default apache host file and add below mentioned lines before </VirtualHost> tag to redirect url country wise.
#nano /etc/apache2/sites-available/000-default.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.yahoo.com$1 [R,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Save and exit. Once restart apache server.
#service apache2 restart
Brief Information about the lines.
1) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
Above line will redirect your default page to example.php in your root directory (html folder) If opened with INDIAN IP.
2) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
Above line will redirect your default page to 2.php in your root directory (html folder) If opened with GERMANY IP.
3) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.example.co.us$1 [R,L]
Above line will redirect your default page to another URL. If opened with US IP.
4) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Above line will redirect your default page to another URL. If opened with CANADA IP.
Use your desire setting to achive your goal !!
Tuesday, 9 December 2014
Install MongoDB php driver in XAMPP/LAMPP
To install the php driver for MongoDB
Prerequisite ::
#sudo apt-get install autoconf
#export PHP_AUTOCONF=/usr/bin/autoconf
#sudo apt-get install gcc
#sudo apt-get install make
Installing mondodb phpdriver
#sudo /opt/lampp/bin/pecl install mongo
It will download and installing mongo php driver and given message as below
Build process completed successfully
Installing '/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226/mongo.so'
install ok: channel://pecl.php.net/mongo-1.5.8
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
Now, Just add below mentioned line into php.ini file.
extension=mongo.so
and restart the lampp
#sudo /opt/lampp/lampp restart
Prerequisite ::
#sudo apt-get install autoconf
#export PHP_AUTOCONF=/usr/bin/autoconf
#sudo apt-get install gcc
#sudo apt-get install make
Installing mondodb phpdriver
#sudo /opt/lampp/bin/pecl install mongo
It will download and installing mongo php driver and given message as below
Build process completed successfully
Installing '/opt/lampp/lib/php/extensions/no-debug-non-zts-20131226/mongo.so'
install ok: channel://pecl.php.net/mongo-1.5.8
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
Now, Just add below mentioned line into php.ini file.
extension=mongo.so
and restart the lampp
#sudo /opt/lampp/lampp restart
Wednesday, 3 December 2014
How to redirect HTTP to HTTPS
First you need to install SSL Certificate Successfully. Once your done that choose any of example to do redirect url.
Example : 1
In this example you don't need mod rewrite module to be enabled.
Open your apache configuration file
Example : 1
In this example you don't need mod rewrite module to be enabled.
Open your apache configuration file
#nano /etc/apache2/sites-enabled/000-default.conf
Modify your VirtualHost Tag as followed
<VirtualHost *:80>
ServerName www.example.com (your domain name)
Redirect / https://www.example.com/
</VirtualHost>
Save and exit. Restart apache service once
#service apache2 restart
Check your domain url with http it will redirect automatically on HTTPS.
Example : 2
In this Example you have to enable mod rewrite module first with below command
#a2enmod rewrite
Now, Copy below code in your .htaccess file without any changes on beginning of .htaccess file.
# BEGIN REWRITE SITEWIDE HTTP TO HTTPS
# This will enable the Rewrite capabilities
RewriteEngine On
# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on
# This rule will redirect users from their original location, to the same location but using HTTPS.
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
# END REWRITE SITEWIDE HTTP TO HTTPS
Save and exit from file.
Now open your apache configuration file and make mentioned changes in your file.
1) "AccessFileName .htaccess" tag should be open.
2) Check Directory tag and change "AllowOverride None" to "AllowOverride All"
e.g.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save and exit the file.
Restart Apache service once
#service apache2 restart
#service apache2 restart
Check your domain url with http it will redirect automatically on HTTPS.
Example : 2
In this Example you have to enable mod rewrite module first with below command
#a2enmod rewrite
Now, Copy below code in your .htaccess file without any changes on beginning of .htaccess file.
# BEGIN REWRITE SITEWIDE HTTP TO HTTPS
# This will enable the Rewrite capabilities
RewriteEngine On
# This checks to make sure the connection is not already HTTPS
RewriteCond %{HTTPS} !=on
# This rule will redirect users from their original location, to the same location but using HTTPS.
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
# END REWRITE SITEWIDE HTTP TO HTTPS
Save and exit from file.
Now open your apache configuration file and make mentioned changes in your file.
1) "AccessFileName .htaccess" tag should be open.
2) Check Directory tag and change "AllowOverride None" to "AllowOverride All"
e.g.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save and exit the file.
Restart Apache service once
#service apache2 restart
All Done Check now !!!

