Kamis, 27 Oktober 2016

Tips Untuk Mengamankan Apache Web Server

ali ini saya akan membahas cara atau tips untuk mengamankan web server apache dari gangguan tangan-tangan jahil :D. Walaupun mungkin tips ini ga akan mengamankan server anda secara 100%, tetapi setidaknya mengurangi celah 😀 . Ok langsung saja,
1. Menyebunyikan versi apache dan jenis OS.
Saat kita meng-install webserver apache, browser akan memunculkan versi apache dan jenis OS yang kita gunakan saat page yang kita browse tidak ditemukan atau error, seperti gambar dibawah ini:

Page Error
Dari gambar diatas, kita dapat melihat informasi mengenai versi apache yang digunakan dan jenis OS nya. Dengan munculnya informasi tersebut, maka ini merupakan sebuah celah keamanan yang dapat digunakan oleh para tangan-tangan jahil :D. Untuk itu kita perlu menyembunyikan informasi tersebut, agar terhindar dari eksploitasi. Berikut caranya:

# nano /etc/httpd/conf/httpd.conf (RHEL/CentOS/Fedora)
# nano /etc/apache/apache2.conf (Debian/Ubuntu)
ServerSignature Off
ServerTokens Prod
# service httpd restart (RHEL/CentOS/Fedora)
# service apache2 restart (Debian/Ubuntu)
Setelah SeverSignature & ServerTokens kita setting seperti diatas, maka saat page tidak ditemukan atau page error tampilan dibrowser akan seperti gambar dibawah ini:

Page Error

2. Disable Directory Listing
Secara default pada web server apache, apabila web directory kita tidak mempunyai file index, maka list file akan ditampilkan dibrowser seperti gambar berikut:

Directory Listing
Kita dapat menghilangkan fungsi directory listing pada apache dengan menambahkan command dibawah ini pada httpd.conf / apache2.conf

    Options -Indexes
Setelah itu restart apache servernya, maka sekarang saat kita browser web directory yang tidak mempunyai file index, maka akan ditampilkan seperti berikut ini:

No Directory Listing

3. Selalu Update Apache Secara Berkala.
Pastikan apache web server anda selalu update, karena diversi apache terbaru akan selalu ada patch untuk celah-celah keamanan pada versi sebelumnya.
# yum update httpd (RHEL/CentOS/Fedora)
# apt-get install apache2 (Debian/Ubuntu)
4. Disable Modul-Modul yang tidak digunakan.
Untuk melihat semua modul-modul yang aktif di server apache, bisa kita liat dengan cara berikut ini:
# grep LoadModule /etc/httpd/conf/httpd.conf

# have to place corresponding `LoadModule' lines at this location so the
# LoadModule foo_module modules/mod_foo.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
....
Dari list modul diatas dapat kita lihat modul yang sedang aktif secara default tetapi tidak digunakan/dibutuhkan, seperti: mod_imap,mod_include, mod_info, mod_userdir, mod_autoindex. Untuk disable modul tersebut, kita tinggal tambahkan tanda pagar “#” (tanpa tanda kutip) didepan LoadModule pada file /etc/httpd/conf/httpd.conf, kemudia restart apache server anda.

5. Gunakan Modul mod_security dan mod_evasive untuk keamanan Apache Server.
Mod_security
Mod_security bekerja sama seperti firewall untuk aplikasi web dan memonitoring webserver secara realtime. Ini dapat membantu kita untuk mengamankan aplikasi web dari jenis serangan brute force. Kita dapat meng-install mod_security di webserver kita seperti langkah dibawah ini:
Install mod_security on Ubuntu/Debian
$ sudo apt-get install libapache2-modsecurity
$ sudo a2enmod mod-security
$ sudo /etc/init.d/apache2 force-reload
Install mod_security on RHEL/CentOS/Fedora/
# yum install mod_security
# /etc/init.d/httpd restart
Mod_evasive
mod_evasive sangat efficient kita gunakan untuk menanggulangi DDOS Attack. Fitur mod_evasive dapat menangani serangan seperti HTTP Brute Force, DOS, dan DDOS. Berikut cara instalasi mod_evasive:

## For RHEL/CentOS 6.2/6.1/6/5.8 ##
# cd /usr/src 
# wget http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz
# tar xzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# apxs -cia mod_evasive20.c

## For Fedora 17,16,15,14,13,12 ##
# cd /usr/src 
# wget http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz
# tar xzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# apxs -cia mod_evasive20.c
Untuk konfigurasinya sebagai berikut:
Pada file httpd.conf cari modul evasive kemudian enable dengan cara menghilangkan tanda pagar # didepan modul tersebut. Jika tidak ada, silahkan tambahkan kedalam httpd.conf nya baris berikut ini:
LoadModule evasive20_module   /usr/lib/httpd/modules/mod_evasive20.so
Setelah itu, kita tambahkan parameter untuk modul mod_evasive pada baris terakhir konfigurasi apache/httpd.conf nya. Pada DOSEmailNotify silahkana isi dengan email anda, untuk mendapatkan notifikasi saat ada serangan Dos. Seperti berikut ini:

DOSHashTableSize    3097
DOSPageCount        2
DOSSiteCount        50
DOSPageInterval     1
DOSSiteInterval     1
DOSBlockingPeriod   60
DOSEmailNotify someone@somewhere.com


Setelah itu restart apache webservernya.

#service httpd restart

How to remove apache test page in CentOS

After you install apache web server in CentOS and point your browser to http://localhost you will see a Apache 2 Test Page powered by CentOS. You can disable or remove this apache test page from the configuration file. Before you do any modification, please make sure you have the privilege to reload the apache webserver.



To remove apache test page in CentOS, follow the steps below:-


Advertisements


  • Start your Terminal and login to your webserver thru SSH
  • Once logged in, edit this file with your favorite editor
  • The content of the file should look similar like this:-
  • To remove the apache test page, comments all the line like below:-
  • now reload your apache web server
    service httpd reload
  • Now point your browser to http://localhost and you shouldn't see any Apache Test Page again.





How To Create a SSL Certificate on Apache for CentOS 6

 About Self-Signed Certificates

A SSL certificate is a way to encrypt a site's information and create a more secure connection. Additionally, the certificate can show the virtual private server's identification information to site visitors. Certificate Authorities can issue SSL certificates that verify the virtual server's details while a self-signed certificate has no 3rd party corroboration.

Step One—Install Mod SSL

In order to set up the self signed certificate, we first have to be sure that Apache and Mod SSL are installed on our VPS. You can install both with one command:
yum install mod_ssl

Step Two—Create a New Directory

Next, we need to create a new directory where we will store the server key and certificate
mkdir /etc/httpd/ssl 

Step Three—Create a Self Signed Certificate

When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/httpd/ssl/apache.key -out /etc/httpd/ssl/apache.crt
With this command, we will be both creating the self-signed SSL certificate and the server key that protects it, and placing both of them into the new directory.
This command will prompt terminal to display a lists of fields that need to be filled in.
The most important line is "Common Name". Enter your official domain name here or, if you don't have one yet, your site's IP address.
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Awesome Inc
Organizational Unit Name (eg, section) []:Dept of Merriment
Common Name (e.g. server FQDN or YOUR name) []:example.com                  
Email Address []:webmaster@awesomeinc.com

Step Four—Set Up the Certificate

Now we have all of the required components of the finished certificate.The next thing to do is to set up the virtual hosts to display the new certificate.
Open up the SSL config file:
 vi /etc/httpd/conf.d/ssl.conf
Find the section that begins with and make some quick changes.
Uncomment the DocumentRoot and ServerName line and replace example.com with your DNS approved domain name or server IP address (it should be the same as the common name on the certificate):
 ServerName example.com:443
Find the following three lines, and make sure that they match the extensions below:
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/apache.crt
SSLCertificateKeyFile /etc/httpd/ssl/apache.key 
Your virtual host is now all set up! Save and Exit out of the file.

Step Five—Restart Apache

You are done. Restarting the Apache server will reload it with all of your changes in place.
 /etc/init.d/httpd restart

In your browser, type https://youraddress to view the new certificate.



Source : digitalocean.com

