Web Server for testing on Linux
I am looking for a simple easy to use lightweight Web server ( linux/Ubuntu Koala ) for testing some web apps.
On Windows开发者_JAVA百科 I used Web Savant ( which was rather easy, just enter the html directory and the bin directory and press start ) to give some people an idea of what I'm looking for.
Update: My apologies. I didn't realise that this was a requirement untill now. Ideally the whole package would be one executable file, however since it is a webserver it would be understandable if there were some infrastructure created so maybe a tarball containing a executable. It would be nice if it started from the commandline and required no administrator privileges to run. Furthermore it should not require any configuration files or log files stored in any areas which are usually administrator access only.
PS This is a question about a tool for testing programs, not a question about system administration. Thus this question is appropriate for stackoverflow not serverfault. If you insist on arguing this, then I suggest you reread the question. Still want to argue? Keep rereading the question untill you understand it, I'll wait. Understand it now? Good now go away.
This question is currently one of the top google results for "lightweight web server ubuntu", and while I didn't find the current answers all that helpful, I stumbled upon another solution that is installed by default on most every linux system:
python -m SimpleHTTPServer
This will run a webserver in the current directory (html, css, images, documents, etc), serving the files to localhost:8000
, and shouldn't require any additional software installation. Python documentation for this module has more information on parameters, etc.
For someone looking to quickly test a website, this is an ideal solution.
If you use CGI or plain HTML pages only, the simplest would be thttpd
just:
thttpd -D -C '*.cgi' -p 8080
And go!
Lighttpd is very simple to configure as well, but requires writing a little configuration file.
If you have PHP installed then you can use it's built-in webserver to quickly serve a directory.
cd www/
php -S localhost:1234
and your www/
directory is now available at http://localhost:1234/
I used Mongoose (SHTTPD) for some quick testing. I needed to test HTTP/S + CGI on the fly and found it rather easy to use. I did come across one problem. Whenever I pushed the process into the background the CGI pages would stop working. This was fixed by issuing:
nohup <command> &
Anyways, the link for Mongoose is http://code.google.com/p/mongoose/ if you're interested. For such a tiny web server the features are pretty good.
- Crossplatform - works on Windows, MacOS and most flavors of UNIX
- CGI, SSL, SSI, Digest (MD5) authorization, resumed download, aliases
- IP-based ACL, Windows service, GET, POST, HEAD, PUT, DELETE methods
- Small footprint: 40 Kb executable on Linux 2.6 i386 system
- Embeddable with simple and clean API. Source is in single .c file to make things easy
- Language suport for: o C/C++ (native) o Python - since version 2.6 (done) o C# - since version 2.7 (done) o Ruby - since version 2.9 (todo) o Lua - since version 2.9 (todo)
Cheers
Ubuntu is awesome, it has a much easier AMP install than Windows(using xampp). Just run this:
sudo tasksel
Check "LAMP" and it will install the entire stack for you. I also recommend doing a :
sudo apt-get install phpmyadmin
Just go to http://127.0.0.1/phpmyadmin to setup new databases.
Xampp is one of the several LAMP available on Linux, and it is a good one.
Installation is easy (documentation is here): load the archive and then:
sudo tar xvfz xampp-linux-1.7.3a.tar.gz -C /opt
cd /opt/lampp/
sudo ./lampp start
Furthemore it does not clash with the filesystem (the full archive is dezipped in /opt directory).
Please look at the full list of X-AMP distributions in wikipedia.
I also use the Python approach mentioned here by @sAlexander, but at times need to have the server listening on something other than localhost
. In my case, I'm testing Android apps running in an Android VirtualBox VM. By default, these virtual Android devices are connected to the VirtualBox host-only adapter at 192.168.56.xx, so the server address needs to be 192.168.56.1. To do this, I use the following python script which I adapted from a Linux Journal tech tip:
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"
if sys.argv[1:]:
server = sys.argv[1]
else:
server = '127.0.0.1'
if sys.argv[2:]:
port = int(sys.argv[2])
else:
port = 8000
server_address = (server, port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
print "httpd on", server, ":", port
httpd.serve_forever()
Arguments are server address (1st argument) and port (2nd), with defaults of 127.0.0.1 (localhost
) and 8000, respectively. You can specify neither, just an address, or both address and port.
xampp? http://www.apachefriends.org/en/xampp.html
精彩评论