Tested News

How To Run a Local Web Server to Host Web Apps

Not all web apps need to be run online. In fact, it makes sense to run some services locally on your own machine.

Hosting is expensive. So is registering a domain name and renewing it every year — especially for a personal blog or wiki you might not use all that often. So why not host it yourself? It's not as crazy as it sounds.

Of course, we don't actually recommend you host your collaborative Star Trek wiki or trendy food blog on your own machine. What we're referring to are web applications that are just as useful when run locally as they are online. For example, some people maintain personal Wikis for storing notes and private information. Or consider ThinkUp, an app that archives all of your Twitter and Facebook posts, and generates statistics and trends with the results. You could buy a hosting plan and install each of these services online — or you could run them locally, free of charge. You'll get the same results, not to mention the added peace of mind that your personal data is safe, secure and only accessible by you.

Today, we'll focus on installing the aforementioned ThinkUp, one of many legitimate reasons for running online apps and services on your own machine with a local web server. Let's get started!

Getting started with XAMPP

We need two services in particular: mySQL and PHP. The former is a database management system used by most online services, and is responsible for storing everything from password data to user generated content. PHP on the other hand, stands for Hypertext Preprocessor, and is scripting language used to create dynamically generated webpages. This is just one of many methods websites such as Facebook use to serve constantly updated information at a single address, instead of creating static links or pages that must be individually updated.

For our purposes, we'll be using a cross-platform software suite called XAMPP (which stands for Apache, mySQL PHP and Perl). XAMPP will automatically install and configure all the software and services your computer requires for a working local web server. The installation process is similar for both Mac and PC (administrator privileges are required), although Windows users will have the added option of installing Apache, mySQL and PHP as services that launch at startup.

Once installation is complete, you can access the dashboard from your browser via http://localhost/ or http://127.0.0.1. Now click the Security option from the toolbar on the left. Here you can see that a number of services are currently unsecured, which means that other users on the network can technically gain access to the contents of your server (assuming they know your IP, and where to look, of course). In most cases, this is unlikely to be an issue; you probably won't be running XAMPP round-the-clock, or storing particularly sensitive information anyhow. However, if you want to make absolutely sure your server environment is safe, XAMPP provides a simple script to help lock everything down (if you'd rather take your chances, feel free to skip to the next section).

Windows users have it easy. Simply follow the instructions listed on the security page to set a new root username and password for your Apache server and MySQL database. OS X users, however, will need to open up a new session in Terminal and execute the following script:

sudo /Applications/XAMPP/xamppfiles/xampp security

But that's not all. XAMPP's mySQL database still needs to be secured. From the toolbar on the left, this time select phpMyAdmin. Here, you should see a label called "SQL" at the top of the page. Enter the following commands, while replacing 'password' with the password of your choice, (and remember to press 'go' when finished):

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;

Once you refresh the page, you'll notice that your access to the administration panel has now been denied.That's fine, however; while we've changed the password, phpMyAdmin just doesn't know it yet. To fix this, head back to Terminal and type the following (all one line, space after TextEdit):

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /Applications/XAMPP/xamppfiles/phpmyadmin/config.inc.php

Search for $cfg['Servers'][$i]['password'] = ‘password’; and replace the password after the equals sign with the value we entered in the myPHPadmin panel.

Installing ThinkUp

As previously mentioned, ThinkUp is a neat beta application from former Lifehacker Editor Gina Trapani that archives tweets and Facebook postings for later use. After all, neither service makes searching through and interpreting your online profile easy, something Trapani has sought out to do. After downloading the package from ThinkUp's website, extract it into your htdocs directory (found under /Applications/XAMPP/xamppfiles/), and point your browser at http://localhost/thinkup.

Here, Windows users will notice that not all of XAMPP's services are working correctly. According to ThinkUp, something called cURL has been disabled, and we'll need to reenable it for the application to work. Luckily, this is a simple task. Find your php.ini file in C:\xampp\php\ (or wherever your XAMPP directory is located), and remove the semi-colon before the following line: extension=php_curl.dll. Save, and refresh the ThinkUp page to continue.

OS X users, meanwhile, have a small problem of their own to deal with. Because XAMPP's htdocs folder has its own set of permissions, as you'll have to issue the following command in Terminal as root (all one line)l:

sudo chown -R nobody /Applications/XAMPP/xamppfiles/htdocs/thinkup/_lib/view/compiled_view/

