Installing CentOS 6.9 Server – Minimal Build

Installing Centos 6.9

CentOS (Community Enterprise Operating System) is a free Linux operating system that has a 100% binary compatibility with RHEL (Red Hat Enterprise Linux). Because of this compatibility, many individuals and organisations choose CentOS as their choice of Linux. In the example that follows, we will show you how to install a minimal build server without a graphical user desktop. To install CentOS 6.9 (Minimal Build) simply follow the instructional guide below:

To download your iso image of CentOS 6.9, follow the Link: CentOS 6.9 Download

In the example that follows I have used the 64 bit version FileName: CentOS-6.9-x86_64-minimal.iso.
These “iso” images can be found in either a 32 bit or 64 bit option. (32 bit = i386 and 64 bit = x86_64)

Once you have downloaded your CentOS 6.9 iso for your chosen architecture (32 bit or 64 bit), you will need to burn this to a blank CD/DVD. For software that can do this, search for “dvd iso burning software” in the search box located at the top of this page. Your system may already have CD/DVD burning software installed such as “Brasero, K3B, Nero, CDBurnerXP or Roxio”. Once you have burned your “iso” image of CentOS 6.9 to your DVD, you will need to leave the DVD in the DVD drive and reboot your system. As your computer reboots, you will need to press the appropriate key to access your system’s BIOS settings. On many systems this key will be “F8”, “F11” or “F12”. Most systems will display the a message indicating which key needs to be pressed. Once you have access to your BIOS settings, you will need to modify the boot sequence order of your system to boot from CD/DVD first. Once you have made this change, you can reboot your system and follow the instructions below. If you are using a Virtualised environment such as VirtualBox or VMWare, simply copy your iso image to the relevant directory/data-store.

Welcome to CentOS 6.9 Installation Menu

To start your installation of CentOS 6.9, simply highlight the “Install or upgrade an existing system” and press enter. Your installation will now start.

Testing Installation Media

It’s always recommended that you should test your installation media before carrying out an installation. If you do not want to test your installation media, then select “skip” to continue.

CentOS 6 Start Screen

At this screen click on the “Next” button to start your installation.

Language Selection

At this screen you will need to select the language that is to be used throughout the installation. In this example “English” has been chosen.

Select Keyboard

Select the appropriate keyboard for your system. In this example I have chosen a “United Kingdom” keyboard.

Selecting Storage Devices

At this screen you have two options available. “Basic Storage Devices” and “Specialized Storage Devices In the example I have gone with the “Basic Storage Device” option.

Storage Device Warning

At this screen you must confirm you are happy to use the identified disk for your installation of CentOS 6.9.

Provide a Hostname

At this screen you must provide a unique name hostname to be used by your new system. In the example I have chosen “centos69a. It is also from this screen that you have the option to configure your network settings. If you want to use “DHCP to automatically allocate your system an IP address, then simply click on “Next”. If you wish to manually assign an IP address to your new system, then click on the “Configure Network option.

Network Connections

If you have chosen the option to configure your network as per the previous step. You will be presented with a list of attached interfaces to your system. At this screen, highlight the interface you want to work with and then choose Edit

Editing Interface

It is from this screen that we can manually assign an IP address to the interface. In the example, I am going to be configuring the interface under the heading “IPv4 Settings“. Under the “Method pull down menu, amend the selection to read “Manual“. This is the option for a “static” IP address. Now click on the Address, Netmask and Gateway boxes to enter your network details. In the example, I have added a static IP address of “192.168.0.56“, a Netmask of “255.255.255.0, and a Gateway address of “192.168.0.1.

You are also required to provide the IP address of a DNS server to be used. If this information has not been provided to you and you require external internet access, you may use a free address of “8.8.8.8“.

If you are configuring a system that will be part of a wider network, you may add a list of Domain names into the “search Domains” box.

I have also selected both of the options: “Connect automatically and Available to all users.

Once you are happy with your network configuration settings, click on “Apply“.

Configure your Time Zone

At this screen you must choose your geographic location from the pull down menu or from the map. In the example “Europe/London” has been chosen. It is this setting that will set your time zone that will be used by your system.

Root Password

At this screen you must provide a “root” password to be used on your system. If you supply a weak password, then you will be asked to confirm that you want to use the weak password. Once you have provided your password, click on “Next” to continue with the installation process.

Installation Type

 

