Git Grep and Open File

Git grep is a search command built around the Git ls-files command.

git ls-files | grep -v -f ignore.txt | xargs grep -n

The command line takes all the files checked into version control, strips out the unwanted files, then searches the remaining for a text string or regular expression.

The result is a list of matching lines with their filename and line numbers.

I wrote an Emacs command called slf-git-grep to run it. You select some text then press a key (ctrl+space) to find the selected text in all your source files. It opens a buffer for the results and the matching text is colored red.

This allows you to navigate your source with just a few keystrokes.

If there is no selection, it prompts you for the search string (or regular expression).

It works with multiple repositories on the same machine. Each one has its own results buffer that’s appended to.

The Git root folder is found mostly automatically by searching relative to the current file. If it cannot find it that way, it uses the Git root found last. If it still isn’t found, you are prompt for it.

You may have source checked in that you don’t want to look at. For example third party libs. You can exclude these files using ignore.txt.
The grep command looks for the ignore.txt file in the Git root directory and if not found it looks in your home folder.

The results buffer shows the relative filename and line number. This allows you to go to the found line with one keystoke (ctrl+o). That’s done using another command I wrote called slf-open-file-under-cursor.

slf-open-file-under-cursor is an emacs command which opens the file under the cursor and goes to the specified line number.

The command parses the current line to extract the filename and line number. Then it opens the file and goes to the line.

The command supports common file/line formats generated by grep, a couple stack traces and logging.

Filename is either a full path or a filename relative to the current directory.

Download from github at:

https://github.com/flenniken

Send Email using Python and 1and1

The code you use to send email depends on whether the code is running on 1and1.com or on an external machine.

If you are on an external machine like your desktop, you use an SMTP script to send through your 1and1 email account. The following script called sendmail.py sends an email with python.

#!/usr/bin/python
import smtplib
from email.mime.text import MIMEText
me = "steve@example.com"
you = "sam@comcast.net"
password = "mypassword"
msg = MIMEText("This is a test message body.")
msg['Subject'] = 'Test message'
msg['From'] = me
msg['To'] = you
session = smtplib.SMTP("smtp.1and1.com", 587)
session.login(me, password)
session.sendmail(me, you, msg.as_string())
session.quit()

Run it like this: python sendmail.py

On 1and1 you need a mailbox type email. These types of emails have a password that you use in the script. It is easy to create a mailbox, if you don’t have one, by by logging into 1and1 and using their web interface.

If you copy this script to your web space on 1and1 and run it there, it will fail. 1and1 does not allow SMTP within 1and1. To send an email when running on 1and1 use this script:

#!/usr/bin/python
import os
mail_to = "sam@comcast.net"
mail_from = "steve@example.com"
subject = "test message"
header = """From: {0}
To: {1}
Subject: {2}
""".format(mail_from, mail_to, subject)
msg = header + "a test from me"
sendmail = os.popen("/usr/lib/sendmail -t", "w")
sendmail.write(msg)
sendmail.close()

Just open sendmail and write to it!

Firefox backspace

On Ubuntu Firefox the backspace key it does nothing by default.  You can change a setting to make it go to the previous page. Filefox has a bunch of settings you can access by typing about:config in the address bar. By changing browser.backspace_action from 2 to 0, it does the trick.

When you type about:config in the address bar you get an interesting warning dialog.

After you promise to be careful, type browser.backspace_action into the search box. Then change the 2 to a 0.

XCAPE

I’ve configured my keyboard to generate a special key code when you press the Caps Lock key by itself. I use this as a mode switch in Emacs which I have configured somewhat like VIM.

For VIM users the escape key is used to switch between typing and command mode and escape is pressed all the time.

The problem is that it is a long reach to hit the escape key. The Caps Lock key is in a prime location and who needs the Caps Lock key anyway? (You can move it if you want.)

On Ubuntu I use the program xcape to accomplish this remapping. I will show you how to download, install, configure and test xcape.

Note:
On the Mac you can use KeyRemap4MacBook and PCKeyboardHack to do the same thing.