This should allow installation to continue without issue. In the next step, you'll see that ThinkUp now requires some of the information we modified previously, including your root username, password and database host (localhost). Fill in each form accordingly, give ThinkUp a descriptive database name to store its stuff, and you're done.

Well, almost. Windows users will notice that XAMPP throws a an error at the top of the screen, indicating that the service's activation email failed to send. This is because the Windows and OS X packages have different mechanisms for sending outgoing mail. Instead of going through the complicated and tangential process of fixing for our XAMPP mail client, we'll simply make a small edit to activate ThinkUp ourselves.

  • Head back to the phpMyAdmin panel, and select the ThinkUp database on the lefthand side.
  • Click tu_owners on the lefthand side.
  • On the top of the page, select the Structure tab.
  • Click the pencil icon beside is_activated
  • Change the value beside Default from 0 to 1.

And that's it. Reload ThinkUp, and you can link your accounts as you see fit.

Configuring ThinkUp

Installation is the hard part, of course. Connecting your Facebook and Twitter accounts to the ThinkUp app is relatively easy by comparison. In both cases, you'll have to essentially "create" a Facebook/Twitter application, but only so you can acquire an API key for ThinkUp's crawler. The process is pretty self explanatory, so we won't go into too much detail here.

However, you'll notice in both cases that the address of your web application is required for setup. Since we're not actually running our application online, this could pose a problem. Luckily, there's a workaround. You might remember earlier we mentioned the address of your local server was either http://localhost/ or http://127.0.01/. By choosing the later, both Facebook and Twitter will treat your local web server as an actual address.

Also, it's worth pointing out that ThinkUp isn't perfect, either. Twitter, for example, will only offer the last 3200 available tweets, because the company claims to have no infrastructure in place to handle earlier request. You can't really blame ThinkUp's developers, but it's still a bit of a drag. On the upside, however, you can simply run XAMPP every few days and build up your own working archive yourself.

Conclusion

It's important to note that not all web applications are quite as complicated to install. Wordpress, for example, has its famed "five-minute installation," and the only thing required is you create a database beforehand. And though we've chosen to focus on ThinkUp, this installation process is generally the same for almost every other web application imaginable — from Wikipedia to Moveable Type. Thus, here are a few general rules for installing other web applications to a local web server using this method.

  • Always have the root username and password for your mySQL database on hand. Almost every web application you install will require it.
  • When installing applications locally, the database host is always localhost.
  • Some applications, such as Wordpress, won't create a mySQL database for you. If this is the case, you can create one very easily from the phpMyAdmin panel under the "Create new database" heading. Just remember what you named it, as you'll need to feed this info back to the your app.

Lead image via Flickr user Michael @ NW Lens.

Vrikkon June 22, 2011 at 4:45 p.m.

Kitty!

austinmilleron June 22, 2011 at 4:51 p.m.

havent we seen this picture before?

snetErzon June 22, 2011 at 4:53 p.m.
When I develop php stuff on my mac, I use MAMP, which makes the whole apache, php, db thing a simple task. Then I point the MAMP folder to look at the default SITES folder, and you can copy your thinkup install in there, and it should work fine.
Phunk_Kingon June 22, 2011 at 4:54 p.m.

Hmmm, sounds interesting but I don't know how I would utilize this for more than just an idle curiosity, a toy to tinker with once in a while. I'll have to see what other sorts of things I could do. Regardless, informative post and easy to understand. Thanks!

worknmanon June 22, 2011 at 5:26 p.m.
A google search reveals that you can also get Python working on this as well. Pretty cool :)
24bearon June 22, 2011 at 6:14 p.m.
Now make an article on how to run this on a network storage device! I want to save power!
bagels staff on June 22, 2011 at 6:53 p.m.

@austinmiller: I'm sorry. I just really like this picture.

@sneterz: I usually use MAMP as well for all of my light web dev, but I figured I'd wade into uncharted waters and use XAMPP for the sake of consistency. Considering MAMP also uses phpMyAdmin, the steps are more or less identical for both.

@phunk_king: It's definitely more of a niche project, which is why I tried to illustrate some solid uses for the everyman. But I'm also curious to see what others suggest. Glad you enjoyed it, however.