At this screen several options are available to select. In the example, I have chosen the option “Use All Space“. You also have the option to “Encrypt system“.

Write Storage Configuration

From the pop menu, you must choose “Write changes to disk” to allow the installation to continue.

Installation Continues

At this screen, no further interaction is required. Progress of the installation is displayed by a progress bar.

Congratulations

Congratulations, your CentOS installation is now complete. Before you can use your system, a re-boot is required. Click on the “Reboot” icon in the lower right hand corner.

Login Screen

At the login screen, you must use the “root” account to login with and use the password you provided earlier.

iConnect Predictive Dialer Installation

Once you have 64-bit CentOS 6.10 or 7.X minimal ISO up and running, log into your server as root and issue the following commands to kick off the Incredible PBX install.
yum -y update
yum -y install net-tools nano wget tar
wget http://incrediblepbx.com/incrediblepbx-13-13-LEAN.tar.gz
tar zxvf incrediblepbx-13-13-LEAN.tar.gz
rm -f incrediblepbx-13-13-LEAN.tar.gz
./create-swapfile-DO
# kick off Phase I install
./IncrediblePBX-13-13.sh
# after reboot, kick off Phase II install
./IncrediblePBX-13-13.sh
# add Full Enchilada apps, if desired
./Enchilada-upgrade.sh
# add HylaFax/AvantFax, if desired
./incrediblefax13.sh
# set passwords
./update-passwords
# set desired timezone
./timezone-setup

Come back in 15 minutes.

yum -y install perl-CPAN perl-YAML


perl -MCPAN -e shell
install CPAN::Meta::Requirements
install CPAN
reload cpan
install YAML
install MD5
install Digest::MD5
install Digest::SHA1
install readline
install Bundle::CPAN
reload cpan
install DBI
force install DBD::mysql
install Net::Telnet
install Time::HiRes
install Net::Server
install Switch
install Mail::Sendmail
install Unicode::Map
install Jcode
force install Spreadsheet::WriteExcel
install OLE::Storage_Lite
install Proc::ProcessTable
install IO::Scalar
force install Spreadsheet::ParseExcel
install Curses
install Getopt::Long
install Net::Domain
install Term::ReadKey
install Term::ANSIColor
force install Spreadsheet::XLSX
install Spreadsheet::Read
install LWP::UserAgent
install HTML::Entities
install HTML::Strip
install HTML::FormatText
install HTML::TreeBuilder
install Time::Local
install MIME::Decoder
install Mail::POP3Client
install Mail::IMAPClient
install Mail::Message
install IO::Socket::SSL
install MIME::Base64
install MIME::QuotedPrint
install Crypt::Eksblowfish::Bcrypt
install Text::CSV

cpan -i String::CRC Tk::TableMatrix Net::Address::IP::Local Term::ReadLine::Gnu Spreadsheet::Read \
Net::Address::IPv4::Local RPM::Specfile Spreadsheet::XLSX Spreadsheet::ReadSXC

perl -MCPAN -e shell
install CPAN::Meta::Requirements CPAN
reload cpan
install YAML MD5 Digest::MD5 Digest::SHA1 readline Bundle::CPAN
reload cpan
force install DBD::mysql
install Net::Telnet DBI Time::HiRes Net::Server Switch Mail::Sendmail Unicode::Map Jcode Spreadsheet::WriteExcel OLE::Storage_Lite Proc::ProcessTable IO::Scalar Spreadsheet::ParseExcel Curses Getopt::Long Net::Domain Term::ReadKey Term::ANSIColor Spreadsheet::XLSX Spreadsheet::Read LWP::UserAgent HTML::Entities HTML::Strip HTML::FormatText HTML::TreeBuilder Time::Local MIME::Decoder Mail::POP3Client Mail::POP3Client Mail::IMAPClient Mail::Message IO::Socket::SSL MIME::Base64 MIME::QuotedPrint Crypt::Eksblowfish::Bcrypt Mail::Message IO::Socket::SSL MIME::Base64 MIME::QuotedPrint Crypt::Eksblowfish::Bcrypt Text::CSV

cd /usr/src
wget http://download.vicidial.com/required-apps/asterisk-perl-0.08.tar.gz
tar -zxf asterisk-perl-0.08.tar.gz
cd asterisk-perl-0.08
perl Makefile.PL
make all
make install

cd /usr/src
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -zxf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
make install

