Thursday, 3 April 2014

How To Install Wordpress on Ubuntu

How To Install Wordpress on Ubuntu


Step One—Download WordPress


We can download Wordpress straight from their website:

# wget http://wordpress.org/latest.tar.gz


This command will download the zipped wordpress package straight to your user's home directory. You can unzip it the the next line:

# tar -xzvf latest.tar.gz


Step Two—Create the WordPress Database and User


After we unzip the wordpress files, they will be in a directory called wordpress in the home directory. 

Now we need to switch gears for a moment and create a new MySQL directory for wordpress. 

Go ahead and log into the MySQL Shell:

# mysql -u root -p


First, let's make the database (I'm calling mine wordpress for simplicity's sake; feel free to give it whatever name you choose):

mysql > CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:

mysql > CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

Set the password for your new user:

mysql > SET PASSWORD FOR wordpressuser@localhost=PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)

Finish up by granting all privileges to the new user. Without this command, the wordpress installer will not be able to start up:

mysql > GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Then refresh MySQL:

mysql > FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Exit out of the MySQL shell:
mysql > exit


Step Three—Setup the WordPress Configuration


The first step to is to copy the sample wordpress configuration file, located in the wordpress directory, into a new file which we will edit, creating a new usable wordpress config:

# cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Then open the wordpress config:

# nano ~/wordpress/wp-config.php


Find the section that contains the field below and substitute in the correct name for your database, username, and password:

Step Four—Copy the Files

We are almost done uploading Wordpress to the virtual private server. The final move that remains is to transfer the unzipped WordPress files to the website's root directory.

# rsync -avP ~/wordpress/ /var/www/

Tuesday, 1 April 2014

How To Setup NFS Mount On Ubuntu

About NFS (Network File System) Mounts

NFS mounts work to share a directory between several virtual servers. 

This has the advantage of saving disk space, as the home directory is 

only kept on one virtual private server, and others can connect to it 

over the network. When setting up mounts, NFS is most effective 

for permanent fixtures that should always be accessible.


Master: 172.16.6.12
Client: 172.16.6.13

The system should be set up as root. You can access the root user by typing

$ sudo su

Setting Up the NFS Server

Step One—Download the Required Software


Start off by using apt-get to install the nfs programs.

# apt-get install nfs-kernel-server portmap

Step Two—Export the Shared Directory


The next step is to decide which directory we want to share with the client server. The chosen directory should then be added to the /etc/exports file, which specifies both the directory to be shared and the details of how it is shared. 

Suppose we wanted to share two directories: /home and /var/nfs.

Because the /var/nfs/ does not exist, we need to do two things before we can export it. 

First, we need to create the directory itself:

# mkdir /var/nfs/

Second, we should change the ownership of the directory to the user, nobody and the group, no group. These represent the default user through which clients can access a directory shared through NFS. 

Go ahead and chown the directory:

# chown nobody:nogroup /var/nfs

After completing those steps, it’s time to export the directories to the other VPS:

# nano /etc/exports

Add the following lines to the bottom of the file, sharing both directories with the client:
/home 12.33.44.555(rw,sync,no_root_squash,no_subtree_check)

/var/nfs 12.33.44.555(rw,sync,no_subtree_check)

Once you have entered in the settings for each directory, run the following command to export them:

# exportfs -a


Setting Up the NFS Client


Step One—Download the Required Software


Start off by using apt-get to install the nfs programs.

# apt-get install nfs-common portmap


Step Two—Mount the Directories


Once the programs have been downloaded to the the client server, create the directories that will contain the NFS shared files

# mkdir -p /mnt/nfs/home
# mkdir -p /mnt/nfs/var/nfs


Then go ahead and mount them

# mount 12.34.56.789:/home /mnt/nfs/home
# mount 12.34.56.789:/var/nfs /mnt/nfs/var/nfs

You can use the df -h command to check that the directories have been mounted. You will see them last on the list.

# df -h

Additionally, use the mount command to see the entire list of mounted file systems.

# mount


Testing the NFS Mount


Once you have successfully mounted your NFS directories, you can test that they work by creating files on the Client and checking their availability on the Server.

Create a file in each directory to try it out:

# touch /mnt/nfs/home/example /mnt/nfs/var/nfs/example

You should then be able to find the files on the Server in the /home and /var/nfs directories.

# ls /home

# ls /var/nfs/


You can ensure that the mount is always active by adding the directories to the fstab file on the client. This will ensure that the mounts start up after the server reboots.

# nano /etc/fstab


You can learn more about the fstab options by typing in:

# man nfs

Any subsequent restarts will include the NFS mount—although the mount may take a minute to load after the reboot You can check the mounted directories with the two earlier commands:

# df -h
 
# mount

Removing the NFS Mount


Should you decide to remove a directory, you can unmount it using the umount command:

# cd 
# sudo umount /directory name


You can see that the mounts were removed by then looking at the filesystem again.

# df -h





How To Do SSH Without Password On Ubuntu

1. ssh to server1

ssh myusername@server1
password:
ssh-keygen -t rsa

When you run this command you will be prompted to answer several questions. Just hit enter each time until you are returned to a prompt.

Generating public/private rsa key pair.

Enter file in which to save the key (/home/local/myusername/.ssh/id_rsa):

Created directory '/home/local/myusername/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/local/myusername/.ssh/id_rsa.
Your public key has been saved in /home/local/myusername/.ssh/id_rsa.pub.
The key fingerprint is:
15:68:47:67:0d:40:e1:7c:9a:1c:25:18:be:ab:f1:3a myusername@server1
The key's randomart image is:
+--[ RSA 2048]----+
|        .*Bo=o   |
|       .+o.*  .  |
|       ...= .    |
|         + =     |
|        S +      |
|         .       |
|      . .        |
|      E+         |
|      oo.        |
+-----------------+

Now you will need to copy the public key you just generated and save it somewhere, you will need it later. Also ensure when you copy the key that the text is all on one line, if there are line breaks in the text, it will cause problems later when you try and use the key.

cd .ssh
cat id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyFS7YkakcjdyCDOKpE4RrBecRUWShgmwWnxhbVNHmDtJtK
PqdiLcsVG5PO94hv3A0QqlB1MX33vnP6HzPPS7L4Bq+5plSTyNHiDBIqmZqVVxRbRUKbP44BaA9RsW2ROu
8qdzmXRPupkyFBBOLa23RJJojBieFGygR2OwjS8cq0kpZh1I3c1fbU9I5j38baUK0naTBe2v7s/C8allnJ
hwkfds+Q9/kjaV55pMZIh+9jhoA8acCA6B55DYrgPSycW6fEyV/1PIER+a5lOXp1QCn0U+XFTb85dp5fW0
/rUnu0F9nBJFlo7Rvc1cMuSUiul/wvJ8tzlOhU8FUlHvHqoUUw== myusername@server1

2. ssh to server2

Now we will copy the public key from server1 to server2.

ssh myusername@server2
password:
mkdir .ssh
cd .ssh
vi authorized_keys
# paste the public key
chmod 600 authorized_keys

3. Test that your setup is working

ssh myusername@server1
password:
ssh myusername@server2
# you should not be prompted for a password