@24bear: it's definitely possible. Lifehacker had a piece a while back on how to get this sort of thing working on a Pogoplug.The problem with that, however, is that it's definitely a lot more niche due to the limited hardware requirements.

japhon June 22, 2011 at 7:03 p.m.
Interesting article, Matt, thanks! 
 
Can I ask why you're prompting users on Macs to setup a password for their "root" account instead of just using "sudo", which would seem to me to be a much safer alternative and cuts down the number of steps for this tutorial too?
glasswall52on June 22, 2011 at 7:08 p.m.

WAMP is another alternative that I use to develop with Apache, PHP and various databases. It's really easy to use but is only for Windows. I use it for local development, have about 30 different local websites and applications on it, and I haven't had any real problems to date, plenty of room for customization if you'd like, as well.

WolfOfOneon June 22, 2011 at 7:22 p.m.

@bagels: I really like Microsoft's WebMatrix for web dev. Very slick piece of software :)

bagels staff on June 22, 2011 at 7:25 p.m.

@japh: To be honest...I don't know! I use sudo later in the piece, so I think that was simply a mistake on my part. I tend to enable the root user whenever I reinstall OS X, so I tend to forget about sudo from time to time. Fix'd.

japhon June 22, 2011 at 7:29 p.m.
@bagels: Fair enough! I would definitely recommend just using "sudo" whenever root access is required. I can't see why anyone would truly need to enable the root user, personally. 
 
I'm going to give ThinkUp a go this evening now too, thanks!  :)
Uberjannieon June 22, 2011 at 7:52 p.m.
LOL, a Windows/OSX web-hosting solution? 
Who hosts on those anyways? In worst case I could have chosen Windows Server, but I wouldn't switch from RHEL. 
bagels staff on June 22, 2011 at 8:42 p.m.

@uberjannie: I don't think you read the article. This isn't for production/live environments.

Uberjannieon June 22, 2011 at 9:01 p.m.
@bagels: It does state that you should run live instances of web applications though? Like a blog or a wiki. What that requires is an fast internet connection, full duplex speed, not your common cable or DSL connection. 
I run several servers at home, but I have a 150/100 mbps fiber connection, which I cant utilize for other than work/hosting, so I also have a 40/10 ADSL2+ connection for personal use.  

Why would you expose your computer environment that you use for personal use to the dangers of the internet. Once you start listening on hosting ports, you suddenly become a target for a hacker that is looking to boost his botnet, and a PC has many applications with outdated software that poses a holes in security, is the ideal target of botnet hackers. 
 
If you absolutely want to host a app/service, just fork up with the money for hosting. I don't see the need to have a computer turned on 24/7 to host blogs etc anyways. 
 
Good article, but I am still unsure of the usefulnes. 
japhon June 22, 2011 at 9:05 p.m.
@uberjannie: I believe the article is aimed at "live" web applications that are for personal use, not public use. Such as ThinkUp, for example. Clearly you don't want to archive all your Twitter and Facebook accounts for public consumption.
Uberjannieon June 22, 2011 at 9:17 p.m.
@japh: Sure, if you only want them for ThinkUp. I do not use neither Facebook nor twitter, so I stopped reading when I reached that paragraph in the article, then I just skipped to the conclusion.  
 
I still do not like to have active hosting services active on a Windows box. This article would be great if it was made for a windows home server. I think most people running WHS would have loved many of the services you can get with a web-server. 
Also, if that box get hacked, most likely they wouldn't have gotten more than vacation pictures, wedding movies and maybe in worst cases encrypted backups. 
CROMon June 22, 2011 at 11:16 p.m.
@uberjannie: Ever consider that some people might want to play around with running web services for fun, and for personal utility? As for security, just sandbox your server by running it with all ports blocked from communicating with your local network (stick a firewall in between it and your LAN, if needed, and only provide the ability for the server to communicate with your internet gateway). Then, even if the server is compromised, you're still not in a position to lose anything else (and you should be able to restore the server from a backup if you were responsible enough to make one).
smxon June 22, 2011 at 11:32 p.m.

careful though don't serve too many pages or your ISP will cut you off , I think it violates some kind of Agreement. So either set up an internat and don't host your blog on your home computer.

Personally I setup a few "apps" on my homeserver to keep track of things like bills, appointments, events, announcements etc.. and only people in my network have access to them.

I have an HP WHS but a lot of the apps I am running are based of this

http://www.amahi.org/apps?category=sbs

