Category Archives: Ubuntu 14.04

Install Moodle On Ubuntu 14.04 Trusty Tahr

MoodleTest

Moodle is a virtual learning environment used by tens of thousands of schools across the world. Using Moodle, you can create a fully online course, or use it to supplment a traditionally-taught classroom course. Best of all, Moodle is free, and you can install it on Ubuntu 14.04 Trusty Tahr Installing Moodle on Ubuntu is a bit of work, but once it is finished, you’ll have a robust e-learning server application.

It’s quite possible to install Moodle on a machine running either the desktop or the server version of Ubuntu. This makes an excellent environment for testing and experimentation, since you can tweak and experiment to your heart’s desire without rendering your production site inoperable. Given that Moodle is free, if you have a bit of Linux knowledge, you can use Moodle in lieu of far more expensive alternatives.

Let’s begin!

First, install Ubuntu into your machine of choice. Once Ubuntu is installed and updated, you will need to install five pieces of software: the Apache web server, the MySQL database server version 5.5, PHP version 5, the MySQL module for PHP, and finally the Moodle software itself.

First, install the Apache web server. To install Apache, go to a Terminal window or a command prompt and type this command:

sudo apt-get install apache2

(Technically, you’ll be installing Apache 2, the latest version.)

Enter your password to authenticate, follow the default prompts, and apt will download and install the Apache web server for you.

Apache should now be working. To test it from the web server itself, go to a web browser and visit the address http://127.0.0.1 . Alternatively, you could test it from another computer on the same subnet. For instance, if you installed Apache on a computer with an IP address of 192.168.1.100, you could test it by going to another computer on the same subnet and visiting http://192.168.100 from the web browser.

Regardless, if Apache is working properly, you should see a web page with only two words on it:

It works!

Apache is now operational.

The next step to install Moodle is to install the MySQL database server. Return to the Terminal and type this command:

sudo apt-get install mysql-server-5.5

(As of this writing, MySQL Server version 5.5 is the latest version available in the Ubuntu repositories, though future versions of Ubuntu may receive the newer versions of MySQL.)

Enter your password to authenticate, and apt will download the MySQL files and install them for you. It’s a big set of files, so depending on the speed of your Internet connection, it might take a while to download. After the files are downloaded and are installing, the installer will ask you for a password for MySQL’s root user. Just like the root user in Linux, the root user in MySQL has absolute control over all databases, tables, permissions, and users. For obvious security reasons, you’ll want to create an extremely strong password (a mixture of uppercase, lowercase, numbers, and punctuation, the longer the better) for your MySQL root user.

(Note that in the password dialog box, you can’t get the <OK> field selected, you can use the tab key to jump from the text input line to the <OK> field.)

Next, you’ll want to run the mysql_secure_installation script to tighten up security on your new MySQL server. Run this command from the prompt:

sudo mysql_secure_installation

First, the mysql_secure_installation script will ask you to enter the current password for the MySQL root user. After you do that, it will ask if you want to change the root password. Since you already set a root password, you can hit “n” (unless you want to change it again for some reason).

Next, the script will ask if you want to remove the anonymous user. The anonymous user, like anonymous access in FTP, lets someone log into MySQL without having a proper user account. For security reasons, it’s always best to remove the anonymous user, so hit “y” to continue.

After that, the script will ask if you want to prevent the MySQL root user from logging in remotely to the MySQL server. Always hit “y” to forbid root remote access, since if an attacker guesses your root password, he can destroy your databases or steal the information they contain.

After this, the script will ask if you want to remove the test database. MySQL includes a test database that anyone can access. Again, this is a security hole, so you’ll want to hit “y” to remove the test database.

The script will then ask to reload the privilege tables so the changes take effect. Hit “y”, and the mysql_secure_installation script will conclude and return you to the command line.

MySQL server is now installed on your Ubuntu system.

Now we’ll need to prepare MySQL for use with Moodle. Moodle requires a database and a database user, and full permission for its database user to access its database. To start the MySQL command-line client, use this command:

mysql -u root -p

Enter the password for the MySQL root user, and you’ll find yourself at the MySQL command prompt, which will look like this:

mysql>

Our next steps are to create a Moodle database, create a user to access that database, and grant our new user all rights to the Moodle database.

