If you’d like to install WordPress on your cloud server, one of the easiest approaches is to work in shell. In this article we’ll explain how to:

Create a new database in MYSQL

Download the latest WordPress package using WGET and TAR

Later, in another post, I’ll cover actually installing WordPress. The first step is to create a new database. To do this, first log into your server via shell. If you are on a remote computer , I recommend using Putty.

Once logged into shell it will be necessary to log into MYSQL. I use the mysql command with the root user as follows:

sudo mysql -u root -p

Breaking this command down, I entered ‘sudo’ so the system recognizes me as an administrator for this command, then mysql. -u is to indicate the next string is a user and -p indicates it should prompt me for a password.

Note, because I used sudo the system will first prompt me for my sudo (superuser) password. Once I enter it the system will prompt me for the password for my root database account.

If you run your own LAMP stack there will probably come a day when you are ready to run more than one CMS driven website on the server. When the time comes, it becomes necessary to create a new database for each one. It is a very bad idea to provide anyone with root access to the database so creating unique users for each new database is recommended.

When I first moved from Microsoft to LAMP servers there was nothing more confusing to me than interacting with a database through shell. However, since I’ve grown used to working this way, I’ve actually come to prefer it. I also think it is an important skill for any programmer or ‘code-curious’ individual to get familiar with so we’ll approach the task this way.

Once logged into shell it will be necessary to log into MYSQL. I use the mysql command with the root user as follows:

sudo mysql -u root -p

Breaking this command down, I entered ‘sudo’ so the system recognizes me as an administrator for this command, then mysql. -u is to indicate the next string is a user and -p indicates it should prompt me for a password.

Note, because I used sudo the system will first prompt me for my sudo (superuser) password. Once I enter it the system will prompt me for the password for my root database account.

Once successfully logged into the database there are only two things to do:

Create a new user

Grant the new user rights to an existing database

The first step, creating a new user is accomplished using the CREATE USER command. The syntax is as follows:

CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;

The items in capital letters are parts of the command that don’t change. The parts within the single quotes are all variables which can be changed. However, if you are working on one machine like I do, ‘localhost’ does not change. Give the new user a custom name and password and don’t forget the trailing semicolon!

The final command will give the new user rights to a specified, existing database using the GRANT command:

GRANT ALL ON database.* TO ‘user’@’localhost’;

In this case the word database and the elements within single quotes are all variables. Database should be replaced with the name of the database you want to give the user access to. User should be replaced with the name of the user you just created and the same rules apply for localhost.

Some things to keep in mind:

In order to confirm the correct spelling of the database name use the command SHOW DATABASES;

Be sure to use sufficiently complex passwords for database users. We recommend at least 8 characters in length using upper and lowercase letters, numbers and special characters.

In this Rackspace Recipe we’ll configure a ‘sites-available’ file in Apache2 in order to allow Drupal (or WordPress) to rewrite paths. After installing a Drupal site on a Rackspace Cloud server for the first time, chances are you’ll notice it is not possible to enable the Clean URLs feature. This is most likely because Drupal doesn’t have permission to rewrite the path.

Fortunately, this is a very simple issue to correct. In order to gain access to the sites-available file for the site in question, it is necessary to log in via SSH or shell access on a Unix, Linux or a Mac. You can also access the shell by logging into the Rackspace cloud management console for your account. If you are trying to access SSH via a PC I recommend PuTTY.

All of the Rackspace Recipes on betaprogrammer.com reference the specific installation we’re currently using, which is Ubuntu server running apache2. Some differences may exist on other specific configurations.

Each site we publish on our Rackspace server uses a unique sites-available configuration file. These ‘files’ are located in a specific location by default: /etc/apache2/sites-available. Once logged into the server, type the following:

Of course, change the directory from ‘example’ to the actual directory for the specific site in question. Once this is complete use control-x to exit nano and be sure to save the file under the same name. Once out of the site it couldn’t hurt to restart apache with the following command:

sudo /etc/init.d/apache2 reload

In order to determine success, simply log into the Drupal site and check to see if it is now possible to enable clean URL’s. (/admin/settings/clean-urls)

If you don’t have a lot of experience working in sites-available configuration files it is a good idea to start by saving a backup of the file contents. This way, if anything goes wrong, you can quickly revert back to the way it was before you started.

