顯示廣告
隱藏 ✕
看板 whatla
作者 lecheck (訪客)
標題 How to Run a Web Server on Your Android Device
時間 2014年12月15日 Mon. PM 08:20:24


http://blog.laptopmag.com/android-web-server

 By Avram Piltch, LAPTOP Online Editorial Director | Aug 19, 2013 11:23 AM EST
 198  39 Google +131  2


Whether you have a $50 mini PC that you leave plugged in all the time or a 5-inch smartphone that you carry with you, you can use any Android device as a full fledged web server that's accessible either on LAN or from anywhere on the Internet. With an Android web server, developers can easily test their code without paying for a hosting service. Freelancers can carry a copy of the web tools they've built with them to show their clients. Home and small office users can even set up custom web tools for users on the local network.

Here's how to set up a web server on your Android phone, tablet or mini PC.
Install the Web Server

1. Install and launch KSWEB on your Android device. The app only has a six-day free trial, after which it costs $2.99. There are a number of other web server apps, including Bit Web ($2.39) and Servers Ultimate, but we chose KSWEB for this tutorial because it is one of the simpler options.

ksweb

 2. Navigate to the IP address listed by KSWEB in your computer's browser or to localhost:8080 on the device itself.

ksweb ip

3. Click the link for KSWeb Interface and enter the default username and password (admin and admin).

ksweb admin

4. Select System settings and change the default password from 「admin」 to something else.

kweb change admin password

5. Select KSWEB settings, enter a MySQL shell password and hit save. You can stick with the default, blank password but it is unadvisable to have a blank password, even if your server isn't connected to the Internet.

ksweb mysql pwd

6. Select a root directory for your site by tapping Document Root in the KSWEB app's settings menu and entering the appropriate file path. You may wish to keep the default directory (/mnt/sdcard/htdocs), but we recommend that you save space by putting the folder on a microSD card, if your Android device has one.

ksweb settings document roo

You can now visit your site by navigating to localhost:8080 on the Android device or by navigating to the IP address displayed by KSWeb. However, at this point, you will only see KSWEB's default home page and you will only be able to access it from within the local network.

MORE: Galaxy S4 Tips
Make Your Server Accessible From the Web

If you want users outside of your local network to see your web server, you must make a few tweaks to your router settings. Every brand of router has its own administration menus so the names of menus and fields will vary slightly, but these are the general steps you must take to make your Android web server available on the Internet. Our screen shots and menus were taken from a TRENDnet TEW-633GR router.

1. Log into your router's administration page from your PC. If you don't know its IP address, check the user's manual for your router.

router admin

2. Make a static IP address available for your Android device. Local IP addresses tend to start with 192.168.10.1 and go up from there. If your router provides DHCP (dynamically assigned I IPs) to an address range, anything lower than that range will be available for a static assignment. For example, our router uses addresses 192.168.10.101 to 192.168.10.200 for dynamic assignments so we chose to give our phone the 192.168.10.99 address. Some routers will also let you reserve a specific address.

dhcp server settings

3. Configure your router to forward port 80 to port 8080 on the static IP address you're assigning to your Android device. On our router, this function was labeled 「Add virtual server」 but on others it will called 「port forwarding.」

port forwarding settings

4. Navigate to the Wi-Fi menu on your Android device.

select wifi settings

5. Long press the name of your Wi-Fi network and select Modify Network.

wifi settings modify networ

6. Check show advanced options.

wifi settings show advanced

7. Select Static under IP settings and enter the static IP address you chose (or reserved) and tap Save.

wifi settings static ip

8. Search Google for the term 「What's My IP」 to find your router's public IP address. Google will display it above the search results.

find public ip

Anyone on the Internet will now be able to navigate to your site, as long as you give them this IP address to use. Unfortunately, unless you pay for a plan with a static IP address, your number could change the next time your router reboots. You can solve this problem by purchasing a domain and using a dynamic DNS service such as dyn.com that always directs that domain to your current IP address, no matter how often it changes.

Keep in mind that hosting a web site from your home Internet connection may violate your ISP's terms of service so, if you're planning to have everyone on the Internet visiting, you may want to upgrade your account or purchase a web hosting package.