Senin, 17 Oktober 2016

Install OwnCloud in Linux

 Instalasi ownCloud di Linux CentOS 6.5

Saat ini cloud begitu populer dan menyimpan segala sesuatu melalui cloud adalah hal yang sangat biasa, contohnya menyimpan data di dropbox dan sebagainya. Begitu populernya penyimpanan di cloud sehingga muncul sebuah software OwnCloud yang merupakan aplikasi cloud storage over networkdengan menggunakan ownCloud user bisa berbagi data melalui network yang dapat diakses melalui web browser.
Saya sendiri sempet merekomendasikan salah satu customer freelance untuk menggunakan ownCloud ini untuk sharing data, itung-itung iseng mau coba diterapin di dunia nyata gimana sih hasilnya dan ternyata lumayan OK kok karena user itu lebih bersahabat dengan web-browser.
Aplikasi ini berbasis PHP dan sebuah database (SQLite, MySQL, MariaDB, Oracle atau PostgreSQL) sehingga kita bisa menggunakan ownCloud di berbagai platform yang memenuhi kriteria ini.
Dalam lab kali ini kita menggunakan Operating System CentOS 6.5, webserver yang digunakan adalah Apache dan database yang digunakan adalah MySQL.
Notes 
  • Pada lab kali ini, Selinux dalam keadaan disabled.
  • Pada lab kali ini, IPTables dalam keadaan disabled.
Install Database & Package Dependecies
[root@owncloud ~]# yum install httpd php php-mysql sqlite php-dom php-mbstring php-gd php-pdo php-json php-xml php-zip php-gd curl php-curl mysql-server -y

Notes
  • Karena ownCloud version yang saya gunakan memerlukan versi php 5.4.0 dan version php yang diinstall diatas adalah version 5.3.3 maka saya update seluruh packagesnya, langkah-langkahnya adalah sebagai berikut.
Install SCL Repo lalu install dependencies lainnya.
[root@owncloud ~]# yum install centos-release-SCL
[root@owncloud ~]# yum install php54 php54-php php54-php-gd php54-php-mbstring php54-php-mysqlnd


Lakukan backup untuk konfigurasi php53, karna kita sudah menginstall php54 seharusnya pada direktori /etc/httpd/conf.d/ terdapat file konfigurasi php54 yaitu, php54-php.conf
[root@owncloud ~]# mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php53.off

Restart Apache Services
[root@owncloud ~]# /etc/init.d/httpd restart

Download & Setup
[root@owncloud ~]# wget http://download.owncloud.org/community/daily/owncloud-daily-master.tar.bz2
[root@owncloud ~]# tar -jxvf owncloud-daily-master.tar.bz2
[root@owncloud ~]# mv owncloud /var/www/html/
[root@owncloud ~]# chown -R apache.apache /var/www/html/owncloud/

[root@owncloud ~]# chmod 777 /var/www/html/owncloud/config/

Edit /etc/httpd/conf/httpd.conf, lalu ganti parameter Allowoverride None menjadi Allowoverride All.

[root@owncloud ~]# vi /etc/httpd/conf/httpd.conf
....
AllowOverride All
....

Setelah selesai start database & web service dan jangan lupa buat persistent on boot.
[root@owncloud ~]# chkconfig mysqld on
[root@owncloud ~]# chkconfig httpd on
[root@owncloud ~]# /etc/init.d/httpd start
[root@owncloud ~]# /etc/init.d/mysqld start

Setting root password mysql.
[root@owncloud ~]# /usr/bin/mysqladmin -u root password 'centos'
[root@owncloud ~]# /usr/bin/mysqladmin -u root -h owncloud.arifzulfikarp.net password 'centos'

Buat database untuk owncloud.
[root@owncloud ~]# mysql -uroot -p
Enter password: centos

>

mysql> create database owncloud;
mysql> GRANT ALL ON owncloud.* to 'owncloud'@'localhost' IDENTIFIED BY 'centos';
mysql> flush privileges;
mysql> exit;