Here is the link to xcape: https://github.com/alols/xcape#readme

First install the necessary dependencies. It requires git, gcc, make libx11-dev and libxtst-dev libraries. Open a terminal and type:

sudo apt-get install git gcc make libx11-dev libxtst-dev

Next make a folder for xcape in your home folder:

cd
mkdir xcape
cd xcape

Download the source code for xcape:

git clone https://github.com/alols/xcape.git .

Build the application. This makes a executable called xcape.

make

ls
LICENSE Makefile README.md xcape xcape.c

To see the usage statement:

./xcape -h
./xcape: invalid option — ‘h’
Usage: ./xcape [-d] [-t timeout_ms] [-e <mapping>]
Runs as a daemon unless -d flag is set

I am using the Ubuntu system settings to turn the Caps Lock into a control key and xcape to generate Alt+R when it (now a control key) is pressed by itself.

Use the system settings to make Caps Lock a control key:

  • Open system settings Keyboard Layout
  • Click Options
  • Click “Ctrl key position”
  • Check “Caps Lock as Ctrl”
  • Close the dialogs

If you are a VIM user and you want Caps Lock by itself to generate an escape, use the defaults and run xcape like:

./xcape

I want the left control to generate Alt_L+R when pressed on its own, so I run xcape like:

./xcape -e ‘Control_L=Alt_L|R’

You can remap multiple keys at once using the semicolon to separate commands:

xcape -e ‘Shift_L=Escape;Control_L=Control_L|O’

The list of key names is found in the header file X11/keysymdef.h (remove the XK_ prefix). Here is a link to the file:

http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h

Run xev to test the keycodes generated when you type a key.

xev

For my case the system generates a Control_L press and release then the Alt_L+R press and release combination.

Note:
If you change the keyboard system settings, rerun xcape or it will continue to run with the old settings.

Note:
Make sure you only run one xcape process. To see the xcape process or processes:

ps aux | grep xcape
steve 13342 0.0 0.0 11984 688 ? Ssl 09:25 0:00 ./xcape
steve 13467 0.0 0.0 11984 684 ? Ssl 09:44 0:00 ./xcape
steve 13564 0.0 0.0 11984 688 ? Ssl 10:01 0:00 ./xcape -e Control_L Alt_L R

Quit the extra running xcape processes above:

kill 13342
kill 13467

To make xcape run once when you login, add the xcape to your .bashrc file,

emacs ~/.bashrc

add this line to the bottom of the file:

# Generate a Alt+R when the control key is pressed and released by itself.
# Run xcape once.
if [ -z $XCAPE ] ; then
export XCAPE=1
~/xcape/xcape -e ‘Control_L=Alt_L|R’
fi

Number of Open Files Ubuntu

On Linux you are limited to the number of files you can have open at one time. This note tells how to determine the number of open files on Ubuntu and how to increase the limit.

To determine how many open files a process has, figure out the process id then run the lsof command.

To figure out the process id use the ps command, for example:
ps aux

Since there is so much output, it is often useful to grep for the process you are interested in, for example to find the tomcat process:

ps aux | grep tomcat
steve 21405 0.0 3.3 428148 69060 ? Sl 10:07 0:00 /usr/lib/jvm/java-6-sun/bin/java …

Here the process id is 21405.

Once you have the process id, you can see the open files using the lsof command. For example:

lsof -p 21405
”COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 21405 steve cwd DIR 8,1 4096 407944 /home/steve/apache”-tomcat-6.0.26/bin
java 21405 steve rtd DIR 8,1 4096 2 /
java 21405 steve txt REG 8,1 47308 400238 /usr/lib/jvm/java-6-sun-1.6.0.20/jre/bin/java”

To determine the number of open files, count the number of lines output by the lsof command, for example:
lsof -p 21405 | wc -l
119

An alternate way to see the open files.
ll /proc/21405/fd

To see the list sorted by filename where the names are in numerical sequence:
ll /proc/21405/fd | sort -g +7 -7

To sort by the Name column:
lsof -p 24226 | sort +8 -8 >~/tmp/open.txt