(An important note before we continue, though. All commands made from the MySQL prompt must end with a semicolon to denote the end of the statement. Any commands that do not end with a semicolon will not work. With that in mind, let’s first create a database.)

To create a database for Moodle, use this command at the mysql> prompt:

CREATE DATABASE moodle;

The MySQL client will respond with a message that should say “Query OK, 1 row affect (0.00 sec).” This means the command was successful, and a new database named “newdatabase” has been created.

Next, you’ll create a user who will access that database:

CREATE USER moodleuser;

You should get the “Query OK” message again. Once the new user is created, we’ll need to set a password for the user before we can assign any permissions. In this example, we’ll assign a password of “1234″. However, in real life, just as with the root user, you’ll want to assign a much, much stronger password than this. (This database user won’t have full control over the MySQL user as the root user does, but we will give it full control over the database we just created, and a malicious user who guesses the password could cause all kinds of trouble.)  To create the password, use this command:

SET PASSWORD FOR moodleuser= PASSWORD(“1234”);

Again you should get the “Query OK” confirmation message. The final step is to assign all privileges on the “moodle” database to the “moodleuser” user. Use this command to assign the permissions:

GRANT ALL PRIVILEGES ON moodle.* TO moodleuser IDENTIFIED BY ‘1234′;

That isn’t a typo – those are single quote marks (‘) instead of the usual double quote marks (“) that were used in the command to set the password. MySQL’s internal syntax, alas, isn’t always consistent. Anyway, if you typed the command correctly, you should get the “Query OK” confirmation again.

Once you are done, use this command to quit the MySQL command-line interface:

exit

The next step to installing Moodle is to install PHP version 5, along with the necessary PHP modules. First, install PHP 5 with this command:

sudo apt-get install php5

After this, you will need to install several different PHP extensions not included with the default PHP 5 implementation on Ubuntu. First, install the MySQL module for PHP:

sudo apt-get install php5-mysql

You must also install the GD library for PHP:

sudo apt-get install php5-gd

The JSON extension is also required:

sudo apt-get install php5-json

The CURL extension:

sudo apt-get install php5-curl

The XMLRPC extension:

sudo apt-get install php5-xmlrpc

And, finally, the INTL extension:

sudo apt-get install php5-intl

After all the plugins have installed, restart Apache so it recognizes the plugins properly:

sudo /etc/init.d/apache2 restart

Finally, download the Moodle software to your Desktop. You can obtain it from this address:

http://download.moodle.org

Move the Moodle files over to the /var/www/html directory. (In this command, I’ll assume you unpacked the moodle files to your home directory; you will have to adjust the command if you unpacked them in a different directory.)

