Tuesday, July 7, 2015

LFS using Ubuntu 14.04


Host System Requirements: 

Note :Ubuntu is not compliant out of the box, copy-paste the script and run it:
you might need to install some packages which are not present in ubuntu 14.04

 
bhargav@Inspiron:~$sudo apt-get install texinfo gawk make sed php gcc g++
 
Use scripts from documentation to check for packages and libraries
on your host system : sudo blkid -o list
bhargav@Inspiron:~$ sudo ./version-check.sh 
 
script code version-check.sh : Refer documentation for scrip code.
 
 
 
Note : you might need to install few packages showed after running the script :
 
bhargav@Inspiron:~$ sudo ./library-check.sh
 
script code library-check.sh : Refer documentation for script code.


  • Install gmp mpfr mpc
  • Installation is done manually by going onto site for each package and then 
    download and install it asshown in documentation of each package. 
 
You might get problem while installing mpfr hence just run this command:
 
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
 


Making a partition on disk for lfs using parted application :
 
Note : If you are not sure how PARTED work then refer to below 
link before going forward:

http://www.thegeekstuff.com/2011/09/parted-command-examples/
 
bhargav-Inspiron:/$ sudo parted
(parted) print free
 
Now look for space which is free to use and remember the start and end 
size to make partition:
 
Note : Please re-check or make sure before running any command. 
Any mistake might lead to losing your data onto disk or HD.

(parted) mkpart
Partition name?  []? lfs                                                 
File system type?  [ext2]? ext4                                           
Start? 238GB                                                              
End? 248GB                                                                
(parted) print
Model: ATA WDC WD5000LPVX-7 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system     Name                          Flags
 1      1049kB  525MB   524MB   fat32           EFI system partition          boot
 2      525MB   567MB   41.9MB  fat32           Basic data partition          hidden
 3      567MB   701MB   134MB                   Microsoft reserved partition  msftres
 4      701MB   1488MB  786MB   ntfs            Basic data partition          hidden, diag
 5      1488MB  70.1GB  68.6GB  ntfs            Basic data partition          msftdata
 6      70.1GB  238GB   168GB   ntfs            Basic data partition          msftdata
11      238GB   248GB   10.5GB                  lfs
 7      248GB   459GB   211GB   ntfs            Basic data partition          msftdata
 9      459GB   463GB   4200MB  linux-swap(v1)
10      463GB   491GB   27.3GB  ext4
 8      491GB   500GB   9412MB  ntfs            Microsoft recovery partition  hidden, diag
 
 
Format ext2 partition to ext4 partition :
 
 
bhargav@Inspiron:~$sudo blkid -o list             //this will show partition blkid 
bhargav@Inspiron:~$ sudo mkfs.ext4 /dev/sda11
 
We will make a variable link: (OPTIONAL you can use /mnt/lfs in $LFS or viceversa)
bhargav@Inspiron:~$ export LFS=/mnt/lfs
 
Make directory at /mnt/ name lfs:
 
bhargav@Inspiron:~$ sudo mkdir -pv /mnt/lfs
 
Mounting the partition on the location of lfs directory: 
 
bhargav@Inspiron:~$ sudo mount -v -t ext4 /dev/sda11 /mnt/lfs
/dev/sda11 on /mnt/lfs type ext4 (rw)
 
Make directory inside /mnt/lfs named "sources" : 
 
bhargav@Inspiron:~$ sudo mkdir -v $LFS/sources
mkdir: created directory ‘/mnt/lfs/sources’
 
Give permission to /mnt/lfs/sources : 
 
bhargav@Inspiron:~$ sudo chmod -v a+wt $LFS/sources
mode of ‘/mnt/lfs/sources’ changed from 0755 (rwxr-xr-x) to 1777 (rwxrwxrwt)
 
Download all the packages from site :
 
It includes total 77 files including patches 
 
 ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/lfs-packages-7.7-systemd.tar 
 
 
bhargav@Inspiron:/$ groupadd lfs 
bhargav@Inspiron:/$ sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
bhargav@Inspiron:/$ sudo adduser lfs sudo
bhargav@Inspiron:/$ sudo passwd lfs
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
 
lfs@Inspiron:/mnt/lfs$ sudo mkdir -v $LFS/tools
mkdir: created directory '/mnt/lfs/tools'
lfs@bhargav-Inspiron-3443:/mnt/lfs$ sudo ln -sv $LFS/tools /
'/tools' -> '/mnt/lfs/tools'

lfs@Inspiron:/mnt/lfs$
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/tools
changed ownership of ‘/mnt/lfs/tools’ from root to lfs
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/sources
changed ownership of ‘/mnt/lfs/sources’ from root to lfs
bhargav@Inspiron:/$ 
bhargav@Inspiron:/$ su - lfs
Password: 
  
