Get NIC working in Hyper V for CentOS

Create a new VM in Hyper V – 2GB ram, 60GB disk, using CentOS-6.4x86_64-minimal.iso from Public Mirror list from www.centos.org
(If moving VM – you will need to modify MAC address in the /etc/sysconfig/network-scripts/ifcfg-eth0 file) and then:
After completing this now we need to reload udev configuration to reflect the changes:
start_udev
Create the /etc/sysconfig/network file. This may already exist. If not, enter the following:
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=COMPUTERNAME.DOMAIN
GATEWAY= (your gateway)
Create the network script for the adapter. You’ll need to know the MAC address of the network adapter – you can find this in the VM settings section.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
NM_CONTROLLED=yes
ONBOOT=yes
DHCP_HOSTNAME=$(hostname -s)
chmod 644 /etc/sysconfig/network
Restart the network service to bring up the adapter:
service network restart

Vi Text Editor Commands

As a brief introduction to vi, go through the following: First, type
vi x
at the Unix prompt. Assuming you did not already have a file named x, this command will create one. (If you have tried this example before, x will already exist, and vi will work on it. If you wish to start the example from scratch, simply remove x first.)
The file will of course initially be empty. To put something in it, type the letter i (it stands for “insert-text mode”), and type the following (including hitting the Enter key at the end of each of the three lines):
The quick
brown
fox will return.
Then hit the Escape key, to end insert-text-mode.

Going Further: Other Frequently-Used Commands

You now know how to use vi to insert text, move the cursor to text, and delete text. Technically, the bare-bones set of commands introduced above is sufficient for any use of vi. However, if you limit yourself to these few commands, you will be doing a large amount of unnecessary, tiresome typing.
So, you should also learn at least some of these other frequently-used vi commands:
     h              move cursor one character to left
j move cursor one line down
k move cursor one line up
l move cursor one character to right
w move cursor one word to right
b move cursor one word to left
0 move cursor to beginning of line
$ move cursor to end of line
nG move cursor to line n
control-f scroll forward one screen
control-b scroll backward one screen

i insert to left of current cursor position (end with ESC)
a append to right of current cursor position (end with ESC)
dw delete current word (end with ESC)
cw change current word (end with ESC)
r change current character
~ change case (upper-, lower-) of current character

dd delete current line
D delete portion of current line to right of the cursor
x delete current character
ma mark currrent position
d`a delete everything from the marked position to here
`a go back to the marked position
p dump out at current place your last deletion (``paste'')

u undo the last command
. repeat the last command

J combine (``join'') next line with this one

:w write file to disk, stay in vi
:q! quit VI, do not write file to disk,
ZZ write file to disk, quit vi

:r filename read in a copy of the specified file to the current
buffer

/string search forward for string (end with Enter)
?string search backward for string (end with Enter)
n repeat the last search (``next search'')