MORE: 5 Ways to Speed Up Your Android Phone in Under 5 Minutes
Keep Your Web Server Awake

When your Android device goes to sleep, the server software goes to sleep also so users will not be able to connect to it. There are a number of apps that will keep your device from sleeping, but we like Keep Screen On because it allows you to decide which apps will keep the screen awake and to set the device not to sleep while charging.

To keep your Android device awake while the server is on:

1. Install Keep Screen On.

keep screen on

2. Toggle the service to On and tap settings.

keep screen on toggle on

3. Toggle Keep screen on while charging to on. If you plan to keep your server up and running, you should leave your device plugged in anyway.

keep screen on settings

4. Tap Applications. A list of all applications appears.

keep screen on settings men

5. Check the box next to KSWEB and tap the light bulb icon in the upper right corner of the screen.

keep screen on applications

6. Select 「When app is running」 from the pop-up menu that appears.

keep screen on running

MORE: 30 Apps for Rooted Android Phones
Adding Files to Your Android Web Server

With KWSWEB running, you browse your site directly from the Android device by navigating to localhost:8080 or you can visit its IP address from any computer on your local network. However, there's no point in visiting a site that has no content. If you want to put HTML files, PHP scripts, images or other files on your server, you can either create them locally or send them from your PC via FTP.

To edit Android Web server files locally:

1. Install DroidEdit or another code editor on your Android device.

droidedit

2. Write or edit web files in HTML, CSS, PHP, Javascript or other languages.

3. Save files to the web server's directory by selecting Save as and navigating to the appropriate folder.

save file

To send files to your server over FTP:

1. Install FTP Server by Olive Tree.

ftp server google play

2. Tap Home directory in FTP Server's settings menu and select Custom folder.

ftp server set custom folde

3. Tap Custom folder in the settings menu and enter the KSWEB's root directory (/mnt/sdcard/htdocs if you didn't change it).

ftp server custom folder 670x369

4. Set a username and password by tapping on those options in settings.

ftp server set username pas

5. Tap the start button in FTP server. If the server is active the button will turn green after you tap it. You can tap it again to turn FTP off.

start ftp server

6. Forward port 21 to port 2221 on your Android device's IP address in your router software if you want to FTP from outside of your local network.

ftp port forwrading

Users will now be able to upload and download files from your web server by entering either the local or public IP addresses into an FTP client such as Filezilla.

MORE: Best Android Security Apps 2013
Install WordPress On Your Android Server

With PHP and MySQL on your server, you can install any of a number of content management systems (CMSes), including WordPress, a very powerful publishing tool used by over 8.5 million sites including several large ones. To install WordPress on your Android server:

1. Install Astro File Manager if you don't already have it.

2. Download the WordPress zip file from wordpress.org.

wordpress download

3. Launch Astro File Manager and navigate to the Download folder (usually under /sdcard/Download) on your device.

4. Long press the wordpress zip file and select Extract Here.

astrofile extract

5. Copy the wordpress folder under Download and then paste it into the server's root directory.

astro copy

6. Navigate to the device's local IP address at port 10,000 on your PC. PhpMyAdmin will load.

phpmyadmin ip

7. Enter the root as the username and the password that you assigned to it when configured KSWEB.

phpmyadmin log

8. Click the Databases tab at the top of the screen.

databases tab

9. Enter 「wordpress」 in the Create database field and tap Create.

create wordpress db

10. Navigate to your server's IP address with the port :8080 and path /wp-admin/install.php (ex: 192.168.10.99:8080/wp-admin/install.php) on your PC.

11. Click Create a Configuration File when prompted

wordpress config


12. Enter your database user name and password when prompted by WordPress.

wordpress username password

13. Click Run the Install when asked by WordPress to do so.

wordpress run the install

14. Enter your site title, desired username, password and email address then hit the Install WordPress button. These are the credentials you will use to log into WordPress after it installs.

wordpress username

WordPress will then confirm your install and allow you to log in for the first time.

wordpress install confirmed

You will be able to log into WordPress and write new posts by going to your IP address /wordpress/wp-admin.

--
※ 作者: lecheck 時間: 2014-12-15 20:20:24
※ 看板: whatla 文章推薦值: 0 目前人氣: 0 累積人氣: 113 
分享網址: 複製 已複製
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