The FD column is the File Descriptor column. It is either the number of the file or one of the following:

  • cwd current working directory
  • Lnn library references (AIX)
  • err FD information error (see NAME column)
  • jld jail directory (FreeBSD)
  • ltx shared library text (code and data)
  • Mxx hex memory-mapped type number xx
  • m86 DOS Merge mapped file
  • mem memory-mapped file
  • mmap memory-mapped device
  • pd parent directory
  • rtd root directory
  • tr kernel trace file (OpenBSD)
  • txt program text (code and data)
  • v86 VP/ix mapped file

 

Determine the Limit

 

Each user has a limit for the number of open files. This limit applies to each process run by the user. For example say the limit is 1024 and the user has three processes running, each process can open 1024 files for a total of 3072.

To determine the soft limit:
ulimit -Sn
1024

To determine the hard limit:
ulimit -Hn
2048

ulimit -n shows you the soft limit. The soft limit is the limit applied for opening files. The hard limit is the limit you can increase the soft limit to.

 

Increase the Limit

 

To increase the limit to 1080 use the following command:

ulimit -Sn 1080

You can change the hard limit too, ulimit -Hn 2040. ulimit -n 2040 changes both the soft and hard limits to the same value. Once you change the hard limit, you cannot increase it above the value you just set without rebooting.

If you try to set the soft limit above the hard limit you get the following message:
ulimit -Sn 3000
bash: ulimit: open files: cannot modify limit: Invalid argument

Note: Once you reboot the limit is reset.

You cannot determine the limit of the root user using ulimit. For example:

sudo ulimit -n
sudo: ulimit: command not found

To make the limits bigger and to make the change permanent, edit your configuration file and reboot. On Ubuntu you edit the following file:

sudo nano /etc/security/limits.conf

Add lines like these:

steve soft nofile 4000
steve hard nofile 5000

You can use * in the limit.conf file instead of a user name to specify all users, however this does not apply to the root!

  • soft nofile 20000
  • hard nofile 30000

The limit.conf file is applied during the boot process. If you start a process during the boot process before the limits are applied, you will get the default 1024 value. You can record the starting limit in a file right before starting your process, then check the value to make sure it’s the expected value.

ulimit -n >mylimit.txt

You cannot start a process late enough in the boot process! For example: “sudo update-rc.d tomcat defaults 99 01” is at the end and it is still too late.

The work around is to force the limit to be set before starting the process. Put “ulimit -n 4000” before starting your process, then the limit.conf file is processed here.

 

Testing the Limit

 

I wrote a program called openmany that I use to test the open file limit. It creates a bunch of files in a folder then opens them.

java -jar openmany

Usage: openmany [-c] number
c Continue to run holding on to the open files.
number The number of files to open.

java -jar openmany 100
Creating 100 files in folder openmany.
Opening the files.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

To remove the directory of files created by the program:

rm -r openmany/

When setting the limit at 60,000, the system ran out of memory at about 30,000. So the effective limit is dependent on the java memory size allocated to the program.

Here is an example of trying to open more than the limit:
ulimit -n
1024
java -jar openmany.jar 1050

1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 Exception in thread “main” java.io. FileNotFoundException: openmany/1019.txt (Too many open files)

at java.io. FileInputStream.open (Native Method)
at java.io. FileInputStream.<init> (FileInputStream.java:106)
at java.io. FileReader.<init> (FileReader.java:55)
at openmany.Main.main (Main.java:49)

You can run the program as root and test its limits too:

sudo java -jar openmany.jar 1050

 

Set System Wide Limits

 

There is another file limit in the system, the total number of files that can be opened by all processes.

To see the file max value:
sysctl -a | grep fs.file-max
fs.file-max = 170469

Since it is so big there is no reason to change it.

 

References

 

Documentation for lsof:

http://man-wiki.net / index.php / 8:lsof%23SYNOPSIS

Changing the limit:

http://stackoverflow.com / questions / 34588 / how-do-i- change-the- number-of-open- files- limit- in-linux

http://www.cyberciti.biz / faq / linux-increase- the-maximum- number-of- open- files/