cd /usr/src
wget http://downloads.sourceforge.net/project/ploticus/ploticus/2.42/ploticus242_src.tar.gz
tar -zxf ploticus242_src.tar.gz
cd ploticus242/src/
make clean
make
make install
mkdir -p /var/www/html/vicidial/ploticus/
cp pl /var/www/html/vicidial/ploticus/

vim /etc/php.ini

error_reporting = E_ALL & ~E_NOTICE
short_open_tag = On
max_execution_time = 330
max_input_time = 360
post_max_size = 48M
upload_max_filesize = 42M
default_socket_timeout = 360

vim /etc/httpd/conf/httpd.conf

To disable logging, change:

CustomLog logs/access_log common
to this:
CustomLog /dev/null common

To enable web browsing of Recordings on Asterisk server, add the below line at last line of httpd.conf

Alias /RECORDINGS/ "/var/spool/asterisk/monitorDONE/"

<Directory “/var/spool/asterisk/monitorDONE”>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

Forcetype application/forcedownload
Restart the Apache web server to apply the changes:
service httpd restart
chkconfig httpd on

Installing audio files, Download the audio files
cd /usr/src
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-core-sounds-en-ulaw-current.tar.gz
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-core-sounds-en-wav-current.tar.gz
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-core-sounds-en-gsm-current.tar.gz
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-ulaw-current.tar.gz
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-wav-current.tar.gz
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-gsm-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-moh-opsound-gsm-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-moh-opsound-ulaw-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/sounds/asterisk-moh-opsound-wav-current.tar.gz

Place the audio files in their proper places:

cd /var/lib/asterisk/sounds
tar -zxf /usr/src/asterisk-core-sounds-en-gsm-current.tar.gz
tar -zxf /usr/src/asterisk-core-sounds-en-ulaw-current.tar.gz
tar -zxf /usr/src/asterisk-core-sounds-en-wav-current.tar.gz
tar -zxf /usr/src/asterisk-extra-sounds-en-gsm-current.tar.gz
tar -zxf /usr/src/asterisk-extra-sounds-en-ulaw-current.tar.gz
tar -zxf /usr/src/asterisk-extra-sounds-en-wav-current.tar.gz
mkdir /var/lib/asterisk/mohmp3
mkdir /var/lib/asterisk/quiet-mp3
ln -s /var/lib/asterisk/mohmp3 /var/lib/asterisk/default
cd /var/lib/asterisk/mohmp3
tar -zxf /usr/src/asterisk-moh-opsound-gsm-current.tar.gz
tar -zxf /usr/src/asterisk-moh-opsound-ulaw-current.tar.gz
tar -zxf /usr/src/asterisk-moh-opsound-wav-current.tar.gz
rm -f CHANGES*
rm -f LICENSE*
rm -f CREDITS*
cd /var/lib/asterisk/moh
rm -f CHANGES*
rm -f LICENSE*
rm -f CREDITS*
cd /var/lib/asterisk/sounds
rm -f CHANGES*
rm -f LICENSE*
rm -f CREDITS*
cd /var/lib/asterisk/quiet-mp3
sox ../mohmp3/macroform-cold_day.wav macroform-cold_day.wav vol 0.25
sox ../mohmp3/macroform-cold_day.gsm macroform-cold_day.gsm vol 0.25
sox -t ul -r 8000 -c 1 ../mohmp3/macroform-cold_day.ulaw -t ul macroform-cold_day.ulaw vol 0.25
sox ../mohmp3/macroform-robot_dity.wav macroform-robot_dity.wav vol 0.25
sox ../mohmp3/macroform-robot_dity.gsm macroform-robot_dity.gsm vol 0.25
sox -t ul -r 8000 -c 1 ../mohmp3/macroform-robot_dity.ulaw -t ul macroform-robot_dity.ulaw vol 0.25
sox ../mohmp3/macroform-the_simplicity.wav macroform-the_simplicity.wav vol 0.25
sox ../mohmp3/macroform-the_simplicity.gsm macroform-the_simplicity.gsm vol 0.25
sox -t ul -r 8000 -c 1 ../mohmp3/macroform-the_simplicity.ulaw -t ul macroform-the_simplicity.ulaw vol 0.25
sox ../mohmp3/reno_project-system.wav reno_project-system.wav vol 0.25
sox ../mohmp3/reno_project-system.gsm reno_project-system.gsm vol 0.25
sox -t ul -r 8000 -c 1 ../mohmp3/reno_project-system.ulaw -t ul reno_project-system.ulaw vol 0.25
sox ../mohmp3/manolo_camp-morning_coffee.wav manolo_camp-morning_coffee.wav vol 0.25
sox ../mohmp3/manolo_camp-morning_coffee.gsm manolo_camp-morning_coffee.gsm vol 0.25
sox -t ul -r 8000 -c 1 ../mohmp3/manolo_camp-morning_coffee.ulaw -t ul manolo_camp-morning_coffee.ulaw vol 0.25