Setting Up the Environment :
 
 lfs@Inspiron:~$ ~/.bash_profile << "EOF"
> exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
> EOF
-su: /home/lfs/.bash_profile: No such file or directory
lfs@Inspiron:~$ cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF

lfs@Inspiron:~$ cat > ~/.bashrc << "EOF"
> set +h
> umask 022
> LFS=/mnt/lfs
> LC_ALL=POSIX
> LFS_TGT=$(uname -m)-lfs-linux-gnu
> PATH=/tools/bin:/bin:/usr/bin
> export LFS LC_ALL LFS_TGT PATH
> EOF
lfs@Inspiron:~$ source ~/.bash_profile
 
 
IMP change it back to dash to run in normal enviroment
 
To change symblic link of sh to bash
sudo ln -sf bash /bin/sh 

Change it to dash when it is done
sudo ln -sf dash /bin/sh
 
 
 
Build Binutils package :
 
cd $LFS/sources
tar xf binutils-2.22.tar.bz2
cd binutils-2.22

mkdir -v ../binutils-build
cd ../binutils-build

../binutils-2.22/configure \
    --target=$LFS_TGT --prefix=/tools \
    --disable-nls --disable-werror

make

case $(uname -m) in
  x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac

make install

cd $LFS/sources
rm -rf binutils-build binutils-2.22 


Buils GCC package:
 
cd $LFS/sources
tar xf gcc-4.6.2.tar.bz2
cd gcc-4.6.2

tar -jxf ../mpfr-3.1.0.tar.bz2
mv -v mpfr-3.1.0 mpfr
tar -Jxf ../gmp-5.0.4.tar.xz
mv -v gmp-5.0.4 gmp
tar -zxf ../mpc-0.9.tar.gz
mv -v mpc-0.9 mpc 
 
The following command ill change the location of GCC's default dynamic linker to use the one installed in 