I love you too!

Wow, I’m getting lots of blog comments! I didn’t realize how much I touched you with my posts. You really like me!

“I have simply found your site and revel in each article. We admire your own expertise.”

I’m so happy. You “revel in each article” and admire my expertise!

“Appreciate it for the superb writeup. Anyhow, exactly how could we talk?”

You want to connect up too?

“We recently came all through your post and therefore are currently examining together. We need to communicate my admiration of the crafting ability as well as capability to help to make target audience study through the use of the starting to the finish. I would like to research more recent articles and to talk about my personal suggestions with you.”

You want to personally tell me how much you admire my writing skill? Oh, and you have some suggestions to make my articles better? Tell me more.

“Its like you read my mind! You appear to understand a lot about this, like you authored the e book in it or something. I believe that you can perform with some pics to drive the message home a little bit, but other than that, this is great blog. an awesome read. I will certainly be back..”

So you are thinking about Java JNI and Emacs too! Yes I know, a few pictures would make the posts more interesting. I’m glad you will be visiting my site often.

“Awesome web site you have right here however i had been interested in should you understood of any discussion boards that cover the same topics talked about in this article? Id really like to be a part of network where I’m able to get responses using their company experienced people who reveal the same curiosity. If you have any kind of recommendations, make sure you let me know. Cheers!”

You love me! I’m sorry I cannot recommend any company men with the same curiosity about Java programming. But if I do find them I’m sure to let you know.

“grey Ugg Boots For Men You actually make it seem so easy with your presentation but I find this topic to be really something that I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I will try to get the hang of it! Kenly Uggs on sale”

I know it complicated determining the best direction to take. Both Java JNI and native applications have their benefits. I’m happy you’re hanging in there. Oh, you’re interested in boots?

“The post is absolutely fantastic! Lots of great information and inspiration, both of which we all need! Also like to admire the time and effort you put into your blog and detailed information you offer! I will bookmark your site!”

So you really like the post about my Apple ID problem. It is fantastic! You’re bookmarking my site, the ultimate compliment!

“i discovered your website on reddit as well as thought i’d can be found in and have a appear. fascinating concept you have nevertheless i will possess a number of other folks y you’ve got an interest. they can assist or maybe might not however its well worth a chance.”

I wonder who all my fans are and how can I find out more about them? Oh, I see they provided an email and a website link. I wonder whether I can find out more by following the links…

“I really wish I hadn’t seen this as I really want one now!”

dance wear, urban wear, http://www.partywears…
Luckner @ aol.com

What do you want?  Lets see … party wear …

“My brother recommended I would possibly like this web site.
He used to be entirely right. This post truly made my day. You can not consider just how a lot time I had spent for this information! Thanks!”

http://ereaderplanet.co.za/ kindle-south-africa/ kindle-ebook…
NelomsScianna335 @ aol.com

I’m excited to hear that you are talking over my posts with your brother! I’m thrilled that my post about WordPress on 1and1 made your day. Wow, South Africa fan. It really is the World Wide Web!

“Great issues altogether, you just received a new reader. What could you suggest about your put up that you simply made a few days in the past? Any positive?”

MccarronLongnecker45 @ gnumail.com
http://ereaderplanet.co.za/ kindle-south-africa/ the-kindle-reader-and…

Keep the comments coming about my put ups.  I love you too!

Load Emacs Documentation on your Kindle

There is a lot of free content you can load onto your Kindle. It just a matter of converting to the right format for your Kindle. It is a great device for reading manuals. I’ve loaded my Kindle with all the Python documentation as well as the emacs documentation. Here I show how to load the emacs manual. You can use the same methods for others.

These steps can be done on the Windows and Macintosh platforms as well as Ubuntu. Here are the steps in detail for Ubuntu.

Configuration:

  • Kindle 2, Model D00511
  • Ubunutu 10.04 LTS

Download Emacs Single Page Document

Emacs provides a single page HTML file of all the documentation. Download this page to your machine.

cd ~/tmp