mysql -u root -ppassw0rd
CREATE DATABASE asterisk DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'cron'@'localhost' IDENTIFIED BY '1234';
GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES on asterisk.* TO cron@'%' IDENTIFIED BY '1234';
GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES on asterisk.* TO cron@localhost IDENTIFIED BY '1234';
GRANT RELOAD ON *.* TO cron@'%';
GRANT RELOAD ON *.* TO cron@localhost;
flush privileges;
quit

mkdir /usr/src/astguiclient
cd /usr/src/astguiclient
svn checkout svn://svn.eflo.net/agc_2-X/trunk
cd trunk
perl install.pl

Import sample data, Login to mysql to run some commands:

mysql -u root -ppassw0rd
SET GLOBAL connect_timeout=60;
use asterisk;
\. /usr/src/astguiclient/trunk/extras/MySQL_AST_CREATE_tables.sql
\. /usr/src/astguiclient/trunk/extras/first_server_install.sql
\. /usr/src/astguiclient/trunk/extras/sip-iax_phones.sql
quit

/usr/share/astguiclient/ADMIN_area_code_populate.pl

vim /etc/rc.d/rc.local

# OPTIONAL enable ip_relay(for same-machine trunking and blind monitoring)
/usr/share/astguiclient/ip_relay/relay_control start 2>/dev/null 1>&2
# Disable console blanking and powersaving
/usr/bin/setterm -blank
/usr/bin/setterm -powersave off
/usr/bin/setterm -powerdown
### roll the Asterisk logs upon reboot
/usr/share/astguiclient/ADMIN_restart_roll_logs.pl
### clear the server-related records from the database
/usr/share/astguiclient/AST_reset_mysql_vars.pl
### load dahdi drivers
modprobe dahdi
/usr/sbin/dahdi_cfg -vvvvvvvvvvvvv
### sleep for 20 seconds before launching Asterisk
sleep 20

crontab -e

### recording mixing/compressing/ftping scripts
0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /usr/share/astguiclient/AST_CRON_audio_1_move_mix.pl
#0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /usr/share/astguiclient/AST_CRON_audio_1_move_mix.pl --MIX
#0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /usr/share/astguiclient/AST_CRON_audio_1_move_VDonly.pl
1,4,7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * /usr/share/astguiclient/AST_CRON_audio_2_compress.pl --MP3
#2,5,8,11,14,17,20,23,26,29,32,35,38,41,44,47,50,53,56,59 * * * * /usr/share/astguiclient/AST_CRON_audio_3_ftp.pl --MP3

### keepalive script for astguiclient processes
* * * * * /usr/share/astguiclient/ADMIN_keepalive_ALL.pl --cu3way
### kill Hangup script for Asterisk updaters
* * * * * /usr/share/astguiclient/AST_manager_kill_hung_congested.pl
### updater for voicemail
* * * * * /usr/share/astguiclient/AST_vm_update.pl
### updater for conference validator
* * * * * /usr/share/astguiclient/AST_conf_update.pl
### flush queue DB table every hour for entries older than 1 hour
11 * * * * /usr/share/astguiclient/AST_flush_DBqueue.pl -q
### fix the vicidial_agent_log once every hour and the full day run at night
33 * * * * /usr/share/astguiclient/AST_cleanup_agent_log.pl
50 0 * * * /usr/share/astguiclient/AST_cleanup_agent_log.pl --last-24hours
## uncomment below if using QueueMetrics
#*/5 * * * * /usr/share/astguiclient/AST_cleanup_agent_log.pl --only-qm-live-call-check
## uncomment below if using Vtiger
#1 1 * * * /usr/share/astguiclient/Vtiger_optimize_all_tables.pl --quiet
### updater for VICIDIAL hopper
* * * * * /usr/share/astguiclient/AST_VDhopper.pl -q
### adjust the GMT offset for the leads in the vicidial_list table
1 1,7 * * * /usr/share/astguiclient/ADMIN_adjust_GMTnow_on_leads.pl --debug
### reset several temporary-info tables in the database
2 1 * * * /usr/share/astguiclient/AST_reset_mysql_vars.pl
### optimize the database tables within the asterisk database
3 1 * * * /usr/share/astguiclient/AST_DB_optimize.pl
## adjust time on the server with ntp
30 * * * * /usr/sbin/ntpdate -u pool.ntp.org 2>/dev/null 1>&2
### VICIDIAL agent time log weekly and daily summary report generation
2 0 * * 0 /usr/share/astguiclient/AST_agent_week.pl
22 0 * * * /usr/share/astguiclient/AST_agent_day.pl