householdutensilson June 22, 2011 at 11:38 p.m.

Amazon offers a free tier of their AWS service that gives you a micro ec2 instance. I'd say that if you're in this for the learning experience and not just to host a web app locally, this would be a good option since you get a nice sandbox that is isolated from your home network to play with. Plus you can always delete the instance and create a new one if you want to try different operating systems, or if you've broken something and you want to start again.

How To Rip DVDs to Play on Any Device—For Free!

Our ultimate DVD copying guide shows you how to use Handbrake to rip discs for playback on your laptop, Xbox, PS3, iPhone, Zune, netbook, iPad, PSP, iPod, and pretty much anything else

Tested: Apple Mac OS X Lion

The $30 upgrade from Snow Leopard seems like a no-brainer, but that's not the full story. Read the official Tested review.

Apple iPad 2 Review

Our definitive review of the iPad 2.

Tested: Nvidia GeForce GTX 580 Video Card

The green machine comes back swinging.

Apple iPad Wi-Fi Review

Apple's device isn't magical, but it is going to make the tablet a real category--for better or for worse

Video: How To Build the Best $1500 Gaming PC, Step-by-Step

Do you like saving money? What about playing PC games? Have you ever considered building your own PC? We show you exactly what you need to know to build an awesome $1500 gaming PC.

How To Build an Awesome $500 Windows Home Server

We pick the best parts to build a lean media backup and streaming machine.

The Best Android Phone for Your Network (February 2011)

Don't get locked in with the wrong phone.

Why I’ve Switched from Browser-Based Apps Back to Native Software on the Desktop

Moving from powerful, native Desktop clients to clunky web-apps isn’t always a good thing. In fact, it’s often a significant step backwards.

Qualcomm's Snapdragon S4 Integrates LTE, Tops Benchmarks

Qualcomm's latest Snapdragon SoC outperforms 2011's fastest chips by a wide margin and integrates LTE processing in the name of battery efficiency.

Ivy Bridge Chip Delay to Summer Gives Apple a Shot at Early Access

As PC makers hold onto new models in the summer months before Windows 8's launch, Apple will have plenty of time to launch new laptops with new processors.

Nokia Teases "Pure View" Camera, Which Hopefully Isn't Just More Megapixels [Video]

Nokia's next phone could mark the return of the Xenon flash, a large image sensor, or high quality 1080p video recording.

Future SSDs May Suffer from Speed and Reliability Issues

Researchers at the University of California, San Diego project doubled latency and tripled bit errors in SSDs as storage increases.

Purported 2048x1536 iPad 3 Display Spotted--Now Who's Making It?

A quad-pixel iPad display in the flesh, but it is unlikely that Sharp will manufacture it.

How Windows 8 Will Integrate SkyDrive for Cloud Storage and Remote PC Access

SkyDrive's omnipresence in Windows 8 extends from the profile to Metro apps to the legacy desktop.

Major Changes to Flickr to Begin Rolling Out February 28th

The Photo View and Upload pages are getting much-needed redesigns, which Flickr needs to stop the user bleed.

What Kind of Computer User Needs a High-End 17-inch Laptop?

According to Loyd, there exist three key uses that necessitate a high-end 17-inch laptop.

Why I’ve Switched from Browser-Based Apps Back to Native Software on the Desktop

Moving from powerful, native Desktop clients to clunky web-apps isn’t always a good thing. In fact, it’s often a significant step backwards.

Future SSDs May Suffer from Speed and Reliability Issues

Researchers at the University of California, San Diego project doubled latency and tripled bit errors in SSDs as storage increases.

Comcast Announces Its Netflix Rival: Xfinity Streampix

The streaming video service is launching this Thursday for existing Comcast subscribers.

Tested: The New and Improved Swype Beta on Android 4.0

After acquiring Swype, Nuance had updated the app for Android 4.0 and added some new features.

Everything You Need to Know About Ubuntu for Android

Linux gets more Linux-y when Android gets mashed up with Ubuntu.

Purported 2048x1536 iPad 3 Display Spotted--Now Who's Making It?

A quad-pixel iPad display in the flesh, but it is unlikely that Sharp will manufacture it.

Siri On OS X: Will Most Users Even Care?

One notable feature missing from the upcoming Mountain Lion release of OS X is Apple's Siri.

Submissions can take several hours to be approved.

Save ChangesCancel