wget http://www.gnu.org/ software/ emacs/ manual/ html_mono/ emacs.html

You can see the file in the tmp folder.

ll -h
-rw-r–r– 1 steve steve 3.3M 2011-09-25 11:55 emacs.html

Note: Python documentation comes in a zip file of many HTML files. From all these files you can create an ebook for your Kindle. Just point the converter at the content.html file.

Install calibre

You use calibre to convert the html file to a book (mobi file). If you don’t have calibre, you can install it with:

sudo apt-get install calibre

Here is the current version:

ebook-convert –version
ebook-convert (calibre 0.8.20)
Created by: Kovid Goyal <kovid@kovidgoyal.net>

Note: There are many options you can specify when converting from html to mobi. The options are listed here:
http://manual.calibre-ebook.com/cli/ebook-convert-3.html#html-input-to-mobi-output

Convert HTML to Mobi

If you use the defaults for conversion, the index at the beginning of the book is one big table that runs for many pages. You cannot select any of the links so it is pretty useless. To fix this, specify linearize-tables option and the table will be converted to regular text.

Convert the emacs.html file into a mobi file and turn the tables into regular text. It takes a few minutes to convert:

ebook-convert emacs.html emacs.mobi –linearize-tables –title “The Emacs Editor” –authors gnu.org –comments “The Emacs Editor Kindle book generated from gnu.org single page HTML file.”
 

You can see the file created:

ll -h
total 4.8M
-rw-r–r– 1 steve steve 3.3M 2011-09-25 11:55 emacs.html
-rw-r–r– 1 steve steve 1.5M 2011-09-25 13:20 emacs.mobi

Copy to Kindle

Copy the book to your Kindle. Plug it into the USB port then:

cp emacs.mobi /media/Kindle/documents/
eject Kindle

The content page generated by calibre is at the end of the document. The book is called “The Emacs Editor”

Now you can store the manual under your pillow.

“Apple ID not used with iTunes Store”

When trying to use the App Store to buy the Lion OS upgrade for my new Mac I got this message:

This Apple ID has not yet been used with the iTunes Store. Please review your account information.
Cancel       Review

I just got my Apple ID so I could buy Lion, of course it hasn’t been used with iTunes. I verified my email and account information. What’s this all about?

I can log in to my id at https://appleid.apple.com without problems. I was able to use the id to log into Apple’s support forum. So at some level the id is working.

When clicking on the Review button it talks about checking cookies and checking the computer date/time but nothing that is relevant for my situation.

I launched the iTunes application and somehow entered my credit card associated with my Apple ID. Then I downloaded a free talk from Stanford just to see that things were working.

Trying iTune again and I cannot sign in to my account. I get the same old error message.

How do I get my Apple ID to work for buying things?

Searching with Goggle finds millions of people with the same error message but no solution for this case. There was no response in the support forum either.

Evenually I figured out a solution.

Solution

If your new apple id doesn’t work, create a new one and do it using iTunes.

Java Calling Native Code

JNI vers Executing Processes

In a Java environment you sometimes need to call native code written in C++ or C.  You can do this in two ways, using the Java Native Interface JNI/JNA, or by executing native stand alone applications.

When you use JNI, the native code runs in the same process as the calling Java code.

When you execute a stand alone application, the application runs as a separate process.

The advantages of using JNI are:

  • Its potentially faster since there is no process switch.
  • Error handling is easy. You can use exception handling in the JNI code to return Java exceptions.
  • It’s easy to call JNI code since you call the JNI code just like a normal Java method.
  • You can share memory between the JNI code and the Java code (potentially faster processing).

The advantages to executing system processes are:

  • Crash protection, the code is isolated through a process boundary.  If the process crashes, you can catch it in Java and continue.
  • You can run the code outside the Java environment easily and develop it independent of Java.

The disadvantages of using JNI are:

  • A crash in JNI code will bring down the Java VM.
  • It’s hard to setup, you must create binding code between Java and JNI.  (Java Native Access (JNA) makes this easier.)
  • Hard to run JNI code outside of Java.