for file in \
$(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
cp -uv $file{,.orig}
sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
-e 's@/usr@/tools@g' $file.orig > $file
echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
touch $file.orig
done
 then making a gcc-build directory:
 
mkdir -v ../gcc-build
cd ../gcc-build
 
Installing gcc by running this command :
 
../gcc-4.9.2/configure \
--target=$LFS_TGT \
--prefix=/tools \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--with-local-prefix=/tools \
--with-native-system-header-dir=/tools/include \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-decimal-float \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libitm \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-libcilkrts \
--disable-libstdc++-v3 \
--enable-languages=c,c++
 
 
make
make install

cd $LFS/sources
rm -rf gcc-build gcc-4.9.2 
Installation of Linux API Headers:

cd $LFS/sources
tar -xf linux-3.19.tar.xz 
cd linux-3.19
make mrproper
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
cd $LFS/sources/
sudo rm -rf linux-3.19 
Installation of Glibc-2.21 :
tar xf glibc-2.21.tar.xz 
cd glibc-2.21
sudo mkdir -v ../glibc-build
cd ../glibc-build/

../glibc-2.21/configure                             \
      --prefix=/tools                               \
      --host=$LFS_TGT                               \
      --build=$(../glibc-2.21/scripts/config.guess) \
      --disable-profile                             \
      --enable-kernel=2.6.32                        \
      --with-headers=/tools/include                 \
      libc_cv_forced_unwind=yes                     \
      libc_cv_ctors_header=yes                      \
      libc_cv_c_cleanup=yes

 
 
make
make install


At this point, it is imperative to stop and ensure that the 
basic functions (compiling and linking) of the new
toolchain are working as expected. To perform a sanity
check, run the following commands: 
 
echo 'main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools'
 
If everything is working correctly, there should be no
errors, and the output of the last command will be of the form:
 
[Requesting program interpreter: /tools/lib/ld-linux.so.2] 
 
 
rm -v dummy.c a.out   
 
 
Binutils-2.22 - Pass 2 
 
tar xf binutils-2.25.tar.bz2
cd binutils-2.25 
 
mkdir -v ../binutils-build
cd ../binutils-build 
 
CC=$LFS_TGT-gcc                \
AR=$LFS_TGT-ar                 \
RANLIB=$LFS_TGT-ranlib         \
../binutils-2.25/configure     \
    --prefix=/tools            \
    --disable-nls              \
    --disable-werror           \
    --with-lib-path=/tools/lib \
    --with-sysroot 

make
make install

Now prepare the linker for the Re-adjusting phase in the next chapter: 
 
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
 

5.10.1. Installation of GCC
 
tar xf gcc-4.9.2.tar.bz2
cd gcc-4.9.2 

 cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
  `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
 
 
Once again, change the location of GCC's default dynamic 
linker to use the one installed in /tools.
 
for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
  cp -uv $file{,.orig}
  sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
      -e 's@/usr@/tools@g' $file.orig > $file
  echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
  touch $file.orig
done 
 
As in the first build of GCC it requires the GMP, MPFR and MPC packages. Unpack the tarballs and move them into the required directory names:

tar -xf ../mpfr-3.1.2.tar.xz
mv -v mpfr-3.1.2 mpfr
tar -xf ../gmp-6.0.0a.tar.xz
mv -v gmp-6.0.0 gmp
tar -xf ../mpc-1.0.2.tar.gz
mv -v mpc-1.0.2 mpc
 
 
 
Before starting to build GCC, remember to unset any environment variables that override the default optimization flags.
Now prepare GCC for compilation:


CC=$LFS_TGT-gcc                                    \
CXX=$LFS_TGT-g++                                   \
AR=$LFS_TGT-ar                                     \
RANLIB=$LFS_TGT-ranlib                             \
../gcc-4.9.2/configure                             \
    --prefix=/tools                                \
    --with-local-prefix=/tools                     \
    --with-native-system-header-dir=/tools/include \
    --enable-languages=c,c++                       \
    --disable-libstdcxx-pch                        \
    --disable-multilib                             \
    --disable-bootstrap                            \
    --disable-libgomp
 
 
Compile the package:
 
make
 
Install the package: 
 
make install
 
As a finishing touch, create a symlink. Many programs and
scripts run cc instead of gcc,which is used to keep programs generic and therefore usable
on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system
administrator free to decide which C compiler to install:
 
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools' 
 
If everything is working correctly, there should be no errors, 
and the output of the last command will be of the form: 
 
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
 
 
 
Once all is well, clean up the test files:
 
rm -v dummy.c a.out

 

Once all is well, clean up the test files:
 
HERE  YOU HAVE COMPLETED THE TOUGH PART OF LFS.

  
 

5.11. Tcl8.6.3 Installation :

tar xf tcl8.6.3-src.tar.gz
cd tcl8.6.3/unix
 
Prepare Tcl for compilation:
 
  cd tcl8.6.3/unix        
./configure --prefix=/tools 
 
Build the package:
              
make


Install the package: 

make install
 
 
Make the installed library writable so debugging symbols can be removed later:
 
chmod -v u+w /tools/lib/libtcl8.6.so 
 
 
Install Tcl's headers. The next package, Expect, requires them to build. 
  

make install-private-headers 
 
 
Now make a necessary symbolic link:
 
ln -sv tclsh8.6 /tools/bin/tclsh 




5.12. Expect-5.45 Installation :

First, force Expect's configure script to use /bin/stty instead of a /usr/local/bin/stty it may find on the host system. This will ensure that our test suite tools remain sane for the final builds of our toolchain:

tar xf expect5.45.tar.gz
cd expect5.45
cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure
 
 
Now prepare Expect for compilation:
 
./configure --prefix=/tools       \
            --with-tcl=/tools/lib \
            --with-tclinclude=/tools/include 
 
Build the package:
 
make
 
 
 

5.13. DejaGNU package Installation :


tar xf dejagnu-1.5.2.tar.gz

cd dejagnu-1.5.2/

./configure --prefix=/tools
 
make install 
 
 

5.14. Check-0.9.14 package Installation :

 Prepare Check for complilation:
 
PKG_CONFIG= ./configure --prefix=/tools
 
Build the package:
 
make
 
Install the package:
 
make install  
 
 

5.15. Ncurses-5.9 package Installation :


tar xf ncurses-5.9.tar.gz 
cd ncurses-5.9

Prepare Ncurses for complilation:

./configure --prefix=/tools \
            --with-shared   \
            --without-debug \
            --without-ada   \
            --enable-widec  \
            --enable-overwrite
 
Build the package :
 
make
 
Install the package:
 
make install  
  

5.16. Bash-4.3.30 package Installation :

tar xf bash-4.3.30.tar.gz 
cd bash-4.3.30
Prepare Bash for compilation:

./configure --prefix=/tools --without-bash-malloc


Build the package:

make

Install the package: 

make install

Make a link for the programs that use sh for a shell:

ln -sv bash /tools/bin/sh



5.17. Bzip2-1.0.6 package Installation :

tar xf bzip2-1.0.6.tar.gz 
cd bzip2-1.0.6

The Bzip2 package does not contain a configure script. Compile and test it with:

make

Install the package:

make PREFIX=/tools install
 
 
 

5.18. Coreutils-8.23 package Installation :

tar xf coreutils-8.23.tar.gz 
cd coreutils-8.23
Prepare Coreutils for compilation:

./configure --prefix=/tools --enable-install-program=hostname


Build the package:

make

Install the package: 

make install



5.19. Diffutils-3.3 package Installation :

tar xf diffutils-3.3.tar.gz 
cd diffutils-3.3
Prepare Diffutils for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.20. File-5.22 package Installation :

tar xf file-5.22.tar.gz 
cd file-5.22
Prepare File for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.21. Findutils-4.4.2 package Installation :

tar xf findutils-4.4.2.tar.gz 
cd findutils-4.4.2
Prepare Findutils for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.22. Gawk-4.1.1 package Installation :

tar xf Gawk-4.1.1.tar.gz 
cd gawk-1.1.2
Prepare Gawk for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.23. Gettext-0.19.4 package Installation :

tar xf gettext-0.19.4.tar.gz 
cd gettext-0.19.4
Prepare Gettext for compilation:

cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared


Compile the package:

make -C gnulib-lib
make -C intl pluralx.c
make -C src msgfmt
make -C src msgmerge
make -C src xgettext


Install the msgfmt, msgmerge and xgettext programs:

cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin
 
 

5.24. Grep-2.21 package Installation :

tar xf grep-2.21.tar.gz 
cd grep-2.21
Prepare Grep for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.25. Gzip-1.6 package Installation :

tar xf gzip-1.6.tar.gz 
cd gzip-1.6
Prepare Gzip for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.26. M4-1.4.17 package Installation :

tar xf m4-1.4.17.tar.gz 
cd m4-1.4.17
Prepare M4 for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.27. Make-4.1 package Installation :

tar xf make-4.1.tar.gz 
cd make-4.1
Prepare Make for compilation:

./configure --prefix=/tools --without-guile



Build the package:

make

Install the package: 

make install


5.28. Patch-2.7.4 package Installation :

tar xf patch-2.7.4.tar.gz 
cd patch-2.7.4
Prepare Make for compilation:

./configure --prefix=/tools



Build the package:

make

Install the package: 

make install


5.29. Perl-5.20.2 package Installation :

tar xf perl-5.20.2.tar.gz 
cd perl-5.20.2
Prepare perl for compilation:

sh Configure -des -Dprefix=/tools -Dlibs=-lm



Build the package:

make

Only a few of the utilities and libraries need to be installed at this time:



 








 
 

 
   
 
 
 
 


 
 
               
 







 cp -v perl cpan/podlators/pod2man /tools/bin
 mkdir -pv /tools/lib/perl5/5.20.2
 cp -Rv lib/* /tools/lib/perl5/5.20.2
 
 

5.30. Sed-4.2.2 package Installation :

tar xf sed-4.2.2.tar.gz 
cd sed-4.2.2
Prepare Sed for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.31. Tar-1.28 package Installation :

tar xf tar-1.28.tar.xz
cd tar-1.28
Prepare Tar for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.32. Texinfo-5.2 package Installation :

tar xf texinfo-5.2.tar.xz
cd texinfo-5.2
Prepare Texinfo for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install


5.33. Util-linux-2.26 package Installation :

tar xf util-linux-2.26.tar.xz
cdutil-linux-2.26
Prepare Util-linux for compilation:

./configure --prefix=/tools                \
            --without-python               \
            --disable-makeinstall-chown    \
            --without-systemdsystemunitdir \
            PKG_CONFIG=""


Build the package:

make

Install the package: 

make install


5.34. Xz-5.2.0 package Installation :

tar xf xz-5.2.0.tar.xz
cd xz-5.2.0
Prepare Xz for compilation:

./configure --prefix=/tools


Build the package:

make

Install the package: 

make install









 
 
 

Monday, July 6, 2015

Enabling Two Factor Authentication on SSH (Ubuntu)

Step One - Install Dependencies

sudo apt-get install libpam-google-authenticator

Step Two - Edit the Configuration Files

To use the module you have to edit two configuration files.

nano /etc/pam.d/sshd

Add the following line on top of the file:

auth required pam_google_authenticator.so

One more file to edit:

nano /etc/ssh/sshd_config

Find and change the following line:

ChallengeResponseAuthentication yes

Step Three - Open and Configure google-authenticator :

You can activate the google-authenticator for the root user or any other user. Switch to the user who should use the two-factor authentication and type in:
google-authenticator

You will be prompted to answer a few questions; answer the first two questions with yes (y):

Do you want authentication tokens to be time-based (y/n) y
And then copy the private or secret key. Use that secret key in the google authenticator app.
Then try to login using ssh you will be prompted for key. It means that your authentication is working successfully. 

Monday, June 1, 2015

Anuko Time Tracker Implementation

Install apache webserver :

$ sudo apt-get install apache2

Install php5:
$ sudo apt-get install php5-gd

Install mysql server:

$ sudo apt-get install mysql-server

Create a virtual host file 'localtimetrack.com' :

 $ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/localtimetrack.com.conf

Edit localtimetrack.com.conf file root directory :

sudo nano /etc/apache2/sites-available/localtimetrack.com.conf

In that edit line :

 ServerName localtimetrack.com
 DocumentRoot /var/www/timetracker






Save changes by :

ctrl+x then Y+enter

Enable new virtual host file 'localtimetrack.com.conf' :

sudo a2ensite localtimetrack.com.conf

sudo service apache2 restart

Update Hosts file from /etc :

127.0.1.1       bhrgv-laptop-3443   localtimetrack.com


Now start implementing Anuko Time Tracker.

Download source code .zip from site :

https://www.anuko.com/download/time_tracker/time_tracker.zip


Unzip source code file into var/www directory:

$ sudo cp Downloads/time_tracker.zip /var/www

$ sudo unzip /var/www/time_tracker.zip


Allow Writing to WEB-INF/templates_c/ :

$ cd timetracker/WEB-INF
$ chmod 777 templates_c/

Open mysql server :

$ mysql -h localhost -u root -p


Create Database and grant privilages :

mysql> CREATE DATABASE timetracker CHARACTER SET = 'utf8';
mysql> GRANT ALL PRIVILEGES ON timetracker.* TO 'ttuser'@'localhost' IDENTIFIED BY 'root123';
mysql>exit

Create Config file :

$ cd WEB-INF
$ cp config.php.dist config.php


Change values of config.php :

$ sudo nano config.php

In that change line :

define('DSN', 'mysql://ttuser:root123@localhost/timetracker');

Also add parameter 'timetracker' to line :

define('APP_NAME', 'timetracker'); 


Exit by pressing ctrl+x then Y+enter

 Create Time Traker DB structure with dbinstall.php :

Type http://localtimetrack.com/dbinstall.php in browser

Then select first option 'Create database structure'

Then revoke rights of dbinstall.php :

chmod 000 dbinstall.php

Login onto home page now :

 http://localtimetrack.com

Enter user name : admin and password : secret, then Create a Team

Logout and then login with admin name of team and the password


Go on Project then create a project 

Add details with time date and note, save it.





 


Tuesday, March 3, 2015

Install apache2 server with mod_ssl and dedicated subdomain

First install apache2 webserver firing following command on your terminal:
>sudo apt-get install apache2 
 
 
Step 1 : Create a  ".conf " file in sites-available. 

> cd /etc/apache2/sites-available
> nano test.mydomaine.com.conf
 
Step 2 :

Insert following content in test.mydomaine.com :
 
 <VirtualHost *:80>
        ServerAdmin mymail@gmail.com        //your server email id
        ServerName  test.mydomaine.com      //your domain name
        ServerAlias www.test.mydomaine.com  // alias if you want its optional
        DocumentRoot /var/www/testfolder/   //your root folder if default no change needed
<Directory "/var/www/testfolder">
        AuthType Basic
        AuthName "test"
        AuthUserFile /var/www/testfolder/passwords
        Require valid-user test
</Directory>
</VirtualHost> 
 
Step 3 : Enabling the domain
  
 
      > a2ensite test.mydomaine.com 
> sudo service apache2 reload  

Step 4 : Enable mod_ssl or https feature for your domain name
 
>sudo a2enmod ssl           // it will enable mod_ssl feature  
>sudo a2ensite default-ssl  //it will configure apache2 for https 
>sudo service apache2 restart 

Note : If you want to add a certificate for your website you can change the path in /etc/apache2/sites-available/default-ssl.conf

 
 
Step 5 : Configure DNS resolution for the new hostname 
 
  • If you are just playing with this locally and do not want to create a "real" DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. 
  • If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1.
  •  If the browser is on a different machine on your local network, you'll need to determine the server's IP address and then on the browser machine, edit /etc/hosts to add the mapping.
  • For Windows, the file is called C:\windows\system32\drivers\etc\hosts
  •  A sample entry would be (for the browser running on the same machine as the server):
    127.0.0.1 test.mydomain.com
If the server is at, say 192.168.0.5, the entry would be:
192.168.0.5 test.mydomain.com
  • If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server's real IP instead of 127.0.0.1. Do this on the system where you are running the browser.