###VICIDIAL campaign export scripts (OPTIONAL)
#32 0 * * * /usr/share/astguiclient/AST_VDsales_export.pl
#42 0 * * * /usr/share/astguiclient/AST_sourceID_summary_export.pl
### remove old recordings more than 7 days old
#24 0 * * * /usr/bin/find /var/spool/asterisk/monitorDONE -maxdepth 2 -type f -mtime +7 -print | xargs rm -f
### roll logs monthly on high-volume dialing systems
#30 1 1 * * /usr/share/astguiclient/ADMIN_archive_log_tables.pl
### remove old vicidial logs and asterisk logs more than 2 days old
28 0 * * * /usr/bin/find /var/log/astguiclient -maxdepth 1 -type f -mtime +2 -print | xargs rm -f
29 0 * * * /usr/bin/find /var/log/asterisk -maxdepth 3 -type f -mtime +2 -print | xargs rm -f
30 0 * * * /usr/bin/find / -maxdepth 1 -name "screenlog.0*" -mtime +4 -print | xargs rm -f
### cleanup of the scheduled callback records
25 0 * * * /usr/share/astguiclient/AST_DB_dead_cb_purge.pl --purge-non-cb -q
### GMT adjust script - uncomment to enable
#45 0 * * * /usr/share/astguiclient/ADMIN_adjust_GMTnow_on_leads.pl --list-settings
### Dialer Inventory Report
1 7 * * * /usr/share/astguiclient/AST_dialer_inventory_snapshot.pl -q --override-24hours
### inbound email parser
* * * * * /usr/share/astguiclient/AST_inbound_email_parser.pl
* * * * * /bin/chmod 0777 -R /usr/share/astguiclient/
* * * * * /bin/chmod 0777 -R /var/www/html/icadmin
* * * * * /bin/chmod 0777 -R /var/www/html/vicidial
* * * * * /bin/chmod 0777 -R /usr/share/astguiclient/
* * * * * /bin/chmod 0777 -R /var/log/astguiclient/
@reboot /sbin/modprobe dahdi

0 8 * * * /usr/bin/mysqlcheck -u root -ppassw0rd --auto-repair -r -a -o --all-databases >/dev/null 2>&1
0 8 * * * /usr/bin/mysqlcheck -u root -ppassw0rd --auto-repair --optimize --all-databases >/dev/null 2>&1

/usr/share/astguiclient/ADMIN_update_server_ip.pl –old-server_ip=10.10.10.15

reboot

Changing SSH Port For Best Security on CentOS 6 or 7

First, we must edit the SSHD (SSH server daemon) configuration file. Use your favorite text editor.

#vim /etc/ssh/sshd_config

Add the following code to the bottom of the configuration file. To go to bottom of the file just press “shift+g”.

# SSH Port
Port 9752 # the port you want to change

Next, we’ll update the firewall. If you have disabled the firewall, skip this step. My example uses port 9752. For CentOS 6 users, run these commands:

#iptables -I INPUT -p tcp –dport 9752 –syn -j ACCEPT
#service iptables save
#semanage port -a -t ssh_port_t -p tcp 9752

CentOS 7 users, run these commands instead:

#firewall-cmd –add-port 9752/tcp –permanent
#firewall-cmd –add-port 9752/tcp

The configuration changes are now finished. Restart the SSH service (SSHD)…

#service sshd restart

–Done.

How To Set Up Apache Virtual Hosts on CentOS 6.X