:s/s1/s2 replace (``substitute'') (the first) s1 in this line by s2
:lr/s/s1/s2/g replace all instances of s1 in the line range lr by s2
(lr is of form `a,b', where a and b are either explicit
line numbers, or . (current line) or $ (last line)
:map k s map the key k to a string of vi commands s (see below)
:abb s1 s2 expand the string s1 in append/insert mode to a string
s2 (see below)
% go to the "mate," if one exists, of this parenthesis
or brace or bracket (very useful for programmers!)
All of the `:’ commands end with your hitting the Enter key. (By the way, these are called “ex” commands, after the name of the simpler editor from which vi is descended.)
The a command, which puts text to the right of the cursor, does put you in insert-text mode, just like the i command does.
By the way, if you need to insert a control character while in append/insert mode, hit control-v first. For example, to insert control-g into the file being edited, type control-v then control-g.
One of vi‘s advantages is easy cursor movement. Since the keys h,j,k,l are adjacent and easily accessible with the fingers of your right hand, you can quickly reach them to move the cursor, instead of fumbling around for the arrow keys as with many other editors (though they can be used in vi too). You will find that this use of h,j,k,l become second nature to you very quickly, very much increasing your speed, efficiency and enjoyment of text editing.
Many of the commands can be prefixed by a number. For example, 3dd means to delete (consecutive) three lines, starting with the current one. As an another example, 4cw will delete the next four words.
The p command can be used for “cut-and-paste” and copy operations. For example, to move three lines from place A to place B:
1. Move the cursor to A.
2. Type 3dd.
3. Move the cursor to B.
4. Type p.
The same steps can be used to copy text, except that p must be used twice, the first time being immediately after Step 2 (to put back the text just deleted).
Note that you can do operations like cut-and-paste, cursor movement, and so on, much more easily using a mouse. This requires a GUI version of vi, which we will discuss later in this document.

Installing WordPress on CentOS 5/6

  • Article ID: 3643
  • Last updated on August 14, 2013
  • Authored by: Kyle Laffoon
WordPress is a content management system originally developed for blogging, but has beed greatly expanded through widgets, themes and plugins. Complete the following steps to install WordPress on a CentOS 5/6.

Pre-reqs

yum -y install mysql-server httpd php php-mysql unzip wget  
chkconfig httpd on
chkconfig mysqld on
/etc/init.d/mysqld start
/etc/init.d/httpd start

Create a WordPress database and MySQL User

Note: After the wordpress files are unzipped, they will be in a directory called wordpress in the home directory.
  • Log in to the MySQL Shell and create a new MySQL directory for wordpress
    mysql -u root -p
  • After logging in using your MySQL root password, create a WordPress database:
(For this example, we will use the database name WordPressdb.)
   CREATE DATABASE WordPressdb;
  • Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:
    CREATE USER wordpressuser@localhost;
  • Set the password for your new user:
   SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
Note: For security purposes, you would obviously not use “password” for your password. Be sure to assign a secure password in this line instead.
  • Grant all applicable privileges to the new user. Without this command, the wordpress installer will not start up:
   GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password'; 

  • Refresh MySQL:
FLUSH PRIVILEGES;
  • Exit out of the MySQL shell:
   exit

Configure WordPress

  • Copy the sample wordpress configuration file from the wordpress directory, into a new file.
  • Edit the new file to create a new usable wordpress config file:
    cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
  • Open the wordpress config:
    vi ~/wordpress/wp-config.php
  • Find the section that contains the field below and substitute in the correct name for your database, username, and password:
// ** MySQL settings - You can get this info from your web host ** // 
/** The name of the database for WordPress */ define('DB_NAME', 'wordpress');
/**MySQL database username */ define('DB_USER', 'wordpressuser');
/** MySQL database password */ define('DB_PASSWORD', 'password');
  • Save and Exit.

Copy the Files

  • Transfer the unzipped WordPress files to the website’s root directory.
    sudo cp -r ~/wordpress/* /var/www/html
  • Install the following php module on your server, to enable the WordPress installation form online. Download php-gd:
    sudo yum install php-gd
  • Restart Apache:
    sudo service httpd restart

Confirm setup

Apache Virtual Host Containers in Separate Files

1. Introduction

With the size of the Apache configuration file what it is, it can be easier to find and change a virtual host container (configurations) if the settings are in separate files.

 This isn’t strictly recommended by the upstream documentation, but is a common manual extension to make the system more manageable.

 All manual extensions to your system should be documented for future reference.

 There are several places that virtual host source files can be put. This is a complex topic with several major points of view and is not fully addressed in this document.

2. Usual Practice: conf.d/

The most common location for discrete virtual host configuration files is /etc/httpd/conf.d/. The config files can be named to reflect the website(s) to which they refer, provided they don’t conflict with configuration files of existing or future modules. The matching content can be placed under /var/www/ or /var/www/html/ in sub-directories, such as /var/www/example.com/ or/var/www/html/example.com/.
This has the advantage that the parent directories are already created and SELinux is familiar through rule inheritance, as to how to handle access rights. The packaging system leverages this, of course, by dropping the php.conf file into that configurartion directory such that after a package based install of php, and a restart of the webserver, PHP parsed pages ‘just work’
Though placing a vhost configuration file in a directory full of non-vhost related matter, such as: php.conf and mailman.conf, initially appears an out of order jumble, upon closer reading of the documentation, from Apache HTTP Server Version 2.2 – Configuration Sections, we see that: “Most containers are evaluated for each request.”
So, Apache applies the virtual host directives after all non-vhost related stanzas, regardless of the seeming alphabetical sort order position in the configuration file, or in a merged directory full of such config files, in the matter processed.
This is largely a settled area of Systems Administration, such that the most recent documentation from upstream does not appear to include a ‘System Administration Guide’ in the CentOS 5 series. The System Administration Guide from CentOS 4, Chapter 24. Apache HTTP Server Configuration covers the matter in greater depth.

3. Virtual Host Files

Virtual Host container files can be placed in the configuration directory directly or by link. The name must end with .conf to be included. If using links, make sure to update the SELinux properties of the actual file.

3.1. Example

The file should contain the configuration items specific to this host. An example.conf could be…
# file: /etc/http/conf.d/example.conf
# vhost: example.org *.example.org

ServerName example.org
ServerAlias *.example.org
ServerAdmin webmaster@example.org
ErrorLog /var/log/httpd/example.err
CustomLog /var/log/httpd/example.log combined
DocumentRoot /var/www/example.org

Order allow,deny
Allow from all


Of course, a virtual host configuration file may refer to more than one URL or DNS result as a single file tree.
[userid@webhost conf.d]$ cat example.conf 
### two domain vhost sites handled here:
### example.com and example.org
###
### the .COM

ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/example.com/public_html/
ServerName example.com
ServerAlias www.example.com
ErrorLog logs/example.com-error_log
TransferLog logs/example.com-access_log
AccessFileName .htaccess


### the .ORG

ServerAdmin webmaster@example.org
DocumentRoot /var/www/html/example.org/public_html/
ServerName example.org
ServerAlias www.example.org
ErrorLog logs/example.org-error_log
TransferLog logs/example.org-access_log
AccessFileName .htaccess

This file sets up the two domains, one the .com and the other the .org. As to each, it would provide the same content at the bare domain name, and also at the www when used either way in a URL for a web browser, which is usually the desired result, but of course possibly differing content between the two TLD variations as the content down the file tree specified.

4. Virtual Host Inclusion

There might be times when it is desirable to disable a virtual host. Since the include in /etc/httpd/conf/httpd.conf specifies *.conf, it is possible to hide a virtual host by changing the configuration file name.

4.1. Disable Virtual Host

Virtual hosts can be disabled by renaming the file so it doesn’t match the *.conf file specification. Adding a disabled extension is one way.
mv --verbose /etc/httpd/conf.d/example.conf /etc/httpd/conf.d/example.conf.disabled
If less typing is desired, it can be shortened:
mv -v /etc/httpd/conf.d/example.conf{,_}

4.2. Enable Virtual Host

Virtual hosts can be re-enabled by removing the extra.
To remove the disabled flag:
mv --verbose /etc/httpd/conf.d/example.conf.disabled /etc/httpd/conf.d/example.conf
For the shorter version:
mv -v /etc/httpd/conf.d/example.conf{_,}

 Enabling or disabling a virtual host using this method will not take effect until the web server is restarted.

5. Restart Apache

To make your changes take effect, restart Apache. Using the graceful option ensures that existing processes are allowed to finish serving the current page, reducing the chance of disrupting a user’s browsing experience.
service httpd graceful

 Thanks for the graceful suggestion, Filipe. And the pointer to Apache section interpretation.

6. Optional: vhost.d/ method

6.1. Disclaimer

 This section advocates an alternate approach that is outside of the strict, minimalist configuration used by many CentOS system administrators. Like any manual extension of your CentOSsystem, an update of the distribution could render your system broken.

Another location for virtual host container files is a new directory, /etc/httpd/vhost.d/ for example, and adding a vhost.conf file in conf.d/ to tell apache where they are. This segregates the virtual host container files from the module configuration files. This approach allows for easier backups of virtual host configuration changes and removes the possible chance of the different types of files having conflicting names.

6.2. Create Directory

Creating the directory with the same SELinux attributes as /etc/httpd/conf.d/…
mkdir --context=system_u:object_r:httpd_config_t /etc/httpd/vhost.d

6.3. Update SELinux Properties

Verifying the SELinux properties is as simple as…
ls -lZ /etc/httpd
and should return something similar to…
drwxr-xr-x  root root system_u:object_r:httpd_config_t conf
drwxr-xr-x root root system_u:object_r:httpd_config_t conf.d
lrwxrwxrwx root root system_u:object_r:httpd_log_t logs -> ../../var/log/httpd
lrwxrwxrwx root root system_u:object_r:httpd_modules_t modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx root root system_u:object_r:httpd_config_t run -> ../../var/run
drwxr-xr-x root root system_u:object_r:httpd_config_t vhost.d
Since /etc/httpd/vhost.d/ is under /etc/httpd/, it should inherit any policy changes made to /etc/httpd/ and should survive a file system relabel.

6.4. Create New Virtual Host Configuration File

Let Apache know about the virtual host configurations location by creating a new configuration file in conf.d/.
echo "Include vhost.d/*.conf" >>/etc/httpd/conf.d/vhost.conf
Change the context to make sure Apache is allowed to read it
chcon --reference /etc/httpd/conf.d/README /etc/httpd/conf.d/vhost.conf

 Thanks, BrianMathis, for the conf.d/vhost.conf suggestion.

7. Optional: Configuration File Prefix

Naming the files with a prefix, like vhost-, might be more intuitive for others, might make the TLD more visible and would group the active and non-active virtual hosts.

 This method only works with an additional include directive in /etc/httpd/conf/httpd.conf.

 This can be combined with creating a new configuration file in conf.d/ to avoid modifying the distributed httpd.conf.

7.1. Include Directive

Instead of including files that end in .conf, include files that start with vhost-:
echo "Include conf.d/vhost-*" >>/etc/httpd/conf/httpd.conf
or, if using vhost.d/ method:
echo "Include vhost.d/vhost-*" >>/etc/httpd/conf/httpd.conf

7.2. Disable Virtual Host

Add _ to the beginning of a virtual host file name to prevent its inclusion:
mv -v /etc/httpd/conf.d/{,_}vhost-example.org
or, if using vhost.d/ method:
mv -v /etc/httpd/vhost.d/{,_}vhost-example.org

7.3. Enable Virtual Host

Remove the _ from the beginning of a virtual host file name to allow its inclusion:
mv -v /etc/httpd/conf.d/{_,}vhost-example.org
or, if using vhost.d/ method:
mv -v /etc/httpd/vhost.d/{_,}vhost-example.org

 Enabling or disabling a virtual host using this method will not take effect until the web server is restarted.