The disadvantages of executing processes are:

  • Starting a process is hard, you must write platform dependent code in Java to start the process.
  • It’s is clumsy to call, you must pass command line arguments, environment variables. and a starting directory.
  • Loading of shared libraries is a hard platform dependent problem.
  • Error handling is convoluted, you get one int return value, or you must parse standard error or standard out.
  • You cannot share memory between the Java code and the JNI code.

You may argue that you can protect the JNI code using C++ exception handling but this is not the case.  Below is an example crasher that is not caught.

int crasher()
{
    try
    {
        int *ptr = 0;
        *ptr = 1234;
    }
    catch (...)
    {
        // never gets here
        printf("caught exception");
    }
    return 0;
}

Why doesn’t this work? If this was an option, crashing native code could be protected. It seems like an issue with the Java VM.  Here is a note I found under the JNA documentation:

“Set whether native memory accesses are protected from invalid accesses. This should only be set true when testing or debugging, and should not be considered reliable or robust for applications where JNA native calls are occurring on multiple threads. Protected mode will be automatically set if the system property jna.protected has a value of “true” when the JNA library is first loaded.
If not supported by the underlying platform, this setting will have no effect.”

For the project I was working on the crash protection issue overrode all others.  With our limited testing resources and the complexity of our JNI code, we did not want to take the risk of a crashing bug in the native code bring Java down.  So we switched from JNI to native command line applications.

If you have the resources to test and make your native code stable, JNI is the better approach.  Calling system DLLs with JNA is the best approach for calling stable system features not already in the Java API.  Otherwise consider writing your native code as stand alone command line applications and executing the code in a separate process.

Install WordPress on 1and1

I just set up WordPress and I figured my first post would be about installing it on 1and1.

WordPress blogging software is used by 15% of the top million websites, up about 6% this year! WordPress is free open source software and it has an active community of developers. You can select from hundreds of pre-made templates and selecting one for your site only takes a couple of clicks.

1and1 is a popular and cheap web hosting service. A basic plan is only $5.00 a month.

These instructions were tested on a local Ubuntu 10.4 system installing on 1and1 basic plan with Linux hosting. Similar steps apply if you are running a local Windows system. You can use the same steps for 1and1 advanced and business plans, or there are alternate steps, see below. If you have the Windows based package, 1and1 provides a way for you to switch.

Basically to install WordPress you download WordPress to your system, create a database on 1and1, edit one configuration file, then upload all the files to 1and1. Here are the details.

Download WordPress

The latest WordPress comes as a zip file from wordpress.org. To download WordPress open a terminal window and type the following:

cd
cd tmp
wget http://wordpress.org/latest.zip

Now unzip the file. It will create a folder called wordpress inside your tmp folder. Then delete the zip file to save space.

unzip latest.zip
rm latest.zip

Now rename the wordpress folder to “blog” (or whatever you want) and rename the wp-config-sample.php file to wp-config.php. The name you choose is the name that users will use to get to your blog. If you use “blog” for example, the url will be http://sample.com/blog/.

mv wordpress blog
cd blog
mv wp-config-sample.php wp-config.php

Find your 1and1 domain name and user name

Your domain name and user name are needed to copy files to 1and1.  To find out what they are follow these steps:

  • In your browser go to http://1and1.com/
  • Click on Customer Login (near the top right of the page) and enter your credentials.
  • Click on your package.
  • Find your .us domain name. It will be near the top and it looks something like: s123456789. onlinehome.us

Note: I could not figure out how to select the domain name for copy and paste. So instead, I selected everything on the page with Ctrl+A, then pasted that into a text editor. There I could select the domain name.

While you are still logged into 1and1 find your user name and set up a password for it.

  • Click on Domains & Web Space.
  • Click on FTP Account.
  • Find your user name. It will look something like: u12345678.
  • Edit the entry and add a password, if not already done.

Note: Don’t add a password if you share the account with someone else and it has already has been set up, because they will no longer be able to ftp. Instead ask the other user for the ftp password.

Note: The password for SSH and the password for FTP are identical. If you change one, it changes the other.  The password to log into your 1and1.com account is different than the SSH and FTP one.