This technique can also be used to make it possible for a WordPress site to create simple paths. However, the code for WordPress is slightly different:

Care to venture a guess as to how easy it is to launch a fresh installation of the Drupal CMS? Would you guess 50, 25 or 12 steps? How about 8 steps? Believe it or not, that’s right. In this Rackspace Recipe we will review just how easy it is. This tutorial assumes you’re working on a Linux server with the LAMP stack and Drush previously installed. It also assumes you are logged into the shell with sudo permissions.

Drush is an incredible tool which I could talk about for days, if I fully understood it. This is literally just the tip of the iceberg. To take this one step further…what if you wanted to add a bunch of modules to your new Drupal site? That’s pretty easy too. For instance…you could download an unlimited number of modules using Drush dl (download). Example:

In this Rackspace Recipe we’re going to map out the process for installing LAMP (Linux Apache MySQL PHP) on an Ubuntu server. This will all be done from the command prompt or shell, as it is called in Linux and Unix. If you are attempting to connect to a Linux machine from Windows I suggest using PuTTY. On a Mac or Linux machine, simply open the shell utility and log in to the server with SSH using the credentials provided by Rackspace.

Once logged in:

Type ‘sudo apt-get install apache2′ (yes, it will download and install the package)

Type ‘y’ when prompted

Test Apache by opening a web browser and entering the IP address of your machine.

Type ‘sudo apt-get install php5 libapache2-mod-php5′

Type ‘y’ when prompted

Type ‘sudo /etc/init.d/apache2 restart’

Create a file called using ‘sudo nano /var/www/testphp.php’ enter the following line: <?php phpinfo(); ?> and then click control x to close and save the file.

Open a browser and navigate to http://yourserverip/testphp.php. If you see the PHP diagnostic page you’ve successfully installed PHP.

Type ‘sudo apt-get install mysql-server’

During the install you’ll be prompted to enter a password.

Test mysql by typing ‘mysql -u yourusername -p’

Enter your password when prompted. If you get a mysql prompt you’re done!

As you can see, without testing this process is complete in less than 12 steps and it is free. I began my career on working at a Windows shop and I was amazed at the speed and ease of using a command prompt once I learned a few simple concepts.

I recently began migrating my own websites from a typical managed hosting service to the Rackspace Cloud in order to save money on hosting. I was surprised to discover unparalleled customer service, efficient administrative interface and a completely reliable, fast server. As a result I have decided I am going to use the cloud for my client’s needs whenever possible.

Before you start migrating all your sites, it is important to mention that a cloud server is no different from setting up a server in your own home or office (other than the location of the machine). You will need to administer every aspect of the machine, including security. Although Rackspace customer service is incredibly helpful, it is important to understand the fundamentals of server administration. I thought it would be fun to explain some of things I am learning along the way.

Everything I will share in this series I plan to tag as “Rackspace Recipes” will be based on my own experiences setting up and running LAMP on an Ubuntu Linux server. I’d like to point out they offer a variety of choices which might be better suited for your own specific needs.

Today we’ll take a real quick look at how easy it is to set up a new Ubuntu Linux server in the Rackspace cloud. It couldn’t possibly be any easier:

This week we’ll take a look at manipulating files and folders in PHP by creating an upload form component. Our example will apply PHP filesystem and directory functions and is 100% functional. Feel free to use it on your own project or modify as you see fit. The files are located here.(more…)

Logically, most designers want to pack their template with lots of cool features in order to makes them more marketable. My idea is to give you something really basic and let you take it from there. (more…)

In this article we’ll explore using PHP to calculate whether a given number is prime and then calculate & display all the primes between 0 and that number. For those who slept through math (like me) a prime number is a natural number only divisible by 1 and itself. This problem is excellent for computers because the easiest solution is to check every number between 2 and the number in question. The resulting program is a great example to demonstrate how to use recursive loops and build an array. (more…)

Yesterday, after wrapping up the piece on calculating the Fibonacci sequence I wasn’t happy about the long vertical presentation. It was a missed opportunity to talk about a cool trick someone taught me years ago for generating tables with a variable number of columns using the modulus operator. (more…)