sudo cp -r ~/moodle/* /var/www/html

After that, rename the old index.html file in /var/www/html so Apache uses Moodle’s PHP files for the site, not the index.html file:

sudo mv index.html index.html.old

Now that we’ve got our software downloaded, we’ll need to configure it.

You will need to create a location for Moodle to save data files. Traditionally, the location is in /var/moodledata. (Creating the data directory inside the web server directory is an extremely bad idea, due to the resultant security holes.) To create the data directory, use this command:

sudo mkdir /var/moodledata

Use this command to change the owner of the directory to the Apache system user. In Ubuntu, the Apache system user is usually named www-data:

sudo chown www-data /var/moodledata

Then use this command to make the /var/moodledata directory writable to Moodle:

sudo chmod -R 744 /var/moodledata

Now that configuration and setup is complete, we are actually read to begin installing Moodle!

Fire up a web browser and navigate to the Moodle location to launch the web-based installer. If your server’s IP address (for example) is 192.168.1.100, the address would look like this:

http://192.168.1.100

This will take you to the Moodle setup page.

First, select the language for your Moodle installation, and then click the Next button.

The installer will then ask for the locations of Moodle’s directories. The defaults will work, especially if you already created the /var/moodledata directory as indicated above. Click the Next button to continue.

Moodle will then ask what kind of database server to use. Since we already set up our MySQL database, select “Improved MySQL” and then hit the Next button.

Then installer will then need you to input the information for the database and database user we created above. Since our MySQL server is on the same machine as Moodle, leave “localhost” for the Database Host field. Enter “moodle” for Database Name, “moodleuser” for Database User, and then ‘1234’ for Database Password. Leave the other fields blank, and then click Next.

Moodle will then generate a config.php file. Copy and paste the data of the config.php file, save it as “config.php”, and then transfer it to your server. Make sure to put it in the directory containing the Moodle installation – in this example, /var/www. Once the config.php is in place, make sure to mark it as executable with this command, otherwise the installation will halt:

sudo chmod 744 /var/www/html/config.php

Save the config.php file, and then go back to the web browser and click the Next button.

Moodle will then ask if you agree to the terms of service. If you do, click the Continue button.

The installer will then run a system check to make sure your server has all the necessary software to support Moodle. If not (it’s common to forget one of the PHP extensions), the installation will pause to allow you to install the missing software. Once you have, click Reload. If all the checks are passed, you can click the Continue button to continue.

The Moodle installer will then start building the database tables it requires in the database we created earlier. The Moodle database is large and complex, and building the database may take a considerable amount of time, so be patient. As the installer successfully builds database tables, they will scroll down in the browser window. Once the database construction is complete, the Continue button will appear at the very bottom of the page. Click on it to continue.

Moodle will then display a form for you to set up an administrator account for your new site. Enter an appropriate username and a strong password, along with any other required fields. Once you have finished, click on the Update Profile button at the bottom of the page.

The install will then ask you to pick a full site name and a short name for the site. Select suitable names, and then click the Save Changes button.

Congratulations! Your Moodle installation is now complete, and you can begin adding courses and other materials. For additional documentation, the Moodle site contains many useful resources:

http://docs.moodle.org/26/en/Main_page

-JM

ADDITIONAL READING:

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Enable Workspaces (Virtual Desktops) In Ubuntu 14.04 Trusty Tahr And Ubuntu 14.10 Utopic Unicorn

For several years, Linux has used what’s called virtual desktops, and Ubuntu has called its implementation of virtual desktops “workspaces”. Basically, when you boot up and log into your computer, you see your main desktop, but you can then create a number of different virtual desktops that you can switch to, essentially allowing you to have multiple desktops on one computer. You can moving running applications between Workspaces, letting you put, say, LibreOffice Writer documents on one Workspace and spreadsheets on another. (Though a more common use is to put work documents on one and games on another, allowing the user to switch quickly from games to work should the boss walk by.)

By default, the Workspaces feature in Ubuntu 14.04 Trusty Tahr and Ubuntu 14.10 Utopic Unicorn are disabled. Fortunately, it’s quite easy to turn back on.

To enable virtual desktops in Ubuntu, first launch the System Settings application by clicking on its icon in the Launcher, or by going to the Dash, searching for “System Settings”, and clicking on its icon when it appears. After System Settings launches, click on the icon for Appearance, which will be the first icon on the left on the top row.

When the Appearance item opens up, click on the Behavior tab. After the display switches to the Behavior tab, put a check mark on Enable Workspaces check box. This will immediately enable Workspaces, and add a Workspaces icon to the Launcher. You can click on the Workspaces icon on the Launcher to switch between Workspaces, or use the CTRL+ALT+ARROW KEYS to switch between them.

-JM

Backup And Restore MySQL Databases With mysqldump In Ubuntu 14.04 Trusty Tahr

Terminal
MySQL databases are often used to power web applications such as WordPress or Moodle, which means that those MySQL databases often wind up holding vital information. Therefore, it is important to back them up on a regular basis. A quick and easy way to backup a MySQL database is with the mysqldump command-line tool. This tool downloads the database into a single SQL file, which you can store as a backup or use to transfer the database to another MySQL server, and is quite easy to use in Ubuntu 14.04 Trusty Tahr.

To use mysqldump, you will need to know the root password of the MySQL server (or a user with permissions to the database you need to download).

In this example, we will dump a database named data into a file named data.sql:

mysqldump -u root -p data > data.sql

Enter the root password, and mysqldump will dump the database information into the data.sql file.

To transfer the database to a new server, first create a blank database on the server from the MySQL command prompt. In this example, this command will create a new database named datanew:

CREATE DATABASE datanew;

Then transfer the data.sql file to the new server and write it onto the new database with this command:

mysql -u root -p datanew < data.sql

The datanew database will receive all the tables and columns contained in the data.sql file. Note that this command completely overwrites the target database with the information in the SQL file, so make sure to select the correct database!

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Set A Static IP Address From The Command Line In Ubuntu 14.04 Trusty Tahr

Terminal

It is not intuitively obvious how to assign Ubuntu 14.04 Trusty Tahr a a static IP address from the command line. However, much of Linux administration involves the editing of text files, and assigning a static IP address is no different. You’ll need to edit the following file:

/etc/network/interfaces

Initially, the file only contains information about your local loopback address:

auto lo
iface lo inet loopback

To assign a static IP address, you’ll need to make some changes to this file.

Let’s say you want to assign a static IP of 192.168.1.2 to your eth0 network connection (the first Ethernet adapter on your system; if you only have one, it will be eth0), with a subnet mask of 255.255.255.0 and a local gateway of 192.168.1.1. First, make a backup copy of the interfaces file:

sudo cp /etc/network/interfaces ~

This will make a backup copy in your home directory in case something goes amiss during the editing process. Next, fire up a text editor:

sudo vi /etc/network/interfaces

(Obviously you can substitue emacs or your editor of choice.)

Once the file is open, add the following lines:

iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1

Once you’ve added these lines, save the interfaces file to disk, and exit your text editor.

You’ll then to need have your system load the new IP configuration. You can do that by rebooting, but if that takes too long, you can use this command to force Linux Mint 14 to re-read the configuration files:

sudo ifup eth0

Your system will then have a static IP address.

-JM

/etc/network/interfaces

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Set A Static DNS Server Address In Ubuntu 14.04 Trusty Tahr

Gateway

It is not immediately obvious how to set a static DNS server address from the command line in Ubuntu 14.04 Trusty Tahr. In the Desktop version of Ubuntu, you can of course use the graphical Network Manager to assign a static DNS server. In the Server version, things are a little more complicated. This post will explain how to use the resolvconf utility to set a static address for the DNS server. (In this example, we will assume your DNS server has an address of 192.168.1.100.)

First, log into Ubuntu, and then navigate to this directory:

 /etc/resolvconf/resolv.conf.d

Once you are in the appropriate directory, use this command to launch the vi text editor:

 sudo vi /etc/resolvconf/resolv.conf.d/head

This will open up resolvconf’s head text file in vi. Once vi has launched, press the INSERT key to switch vi to edit mode, and then enter the following line:

 nameserver 192.168.1.100

Then hit the ESC key to switch vi back to command mode, and type this command to save the edited text file and then quit vi:

 :wq

Once vi exits, type this command:

 sudo resolvconf -u

The resolvconf utility will then read the head file and set the static DNS server address you entered.

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Install WordPress In Ubuntu 14.04 Trusty Tahr

WordPress

WordPress is a content management system that powers quite a variety of websites, first developed in 2003. In WordPress’s early days, it tended to run only personal blogs and smaller sites. However, the software improved considerably with every version, and it’s adaptable enough to be used for a variety of different sites. WordPress’s big break came in 2009 when popular blogging platform Movable Type changed its licensing terms. Enough Movable Type users were annoyed with the change that they migrated to WordPress, and WordPress is the dominant open-source content management system on the Internet as of this writing.

It’s quite possible to install WordPress on a machine running either the desktop or the server version of Ubuntu 14.04 Trusty Tahr. This makes an excellent environment for testing and experimentation, since you can tweak and experiment to your heart’s desire without rendering your production blog inoperable. If you need to run an internal corporate blog of some kind, hosting WordPress on an Ubuntu box or virtual machine is a cheaper solution than more expensive blogging or collaboration software. Or, if you’re really ambitious (and you can afford the bandwidth), you can host an Internet-accessible WordPress blog out of your apartment.

Let’s begin!

(Note that the Ubuntu repositories now contain a fully automated WordPress installation. However, I believe that installing it by hand yourself has significant value – you’ll not only learn how to set up a LAMP server, but installing step-by-step gives you valuable troubleshooting knowledge later on in case something breaks.)

First, install Ubuntu into your machine of choice. Once Ubuntu is installed and updated, you will need to install five pieces of software: the Apache web server, the MySQL database server version 5.6, PHP version 5, the MySQL module for PHP, and finally the WordPress software itself.

First, install the Apache web server. To install Apache, go to a Terminal window or a command prompt and type this command:

sudo apt-get install apache2

(Technically, you’ll be installing Apache 2, the latest version.)

Enter your password to authenticate, follow the default prompts, and apt will download and install the Apache web server for you.

And that’s it! Apache should now be working. To test it from the web server itself, go to a web browser and visit the address http://127.0.0.1 . Alternatively, you could test it from another computer on the same subnet. For instance, if you installed Apache on a computer with an IP address of 192.168.1.100, you could test it by going to another computer on the same subnet and visiting http://192.168.100 from the web browser.

Regardless, if Apache is working properly, you should see a web page with only two words on it:

It works!

Apache is now operational.

The next step to install WordPress is to install the MySQL database server. Return to the Terminal and type this command:

sudo apt-get install mysql-server-5.6

(As of this writing, MySQL Server version 5.6 is the latest version available in the Ubuntu repositories, though future versions of Ubuntu may receive the newer versions of MySQL.)

Enter your password to authenticate, and apt will download the MySQL files and install them for you. It’s a big set of files, so depending on the speed of your Internet connection, it might take a while to download. After the files are downloaded and are installing, the installer will ask you for a password for MySQL’s root user. Just like the root user in Linux, the root user in MySQL has absolute control over all databases, tables, permissions, and users. For obvious security reasons, you’ll want to create an extremely strong password (a mixture of uppercase, lowercase, numbers, and punctuation, the longer the better) for your MySQL root user.

(Note that in the password dialog box, you can’t get the <OK> field selected, you can use the tab key to jump from the text input line to the <OK> field.)

After you enter the root password, the installer will finish working with the MySQL files, and return you to the command line. You’ll then need to activate MySQL with the following command:

sudo mysql_install_db

This will set up MySQL Server for use with your Ubuntu system. Next, you’ll want to run the mysql_secure_installation script to tighten up security on your new MySQL server. Run this command from the prompt:

sudo mysql_secure_installation

First, the mysql_secure_installation script will ask you to enter the current password for the MySQL root user. After you do that, it will ask if you want to change the root password. Since you already set a root password, you can hit “n” (unless you want to change it again for some reason).

Next, the script will ask if you want to remove the anonymous user. The anonymous user, like anonymous access in FTP, lets someone log into MySQL without having a proper user account. For security reasons, it’s always best to remove the anonymous user, so hit “y” to continue.

After that, the script will ask if you want to prevent the MySQL root user from logging in remotely to the MySQL server. Always hit “y” to forbid root remote access, since if an attacker guesses your root password, he can destroy your databases or steal the information they contain.

After this, the script will ask if you want to remove the test database. MySQL includes a test database that anyone can access. Again, this is a security hole, so you’ll want to hit “y” to remove the test database.

The script will then ask to reload the privilege tables so the changes take effect. Hit “y”, and the mysql_secure_installation script will conclude and return you to the command line.

MySQL server is now installed on your Ubuntu system.

The next step to installing WordPress is to install PHP version 5:

sudo apt-get install php5

Then install the MySQL module for PHP:

sudo apt-get install php5-mysql

You may also want to install the GD library for PHP, since many WordPress plugins rely on it for graphical manipulation:

sudo apt-get install php5-gd

Finally, download the WordPress software to your Desktop. You can obtain it from this address:

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

If you’re working exclusively from the command line, you can use this command to download the WordPress software:

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

Use this command to unpack the WordPress files:

tar -xzvf latest.tar.gz

Make a directory in /var/www/html for the WordPress files:

sudo mkdir /var/www/html/wordpress

Finally, move the WordPress files over to the /var/www/html/wordpress directory. (In this command, I’ll assume you unpacked the WordPress files to your home directory; you will have to adjust the command if you unpacked them in a different directory.)

sudo cp -r ~/wordpress/* /var/www/html/wordpress

Now that we’ve got our software installed and downloaded, we’ll need to configure it. We’ll start with Apache.

First, it’s always a good idea to make a backup of a system configuration file before you alter it, so start by making a back of Apache’s configuration file. Use this command to back up Apache’s configuration file to your home directory:

cp /etc/apache2/apache2.conf ~

Next, you’ll need to add a line to your /etc/apache2/apache2.conf file, so Apache will properly interpret WordPress’s PHP files. (Note that this is only necessary if you install WordPress in a subdirectory of /var/www, as we are doing in this example. If you install WordPress in /var/www, you don’t need to add this line, but you do need to delete or move the original index.html file.) To edit apache2.conf, fire up the vi editor:

sudo vi /etc/apache2/apache2.conf

Once you are in vi, scroll to the end of the vile, switch to Insert mode, and add the following line:

AddType application/x-httpd-php .html

Return vi to Command mode, save the file, and then exit vi. Restart Apache with this command, so it re-reads its configuration file:

sudo /etc/init.d/apache2 restart

Now we’ll need to prepare MySQL for use with WordPress. WordPress requires a database and a database user, and full permission for its database user to access its database. To start the MySQL command-line client, use this command:

mysql -u root -p

Enter the password for the MySQL root user, and you’ll find yourself at the MySQL command prompt, which will look like this:

mysql>

Our next steps are to create a WordPress database, create a user to access that database, and grant our new user all rights to the WordPress database.

(An important note before we continue, though. All commands made from the MySQL prompt must end with a semicolon to denote the end of the statement. Any commands that do not end with a semicolon will not work. With that in mind, let’s first create a database.)

To create a database for WordPress, use this command at the mysql> prompt:

CREATE DATABASE wordpress;

The MySQL client will respond with a message that should say “Query OK, 1 row affect (0.00 sec).” This means the command was successful, and a new database named “newdatabase” has been created.

Next, you’ll create a user who will access that database:

CREATE USER wordpressuser;

You should get the “Query OK” message again. Once the new user is created, we’ll need to set a password for the user before we can assign any permissions. In this example, we’ll assign a password of “1234″. However, in real life, just as with the root user, you’ll want to assign a strong password. (This database user won’t have full control over the MySQL user as the root user does, but we will give it full control over the database we just created, and a malicious user who guesses the password could cause all kinds of trouble.)  To create the password, use this command:

SET PASSWORD FOR wordpressuser = PASSWORD(“1234”);

Again you should get the “Query OK” confirmation message. The final step is to assign all privileges on the “wordpress” database to the “wordpressuser” user. Use this command to assign the permissions:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser IDENTIFIED BY ‘1234′;

That isn’t a typo – those are single quote marks (‘) instead of the usual double quote marks (“) that were used in the command to set the password. MySQL’s internal syntax, alas, isn’t always consistent. Anyway, if you typed the command correctly, you should get the “Query OK” confirmation again.

Once you are done, use this command to quit the MySQL command-line interface:

exit

Then type exit to quit the MySQL local command-line client. Now that we have MySQL prepared, we can now configure WordPress itself. Specifically, we’ll have to configure WordPress to talk to the database we just created. To do so, you must create a wp-config.php file in the WordPress directory. Fortunately, WordPress includes a handy wp-config-sample.php you can use as a template.

Type this command to create a wp-config file (assuming you installed WordPress in the /varwww/html/wordpress directory):

sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

Next, use vi to edit the newly created wp-config file:

sudo vi /var/www/html/wordpress/wp-config.php

You’ll see that the wp-config.php file contains a number of variables. Change the following three variables:

-Change putyourdbnamehere to wordpress.

-Change usernamehere to wordpressuser.

-Change yourpassword here to 1234.

Once you have your changes made (after double-checking the spelling, of course), switch vi to Command mode, and save your changed file.

Everything should now be ready. Open up a web browser, and navigate to http://127.0.0.1/wordpress. (If you want to access it from a different machine, of course, use the IP address of the WordPress server, for instance – http://192.168.1.100/wordpress .)If you configured everything correctly, you should then be greeted by the WordPress configuration page. You’ll pick a username, and WordPress will assign you a password. Follow the prompts, and you will have a functional WordPress blog installed on a Ubuntu machine. Congratulations!

One final note: if you configure your blog from a local browser, it will probably set your blog’s address as http://127.0.0.1/wordpress. This is fine if you only want to view it from the host machine, but if you want to view it over the network, you’ll need to change it. Fortunately, you can do so quickly by going Options in the WordPress admin interface, and then to General, and changing the blog’s URL.

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Install And Configure MySQL Server On Ubuntu 14.04 Trusty Tahr

MySQL

To install MySQL Server 5.5 on Ubuntu 14.04 Trusty Tahr, make your way to a Terminal window or a command prompt, and type this command:

sudo apt-get install mysql-server-5.5

(As of this writing, MySQL Server version 5.5 is the latest version available in the repositories, though future versions of Ubuntu may receive the newer versions of MySQL.)

Enter your password to authenticate, and apt will download the MySQL files and install them for you. It’s a big set of files, so depending on the speed of your Internet connection, it might take a while to download. After the files are downloaded and are installing, the installer will ask you for a password for MySQL’s root user. Just like the root user in Linux, the root user in MySQL has absolute control over all databases, tables, permissions, and users. For obvious security reasons, you’ll want to create an extremely strong password (a mixture of uppercase, lowercase, numbers, and punctuation, the longer the better) for your MySQL root user.

(Note that in the password dialog box, you can’t get the <OK> field selected, you can use the tab key to jump from the text input line to the <OK> field.)

After you enter the root password, the installer will finish working with the MySQL files, and return you to the command line. You’ll then need to activate MySQL with the following command:

sudo mysql_install_db

This will set up MySQL Server for use with your Ubuntu system. Next, you’ll want to run the mysql_secure_installation script to tighten up security on your new MySQL server. Run this command from the prompt:

sudo mysql_secure_installation

First, the mysql_secure_installation script will ask you to enter the current password for the MySQL root user. After you do that, it will ask if you want to change the root password. Since you already set a root password, you can hit “n” (unless you want to change it again for some reason).

Next, the script will ask if you want to remove the anonymous user. The anonymous user, like anonymous access in FTP, lets someone log into MySQL without having a proper user account. For security reasons, it’s always best to remove the anonymous user, so hit “y” to continue.

After that, the script will ask if you want to prevent the MySQL root user from logging in remotely to the MySQL server. Always hit “y” to forbid root remote access, since if an attacker guesses your root password, he can destroy your databases or steal the information they contain.

After this, the script will ask if you want to remove the test database. MySQL includes a test database that anyone can access. Again, this is a security hole, so you’ll want to hit “y” to remove the test database.

The script will then ask to reload the privilege tables so the changes take effect. Hit “y”, and the mysql_secure_installation script will conclude and return you to the command line.

MySQL server is now installed on your Ubuntu system. In the next section, we’ll discuss using the MySQL command-line client to create databases and users.

The most common use for MySQL on a Ubuntu system is to provide a backend for a dynamic website of some kind, usually content management systems like WordPress or MediaWiki. To host these websites on a Ubuntu machine, you’ll need to create a database and a database user for the website. MySQL Server can support many different databases, limited by the amount of hardware and disk space available on the machine. (Hosting multiple active databases at the same time places a high level of demand upon a hard drive.)

Like Samba, MySQL has its own collection of user accounts, separate from the main system accounts, called “database users.” A database user is simply a MySQL user that has access to a particular database, or specific tables within a database. In this section, we’ll show you how to create database and users with the command-line client.

First, you’ll need to get to the MySQL client prompt. The MySQL command-line client, like the command-line clients for FTP and SFTP, has its own prompt. To access that prompt and start the client, use this command:

mysql

However, if you simply type the command, it will bounce back with an error message. To use the MySQL command-line client, you need to add the -u and the -p switches as well. The -u switch tells it what MySQL user you want to use to log into the client (similar to the -l switch with SSH). The -p switch tells it to ask for the password. So, to use the MySQL client as the MySQL root user, the command should look like this:

mysql -u root -p

Enter the password for the MySQL root user, and you’ll find yourself at the MySQL command prompt, which will look like this:

mysql>

Our next steps are to create a database, create a user to access that database, and grant our new user all rights to that database. Generally, when you’re installing a web application like WordPress, you’ll give the database user you create for the WordPress application all rights to the database so it can function properly. Not giving the application user all rights to the database can cause the application to act erratically or even fail entirely (though some applications can work with limited access to its database).

An important note before we continue, though. All commands made from the MySQL prompt must end with a semicolon to denote the end of the statement. Any commands that do not end with a semicolon will not work. With that in mind, let’s first create a database.

To create a database, use this command at the mysql> prompt:

CREATE DATABASE newdatabase;

The MySQL client will respond with a message that should say “Query OK, 1 row affect (0.00 sec).” This means the command was successful, and a new database named “newdatabase” has been created.

Next, you’ll create a user who will access that database:

CREATE USER newdatabaseruser;

You should get the “Query OK” message again. Once the new user is created, we’ll need to set a password for the user before we can assign any permissions. In this example, we’ll assign a password of “1234″. However, in real life, just as with the root user, you’ll want to assign a strong password. (This database user won’t have full control over the MySQL user as the root user does, but we will give it full control over the database we just created, and a malicious user who guesses the password could cause all kinds of trouble.)  To create the password, use this command:

SET PASSWORD FOR newdatabaseuser= PASSWORD(“1234”);

Again you should get the “Query OK” confirmation message. The final step is to assign all privileges on the “newdatabase” database to the “newdatabaseuser” user. Use this command to assign the permissions:

GRANT ALL PRIVILEGES ON newdatabase.* TO newdatabaseuser IDENTIFIED BY ‘1234;

That isn’t a typo – those are single quote marks (‘) instead of the usual double quote marks (“) that were used in the command to set the password. MySQL’s internal syntax, alas, isn’t always consistent. Anyway, if you typed the command correctly, you should get the “Query OK” confirmation again.

Once you are done, use this command to quit the MySQL command-line interface:

exit

You’ve now set up a database, created a database user, and given that user full control over that database.

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Set Up Apache Virtual Hosts On Ubuntu 14.04 Trusty Tahr

ApacheVirtualHosts

It is quite easy to set up an Apache web server on a Ubuntu 14.04 Trusty Tahr system.However, you might need a more complex web server, one that can host multiple separate websites, rather than subdirectories within a larger website.

How do you do this?

Apache has a feature called “virtual hosts” that lets you run separate websites, with completely different domain names, on the same physical server. Fortunately, implementing virtual hosts for Apache on Ubuntu is actually quite simple to do. In this example, we’ll show you how to set up a new website called “examplename.com” on an Apache web server.

First, you’ll need to set a location for your new web site’s files. Apache, you might recall, by default stores the web files in /var/www. For this example, create a new folder for the website with this command:

sudo mkdir /var/w2

Next, you’ll need to create a configuration file for the new website in the /etc/apache2/sites-available directory. Fortunately, that directory contains a default file you can simply copy and use as a template with this command:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/examplename.conf

Note that any configure files you create MUST have a *.conf extension!

The next step is to edit the new configuration file with the correct settings. You can do this using the vi text editor:

sudo vi /etc/apache2/sites-available/examplename.conf

Once editing the file with vi, you’ll need to make a few changes.

Change the “Document Root” directive from /var/www to the proper location of your new website, in this case, /var/w2.

Also change the “Directory” directive from /var/www to /var/w2.

Finally, under the line that begins “ServerAdmin”, add a new line for the new website’s domain name. For our website named “examplename.com”, add a line like this:

ServerName examplename.com

Save changes to the configuration file, and then exit vi.

Now you’ll need to modify Apache to display the new domain names to web visitors. Fortunately, you can do this with the a2ensite command:

sudo a2ensite examplename.conf

(Note that “examplename” would change depending upon what you named your configuration file.)

One final step – restart Apache to force it to re-read its configuration files and start serving the new website:

sudo /etc/init/d apache2 reload

Make sure you have some sort of index.html file in /var/w2, and the examplename.com website should now be working.

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide

Install And Configure Apache Web Server on Ubuntu

ApacheVirtualHosts

As installations go, installing Apache on Ubuntu 13.10 Saucy Salamander is a breeze. (Configuring it, of course, is substantially more difficult.) To install Apache, type this command at a Terminal window or a command prompt:

sudo apt-get install apache2

(Technically, you’ll be installing Apache 2, the latest version.)

Enter your password to authenticate, follow the default prompts, and apt will download and install the Apache web server for you.

And that’s it! Apache should now be working. To test it from the web server itself, go to a web browser and visit the address http://127.0.0.1 . You’ll remember that this is the “local loopback” address, basically the IP address the local computer uses to refer to itself. Alternatively, you could test it from another computer on the same subnet. For instance, if you installed Apache on a computer with an IP address of 192.168.1.100, you could test it by going to another computer on the same subnet and visiting http://192.168.100 from the web browser.

Regardless, if Apache is working properly, you should see a web page with only two words on it:

It works!

Apache is now operational.

-JM

ADDITIONAL READING:

Ubuntu: 101 Tips & Tricks

The Ubuntu Beginner’s Guide

The Ubuntu Desktop Beginner’s Guide

The Linux Command Line Beginner’s Guide