Step One— Create a New Directory

  • The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.
  • This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory.

  sudo mkdir -p /var/www/slateindia.org/public_html

  • You will need to designate an actual DNS approved domain, or an IP address, to test that a virtual host is working. In this tutorial we will use example.com as a placeholder for a correct domain name.
  • However, should you want to use an unapproved domain name to test the process you will find information on how to make it work on your local computer in Step Six?

Step Two—Grant Permissions

  • We need to grant ownership of the directory to the user, instead of just keeping it on the root system.

sudo chown -R apache:apache /var/www/slateindia.org/public_html

             Now you are all done with permissions.

Step Three— Create the Page

  • We need to create a new file called index.html within our configurations directory.

      sudo vi /var/www/slateindia.org/public_html/index.html

    We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.

<html>
<head>
<title>www.demo.com</title>
</head>
<body>
<h1>Success: You Have Set Up a Virtual Host</h1>
</body>
</html>

 Save and Exit

Step Four—Turn on Virtual Hosts

  • The next step is to enter into the apache configuration file itself.

      sudo vi /etc/httpd/conf/httpd.conf

          Scroll down to the very bottom of the document to the section called Virtual Hosts.

NameVirtualHost *:80

Adding More Virtual Hosts

To create additional virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate new domain name each time. Then just copy and paste the new Virtual Host information into the Apache Config file, as shown below

<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/slateindia.org/public_html
ServerName www.slateindia.org
ServerAlias slateindia.org
ErrorLog /var/www/slateindia.org/error.log
CustomLog /var/www/slateindia.org/requests.log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@example.org
DocumentRoot /var/www/example.org/public_html
ServerName www.example.org
ServerAlias example.org
ErrorLog /var/www/example.org/error.log
CustomLog /var/www/example.orgrequests.log common
</VirtualHost>

The most important lines to focus on are the lines that say NameVirtualHost, Virtual Host, Document Root, and Server Name. Let’s take these one at a time.

  • Uncomment (remove the number sign) NameVirtualHost without making any changes. The star means that any IP address going through port 80 will be a virtual host. As your system probably only has one IP address this is not an issue—however, if you prefer, you can replace the star with your IP address.
  • You can leave the rest of the number marks in place until you reach the line <VirtualHost *:80> . Uncomment everything from there through <VirtualHost>.
  • Leave <VirtualHost *:80> as is—its details must match with those in the NameVirtual Host section. If you replaced the star with your IP address in that section, be sure to do the same here.
  • Document Root is key! For this section, write in the extension of the new directory created in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.
  • Server Name is another important piece of information, containing the virtual host’s domain name (eg. www.example.com). Make sure that you spell the domain out in full; we will put in any alternate possibilities in the next line.
  • ServerAlias is a new line in the config file that is not there by default. Adding it will allow you to list a few variants of the domain name, for example without the www in the front.

The rest of the lines in this section are not required to set up a virtual host. However, it is still helpful to know what they do.

  • Server admin asks for the webmaster’s email.
  • The Error Logs and Custom Logs keep track of any issues with the server. The error log covers issues that arise while maintaining the server, and the custom log tracks server requests. You can set up a custom location for these processes.
  • Make sure that <VirtualHost> is uncommented; then save and exit.

    Step Five—Restart Apache

    We’ve made a lot of the changes to the configuration. However, they will not take effect until Apache is restarted.

  • Then start up apache once again
sudo service httpd restart
 You may see the following error:
Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

The message is just a warning, and you will be able to access your virtual host without any further issues

Optional Step Six—Setting Up the Local Hosts

  • If you have pointed your domain name to your virtual private server’s IP address you can skip this step—you do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone. For this step, make sure you are on the computer itself, not your droplet.
  • To proceed with this step you need to know your computer’s administrative password, otherwise you will be required to use an actual domain name to test the virtual hosts.

If you are on a Mac or Linux, access the root user (su) on the computer and open up your hosts file:

vim /etc/hosts 
  • If you are on a Windows Computer, you can find the directions to alter the host file on the Microsoft site
  • You can add the local hosts details to this file, as seen in the example below. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
127.0.0.1       localhost
#Virtual Hosts
x.x.x.x    www.demo.com

However, it may be a good idea to delete these made up addresses out of the local hosts folder when you are done to avoid any future confusion.

Step Seven—RESULTS: See Your Virtual Host in Action

  • Once you have finished setting up your virtual host, you can see how it looks online. Type your ip address into the browser
  • (ie. http://x.x.x.x)

Good Job!

WhatsApp chat