In this how-to article, I discuss running WordPress on a USB stick.
In a previous article, I talked about using USBWebserver as an alternative to XAMPP and WAMP. I found that the speed and small memory footprint makes it a great choice for local intranet web applications.
Lets get our hands dirty and apply USBWebserver to a practical use case. I assume that you have successfully installed USBWebServer and are ready to go.
Suppose you go to college and take notes while you listen to your teacher’s lecture. Instead of scribbling everything into a notepad, what if you could install USBWebserver and WordPress onto a USB flash drive and put it in your laptop? Does that sound useful? You bet!
Preliminaries
Before we install WordPress, we must make a few changes in our USBWebserver configuration.
Lets make life easier and use the default HTTP port of 80. Go to the UsbWebserver application and click on Settings. Then, change the Apache port from 8080 to 80.
Now, we need to create a MySQL database for our WordPress installation. We can use phpMyAdmin for this. Click on the phpMyAdmin button on the UsbWebserver menu.
Login with the default settings:
username: root password: usbw
After logging in, click the Users button and the Add user link. For our database administrator, lets setup the following:
Username: dbadmin Host: localhost Password: password
Next, click on the Global privileges “Check All” link so that all the check boxes are set. Finally, click the Go button.
Now that we have a MySQL database administrator created, lets create the database! Click on the Databases button. Then, enter in the following and click the Create button:
Database name: wordpress Collation: utf8_general_ci
Congrats! You now have a MySQL database!
Go download the current version of WordPress. Then, take the compressed ZIP file and copy it over to the USB drive into the /root directory. Extract the file. What should happen is a /root/wordpress folder is created along with all the files. Your folder layout on the USB drive should look like this:
/ usbwebserver wordpress-4.5.3 /apache2 /lang /MySQL /php /phpmyadmin /root /wordpress /settings
Delete the WordPress zip file (in this case, wordpress-4.5.3.zip) to save disk space. Now simply type:
http://localhost/wordpress
The WordPress pre-installer will now appear for you to walk through.
Choose the English language (or whatever is appropriate). Then, enter in the following:
Database Name: wordpress Username: dbadmin Password: password Database Host: localhost Table Prefix: wp_
If WordPress can connect to your Mysql database, you can proceed to run the installer.
Setting Up WordPress
Since you are running on Microsoft Windows, you need to go and make a change to the HOSTS file to set localhost to your internal website. Go to /windows/system32/drivers/etc/hosts and open it up with Notepad under Adminstrator mode.
Change it to look like this:
127.0.0.1 localhost iyoursite.com www.iyoursite.com
Preface the website name with a lower case “i” to mean that it is an internal website just so that you don’t confuse it with the public website.
Next, we need to setup Apache virtual hosting. What this allows us to do is create a domain on our USBWebserver. With your text editor, open up /settings/httpd.conf and add the following to the end of the file:
ServerAdmin localhost DocumentRoot "{rootdir}" ServerName localhost
This next virtual host rule should only be used if you have access to the Windows computer as an administrator. If you are on a laptop or desktop computer that you own, go for it. However, if for example, you are trying to use your USB stick on a public library system, this will not work. The reason is because you need access to the Windows HOSTS file.
ServerAdmin admin@iyoursite.com DocumentRoot "{rootdir}/wordpress" ServerName www.iyoursite.com ServerAlias iyoursite.com
Backup the /root/index.php file and rename it to /root/indexold.php.
Copy (not move) the index.php and .htaccess files in the /root/wordpress directory to /root.
Edit /root/index.php to look like this:
require('./wordpress/wp-blog-header.php' );
Now login to WordPress via http://iyoursite.com/wp-login.php. Head to the Settings | General menu and change the following:
Wordpress address URL: http://iyoursite.com/wordpress Site Address URL: http://iyoursite.com
You should be now good to go. I would suggest that you read my other article entitled Things To Do After Installing WordPress to further customize your installation.
Miscellaneous
If you find that your localhost web server is very slow, make sure of the following:
– You have the HOSTS file localhost setting correct
– You have disabled VirtualBox as an Ethernet device in your Network Connections
– You do not have any other HTTP server running including IIS