Lakukan ownCloud Install Melalui Web Browser
Setelah melakukan langkah-langkah diatas saatnya melakukan provisioning melalui web browsernya.
Sekarang kita dapat mengakses ownCloud 
http://ipaddress/owncloud 
atau 
http://domainname/owncloud 
Apabila berhasil akan muncul tampilan seperti dibawah ini.
Untuk konfigurasi awal ini kita harus mendefinisikan database yang akan digunakan oleh ownCloud dan username beserta password yang akan digunakan oleh admin user di kemudian hari.
Klik storage & database yang ada di kotak merah dari gambar atas, lalu isi parameternya menyesuaikan dengan konfigurasi yang telah kita lakukan. 
Pada lab kita kali ini parameter yang kita gunakan adalah.
Setting admin account sebagai berikut,
Admin User : admin
Password : centos@123
Setting data folder sebagai berikut,
Data Folder /var/www/html/owncloud/data (atau biarkan saja default seperti itu).
Setting database sebagai berikut, pilih MySQL/MariaDB.
Database User : owncloud
Database Password : centos
Database Name : owncloud
Database Host : localhost
Gambar lengkapnya seperti dibawah ini.
Setelah selesai klik Finish setup.
Apabila setup awal telah selesai dan berhasil maka kita akan di redirect ke dashboard ownCloud.
Saat ini ownCloud sudah siap digunakan, tinggal kita otak-atik aja karna penggunaan relatif mudah.



Source : http://arifzulfikarp.blogspot.co.id
RESET ADMIN PASSWORD

# For Debian based Systems #
$ sudo -u www-data php /var/www/dev.2daygeek.com/public_html/owncloud/occ user:resetpassword admin
Enter a new password:
Confirm the new password:
Successfully reset password for admin

# For RHEL based Systems #
$ sudo -u apache php /var/www/dev.2daygeek.com/public_html/owncloud/occ user:resetpassword admin
Enter a new password:
Confirm the new password:
Successfully reset password for admin

# For openSUSE Systems #
$ sudo -u www php /var/www/dev.2daygeek.com/public_html/owncloud/occ user:resetpassword admin
Enter a new password:
Confirm the new password:
Successfully reset password for admin




Upgrade PHP5.3 to 5.4

wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm
yum --enablerepo=remi upgrade php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml
 
 
 
 
 
 
1. Confirm your version of PHP is the CentOS 6.7 default

Type in the following:

rpm -qa | grep php

Should output similar to the following:

php-cli-5.3.3-46.el6_6.x86_64
php-common-5.3.3-46.el6_6.x86_64
php-5.3.3-46.el6_6.x86_64

Great, let’s move on.

2. Install and activate the REMI and EPEL RPM Repositories

Type in the following to download and install the required files:

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm

Now to enable the REMI repository globally:

nano /etc/yum.repos.d/remi.repo

Under the section that looks like [remi] make the following changes:

[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

Press CTRL-O to save, and CTRL-X to exit, and we can continue.

3. Update PHP from 5.3 to 5.4

Easy as pie, simply type in the following:

yum -y update php*

Once that’s done, we can verify:

rpm -qa | grep php

And we should see something similar to the below:

php-common-5.4.45-1.el6.remi.x86_64
php-5.4.45-1.el6.remi.x86_64
php-cli-5.4.45-1.el6.remi.x86_64

Make sure PHP is working correctly:

php -v

You should see something similar to the following:

PHP 5.4.45 (cli) (built: Sep 2 2015 18:54:00)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies



 Activate the new PHP version permanently:

source /opt/rh/php54/enable

Disable loading the old PHP 5.3 Apache module:

mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf/old

You should now have a /etc/httpd/conf.d/php54-php.conf file, which loads the correct PHP 5.4 module for Apache.

Finally, restart Apache:

service httpd restart

 

Minggu, 26 Juni 2016

How to Enable RPMForge Repository in RHEL/CentOS 7.x/6.x/5.x

Verifying RHEL/CentOS is 32 Bit or 64 Bit System

We use “uname -a” command to verify a system, whether it is 32 bit or 64 bit.
The 32 bit system will show i686 i686 i386 GNU/Linux and 64 bit server shows x86_64 x86_64 x86_64 GNU/Linux.
So, it’s very easy to verify whether a system is 32 or 64 bit using “uname -a” command from the command line shell.
32 Bit RHEL/CentOS
# uname -r

Linux tecmint.com 2.6.32-279.5.2.el6.i686 #1 SMP Thu Aug 23 22:16:48 UTC 2012 i686 i686 i386 GNU/Linux
64 Bit RHEL/CentOS
# uname -r

Linux tecmint.com 2.6.32-279.5.2.el6.i686 #1 SMP Thu Aug 23 22:16:48 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Installing RPMForge Repository in RHEL/CentOS 6/5/4

Download and Install RPMForge repository by selecting appropriate rpm package for your system.
For RHEL/CentOS 7 64 Bit
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
For RHEL/CentOS 6 32-64 Bit
## RHEL/CentOS 6 32 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.i686.rpm

## RHEL/CentOS 6 64 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
For RHEL/CentOS 5 32-64 Bit
## RHEL/CentOS 5 32 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm

## RHEL/CentOS 5 64 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
For RHEL/CentOS 4 32-64 Bit
## RHEL/CentOS 4 32 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.i386.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el4.rf.i386.rpm

## RHEL/CentOS 4 64 Bit OS ##
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.2-2.el4.rf.x86_64.rpm
Note : The RPMForge repository will be installed under /etc/yum.repod directory as a file rpmforge.repo.

Importing RPMForge Repository Key in RHEL/CentOS 7/6/5/4

Next, you’ll need to download and install DAG’s GPG key for your system.
# wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# rpm --import RPM-GPG-KEY.dag.txt
Note : The imported GPG key stored under /etc/pki/rpm-gpg directory as a file RPM-GPG-KEY-rpmforge-dag.

Installing Packages using RPMForge Repository in RHEL/CentOS 7/6/5/4

Let’s try installing something using rpmforge repository.
# yum --enablerepo=rpmforge install aria2
Sample Output :
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
rpmforge                                                                                                                                       
Setting up Install Process
Dependencies Resolved

=================================================================================================
 Package                         Arch   Version                Repository       Size
=================================================================================================
Installing:
 aria2                           i686           1.15.1-1.el6.rf        rpmforge         1.2 M
Installing for dependencies:
 nettle                          i686           2.2-1.el6.rf           rpmforge         359 k

Transaction Summary
=================================================================================================
Install       2 Package(s)
So, whenever a new packages are install using Yum command the RPMForge repository will be included.

Disable RPMForge Repository in RHEL/CentOS 7/6/5/4

To disable RPMForge repository simply open the file /etc/yum.repos.d/rpmforge.repo.
# vi /etc/yum.repos.d/rpmforge.repo
Change “enabled=1” to “enabled=0“. 0 means turn-off and 1 means turn-on.
### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
 
 
Source Tecmint.com 

Install VirtualBox in Centos 6.6

cd /etc/yum.repos.d
wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
 
Install EPEL
 
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm
 
yum --enablerepo=epel install dkms
 
yum groupinstall "Development Tools"
yum install kernel-devel
 
  

Installing VirtualBox

 

Go to the /etc/yum.repos.d/ directory:
cd /etc/yum.repos.d/
Add the latest oracle virtualbox repository to your CentOS server. You can download the oracle virtualbox latest repository from here.
wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
Add the virtualbox public key:
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
rpm --import oracle_vbox.asc
 
yum update && yum install VirtualBox-5.0
 
 
 

 

After installing virtualbox, add the virtualbox user sk_vuser to the vboxusers group.
usermod -G vboxusers sk_vuser
Now, run the following command to check if virtualbox kernel modules are loaded or not.
In CentOS 7.x:
systemctl status vboxdrv
In CentOS 6.x:
/etc/init.d/vboxdrv status
Sample output:
vboxdrv.service - LSB: VirtualBox Linux kernel module
   Loaded: loaded (/etc/rc.d/init.d/vboxdrv)
   Active: active (exited) since Thu 2015-06-11 19:20:09 IST; 19min ago
  Process: 561 ExecStart=/etc/rc.d/init.d/vboxdrv start (code=exited, status=0/SUCCESS)
Jun 11 19:20:04 server1.unixmen.local systemd[1]: Starting LSB: VirtualBox Linux kernel module...
Jun 11 19:20:09 server1.unixmen.local vboxdrv[561]: Starting VirtualBox kernel modules [  OK  ]
Jun 11 19:20:09 server1.unixmen.local systemd[1]: Started LSB: VirtualBox Linux kernel module.
If it, not loaded, run the following command to load them:
/etc/init.d/vboxdrv setup

Install Oracle VirtualBox Extension pack

Starting with VirtualBox 4.0, we should install Extension pack that will help us to manage and connect our remote guest consoles via web interface. This Extension pack provides the following functionalities to the VirtualBox guests.
  • The virtual USB 2.0 (EHCI) device
  • VirtualBox Remote Desktop Protocol (VRDP) support
  • Host webcam passthrough
  • Intel PXE boot ROM
  • Experimental support for PCI passthrough on Linux hosts
VirtualBox extension pack should be same version as VirtualBox base package. Download Extension pack for VirtualBox 4.3 from here.
wget http://download.virtualbox.org/virtualbox/4.3.28/Oracle_VM_VirtualBox_Extension_Pack-4.3.28-100309.vbox-extpack
Then, Install Extension pack as shown below.
sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.28-100309.vbox-extpack
Sample output:
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Successfully installed "Oracle VM VirtualBox Extension Pack".
That’s it Oracle VirtualBox and Extension pack have been installed successfully on our CentOS 6.5 server. Start using Oracle VirtualBox on your CentOS headless server. For creating and managing virtual machines from the command line, refer the official manual.
Instead, you can use Oracle VirtualBox GUI client called “phpvirtualbox”. to easily create and manage virtual machines via web browser of any remote desktop system.

Create and manage VMs from command line

First, let us create a Ubuntu 14.04 server VM with 512MB RAM and 8GB virtual hdd.
To do that, run:
VBoxManage createvm --name "Ubuntu 14.04" --register
Sample output:
Virtual machine 'Ubuntu 14.04' is created and registered.
UUID: 6ac096ec-01a8-4f5b-9a84-46f874eb7cfb
Settings file: '/root/VirtualBox VMs/Ubuntu 14.04/Ubuntu 14.04.vbox'
Next, assign the RAM size and network card mode(Bridge or NAT).
VBoxManage modifyvm "Ubuntu 14.04" --memory 512 --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0
Assign virtual hard drive size.
VBoxManage createhd --filename Ubuntu_14_04.vdi --size 8000
Sample Output:
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: 8d48aef4-eb92-4181-aed1-63ccbae0f2b1
Add Storage controller:
VBoxManage storagectl "Ubuntu 14.04" --name "IDE Controller" --add ide
Attach the Virtual hard drive file(vdi) to the storage controller using command:
VBoxManage storageattach "Ubuntu 14.04" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/sk/Ubuntu_14_04.vdi
Now, Assign the Ubuntu ISO media using command:
VBoxManage storageattach "Ubuntu 14.04 Server" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/sk/ubuntu-14.04-server-i386.iso
That’s it. The new VM has been created.
To know about VBoxManage command, run:
VBoxManage --help
Or, refer the Official guide.
Now, start the VM using command:
VBoxHeadless --startvm "Ubuntu 14.04"
To stop a running VM, enter the following command:
VBoxManage controlvm "Ubuntu 14.04" poweroff
Similarly we can pause a VM, using command:
VBoxManage controlvm "Ubuntu 14.04" pause
To reset a VM, enter:
VBoxManage controlvm "Ubuntu 14.04" reset
To learn more about VBoxHeadless options, run:
VBoxHeadless --help
Sample output:
Oracle VM VirtualBox Headless Interface 4.3.28
(C) 2008-2015 Oracle Corporation
All rights reserved.
Usage:
   -s, -startvm, --startvm    Start given VM (required argument)
   -v, -vrde, --vrde on|off|config       Enable (default) or disable the VRDE
                                         server or don't change the setting
   -e, -vrdeproperty, --vrdeproperty  Set a VRDE property:
                                         "TCP/Ports" - comma-separated list of ports
                                         the VRDE server can bind to. Use a dash between
                                         two port numbers to specify a range
                                         "TCP/Address" - interface IP the VRDE server
                                         will bind to
   --settingspw                      Specify the settings password
   --settingspwfile                Specify a file containing the settings password
   -c, -capture, --capture               Record the VM screen output to a file
   -w, --width                           Frame width when recording
   -h, --height                          Frame height when recording
   -r, --bitrate                         Recording bit rate when recording
   -f, --filename                        File name when recording. The codec used
                                         will be chosen based on the file extension
For more details, refer the official manual.
Creating and managing might be bit difficult and time consuming method for some lazy administrators. If you are one of them, there is another way to create and manage VMs in the headless from a Remote system web browser using a tool called “phpvirtualbox”.
You can use Oracle VirtualBox GUI client called “phpvirtualbox” to easily create and manage virtual machines via a web browser from any remote desktop system.

What is phpVirtualBox?

phpVirtualBox is an open source, web-based client written using PHP. It can be used to manage and administer Oracle VirtualBox headless instances.

Install phpVirtualBox

Before installing phpVirtualBox, we have to install Apache web server and PHP. To install Apache, PHP refer the following links.
Additionally, install php-soap extension which is required by phpVirtualBox to work well.
yum install php-soap
Restart the web server to take effect the changes.
In CentOS 7.x:
systemctl restart httpd
In CentOS 6.x:
service httpd restart
Now, Download the latest version from the phpVirtualBox official site.
wget http://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-4.3-3.zip
Extract the zip file using the following command:
unzip phpvirtualbox-4.3-3.zip
Move the extracted folder to your apache root folder.
mv phpvirtualbox-4.3-3 /var/www/html/phpvirtualbox

Configure phpVirtualBox

Edit phpVirtualBox config.php file:
cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php
vi /var/www/html/phpvirtualbox/config.php
Change the username/password for system user that runs VirtualBox. In our case, the username/password is sk_vuser/centos.
[...]
var $username = 'sk_vuser';
var $password = 'centos';
[...]
Save and close the file.
Create a file called /etc/default/virtualbox:
vi /etc/default/virtualbox
Append the following line:
VBOXWEB_USER=sk_vuser
Now, start vboxweb-service, and make it to start automatically on every reboot.
/etc/init.d/vboxweb-service start
chkconfig vboxweb-service on
I don’t want to messing around with iptables and SElinux. So, I simply disabled them both.
In CentOS 7.x:
systemctl disable firewalld
systemctl stop firewalld
In CentOS 6.x:
service iptables stop
chkconfig iptables off
Disable SELinux:
vi /etc/sysconfig/selinux
Set SELINUX=disabled.
[...]
SELINUX=disabled
[...]
Reboot your system once to take effect all the changes.

Access phpVirtualBox Web console

Now, go to any client systems that has installed with GUI desktop environments, and try to access the URL http://ip-address-of-virtualbox-headless-server/phpvirtualbox from the web browser.
Now, try again the same URL mentioned above. The following screen should appear. Enter the username/password.
The default username/password is admin/admin.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_001
Now, you’ll be redirected to the phpVirtualBox main dashboard.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_002
From here, you can create, modify, delete, and manage virtual machines.

Creating sample Virtual Machine

Let us create a sample virtual machine to install Ubuntu 14.04.
Click on the New button on the top left corner. Enter the Virtual machine name.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_003
Set the Memory size for the virtual machine.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_004
Select “Create a virtual hard drive now” option.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_005
Select hard drive file type.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_006
Choose whether the new virtual hard drive file should grow as it is used (dynamically allocated) or if it should be created at its maximum size (fixed size).
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_007
Enter the size of the virtual hdd.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_008
That’s it. The virtual machine has been created. Start installing the OS, and use the virtual machine.
phpVirtualBox - VirtualBox Web Console - Mozilla Firefox_009
phpVirtualBox tool will definitely help the system administrators who have only headless CentOS server, and also the installation is not that difficult. So, You can easily run virtual machines as many as your hardware supports from your headless CentOS server.