Preparing to install WordPress from shell in linux

 by jakedimare- May 26, 2012

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.

The entire exchange looks like this:

user@Poseidon:~$ sudo mysql -u root -p
[sudo] password for user:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37855

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input s

mysql>

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

  1. Create a new database
  2. Create a new user with rights to the database

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

CREATE DATABASE newdatabase;

For instructions on how to create the new user with rights to the database, please reference our previous post on this topic:
ADDING DATABASE USERS TO AN EXISTING MYSQL DATABASE

The next step is to download and unzip a fresh copy of the WordPress code base. In order to do this we will first create a folder for the new site on the server and then download the files:

cd /var/www/
mkdir newdirectory
cd new directory
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

The WordPress package will extract into a folder called wordpress in the same directory that you downloaded latest.tar.gz.

Adding database users to an existing MYSQL database

 by jakedimare- February 10, 2012

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.

The entire exchange looks like this:

user@Poseidon:~$ sudo mysql -u root -p
[sudo] password for user:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37855

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input s

mysql>

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

  1. Create a new user
  2. 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: 

  1. In order to confirm the correct spelling of the database name use the command SHOW DATABASES;
  2. 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.

 

How to Configure Apache2 to Allow Drupal to Rewrite Paths

 by jakedimare- September 10, 2011

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:

CD /etc/apache2/sites-available (enter)
sudo nano yoursitename (enter)

Once you’ve opened the specific site configuration file add the following:

<Directory /var/www/example>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-fsu
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

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:

<Directory /var/www/example>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>

Launching a fresh Drupal Installation on Linux with Drush

 by jakedimare- March 8, 2011

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.

  1. Navigate to the root web folder by typing: ‘cd /var/www’
  2. Download the latest version of Drupal by typing: ‘drush dl drupal’
  3. Rename the Drupal folder by typing: ‘mv drupal-XXXX newsitename’
  4. Type ‘cd newsitename’ and open permissions for installation with ‘chmod -R 777 . ‘
  5. Create a database in mysql with the name of the site
  6. Update sites/default/settings.php with the correct connection string
  7. Run the install.php file
  8. Change permissions back to 755

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:

drush dl cck views views_slideshow ctools views_bonus adminrole advanced_help panels admin_menu jquery_update pathauto print nodewords page_title globalredirect path_redirect taxonomy_manager node_import menu_block custom_breadcrumbs ckeditor filefield imageapi imagecache imagefield lightbox2 emfield messaging token webform google_analytics service_links date calendar devel backup_migrate jquery_ui nodequeue context context_reaction_theme views_arg_context cmf content_taxonomy menutrails image

The trick here is to be within the folder containing the site you want these modules to populate.

Installing LAMP on an Ubuntu Server

 by Jake DiMare- February 1, 2011

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:

  1. Type ‘sudo apt-get install apache2′ (yes, it will download and install the package)
  2. Type ‘y’ when prompted
  3. Test Apache by opening a web browser and entering the IP address of your machine.
  4. Type ‘sudo apt-get install php5 libapache2-mod-php5′
  5. Type ‘y’ when prompted
  6. Type ‘sudo /etc/init.d/apache2 restart’
  7. 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.
  8. Open a browser and navigate to http://yourserverip/testphp.php. If you see the PHP diagnostic page you’ve successfully installed PHP.
  9. Type ‘sudo apt-get install mysql-server’
  10. During the install you’ll be prompted to enter a password.
  11. Test mysql by typing ‘mysql -u yourusername -p’
  12. 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.

Floating in the Rackspace Cloud

 by Jake DiMare- February 1, 2011

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:

  1. Set up a new account with Rackspace Cloud
  2. Login
  3. Click Hosting
  4. Click Cloud Servers
  5. Click Add Server
  6. On the first tab you will see options for Linux servers. I use Ubuntu 9.1
  7. Give your server a name
  8. Select a server size. It’s OK not to be perfect here because you can adjust it on the fly later. I started with 256 but 512 is probably the minimum size for a server running multiple Drupal web sites.
  9. Click Create Server

That’s it! You now have a Linux server. In our next Rackspace Recipe we’ll explore installing the LAMP environment.

Uploading files using PHP and HTML

 by Jake DiMare- September 9, 2010

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…)

Super Clean Base WordPress Template

 by Jake DiMare- September 2, 2010

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…)

Basic use of recursion, arrays and loops

 by Jake DiMare- August 25, 2010

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…)

Using Modulus to Build Dynamic Tables in PHP

 by Jake DiMare- August 19, 2010

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…)

Related Posts Plugin for WordPress, Blogger...
Older Posts »