Create WordPress Database

While you are still connected to 1and1 create the database for WordPress. Write down the database information for use when editing wp-config.php later. Here are the steps:

  • Click on MySQL Database Set Up and Configuration.
  • Click on New Database .
  • Write down the database name, host name, user name and database password. They should look similar to:
  1. db123456789 — database name
  2. db123456789.db. 1and1.com — host name
  3. dbo123456789 — user name
  4. mydbpassword – database password

You are done with the 1and1 web interface.

Edit wp-config.php

Edit wp-config.php using your favorite text editor changing the database name, user name, remote host and database password to the names you just wrote down in the last step. Also change the salt values to unique values.

gedit wp-config.php

The lines should look something like this:

define(‘DB_NAME’, ‘db123456789’);
define(‘DB_USER’, ‘dbo123456789’);
define(‘DB_PASSWORD’, ‘mydbpassword’);
define(‘DB_HOST’, ‘db123456789.db. 1and1.com’);

For the salt values change the strings “put your unique phrase here” to something else.

define(‘AUTH_KEY’, ‘12345 zzxcv asdf qwerty zxcv’);
define(‘SECURE_AUTH_KEY’, ‘put 1234 unique phrase 1235’);

Upload Files to 1and1

Now all the files are configured and ready to upload to 1and1.

The 1and1 basic plan supports sftp but not ssh or scp. Using the command line with sftp is too tedious. Instead upload the blog folder to 1and1 using Filezilla. Filezilla is a free GUI based program for ftp. For Windows go to http://filezilla-project.org/ and download the Filezilla client, for Ubuntu, Filezilla can be downloaded and installed with:

 sudo apt-get install filezilla

To run Filezilla type:

filezilla

Once Filezilla is running enter the connection information to your 1and1 account. Select the menu File > Site Manager and enter the following information:

  • Host (domain name) = s123456789.onlinehome.us
  • Server type = SFTP
  • Logon type = Normal
  • User = u12345678
  • FTP Password = myftppassword
  • Comments = this is my account on 1and1

Then press the Connect button.

While still in Filezilla, transfer the blog folder to your account by following these steps:

  1. In the left local site window select the folder to transfer from your local machine, ~/tmp//blog.
  2. In the right Remote site window select the destination,  /.
  3. Right click the source folder and select upload. The files will be uploaded.

Almost done. Run the Install Script by switching to your browser and entering the address to the install script, something like this:

http://sample.com/blog/wp-admin/install.php

Write down your WordPress password.

Now WordPress is installed!

Visit your blog at the URL:

http://sample.com/blog/

Alternate Steps for Advance and Business Packages

The 1and1 advanced and business packages support ssh which makes installing a little easier (but the basic steps work too).

Instead of downloading to your local machine, configuring then uploading, you login to 1and1 using ssh, download directly to your 1and1 account, then configure in place, no need to upload.

To start, open a terminal window and log into your 1and1 account. If you run Windows locally, you need to set up Putty first. Get your user name and host names by logging into 1and1 as noted above under Find your 1and1 domain name and user name.

ssh u12345678@ s123456789.onlinehome.us

Download the latest version of WordPress to your 1and1 account and unzip it. This will create the folder called wordpress with all the files inside it. Then delete the unneeded zip file.

wget http://wordpress.org/latest.zip
unzip latest.zip
rm latest.zip

Rename the wordpress folder to “blog” (or whatever you want) and rename the wp-config-sample.php file to wp-config.php.

mv wordpress blog
cd blog
mv wp-config-sample.php wp-config.php

Log into your main 1and1.com account and create a database. Follow the same steps as above under Create WordPress Database.

Switch back to the terminal window and edit wp-config.php changing the database name, user name, remote host and database password to the names you just wrote down in the last step.

nano wp-config.php

Run the Install Script by switching to your browser and entering the address to the install script, something like this:

http://sample.com/blog/wp-admin/install.php

Write down your WordPress password.

Now WordPress is installed!

Visit your blog at the URL:

http://sample.com/blog/