Building Small Web Tools on Tencent Cloud: Questionnaire System, QR‑Code Utility, Map Search, and Xcode Download
The article walks through setting up a low‑cost Tencent Cloud Ubuntu server with Apache or Nginx‑PHP, then demonstrates building four lightweight web utilities—a self‑hosted questionnaire system, a JavaScript QR‑code generator/scanner with short‑URL support, a Baidu‑map search tool, and a PHP script that parses Apple’s CFPropertyList to list Xcode dmg and docset download URLs.
This article documents a series of lightweight web tools that the author built while learning and practicing cloud development on Tencent Cloud. The tools include a questionnaire system, a QR‑code generator/scanner, a map‑search utility, and a script for retrieving Xcode dmg/docset download URLs.
Environment Setup (PHP)
The author uses a $65/month Ubuntu 14.04 x64 instance on Tencent Cloud. Both Apache+PHP+MySQL and Nginx+PHP‑FPM are described. Example commands for installing Apache:
sudo apt-get update
sudo apt-get install apache2 php5
service apache2 startPreferred Nginx+PHP setup commands (including adding the official Nginx repository, installing, and configuring the service):
# Add Nginx official key
wget http://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
rm nginx_signing.key
# Add Nginx repository
codename=$(lsb_release -a|grep Codename|awk '{print $2}')
echo deb http://nginx.org/packages/ubuntu/ $codename nginx > nginx.list
echo deb-src http://nginx.org/packages/ubuntu/ $codename nginx >> nginx.list
sudo cp nginx.list /etc/apt/sources.list.d/nginx.list
# Install Nginx
sudo apt-get update
sudo apt-get install nginx
# Verify port 80
netstat -tln
# Add nginx user to www-data group
sudo usermod -a -G www-data -G nginx nginxSample nginx virtual‑host configuration:
server {
listen 80;
server_name localhost;
root /home/ubuntu/www;
index index.php index.html index.htm;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/ubuntu/www;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}Enable short open tags and restart services:
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php5/fpm/php.ini
sudo service php5-fpm restart
sudo service nginx restartCreate a demo page to verify PHP:
echo "
" > /home/ubuntu/www/index.phpQuestionnaire System
Background: The author needed a self‑hosted alternative to Google Forms. The system stores form definitions as JSON, saves responses to CSV files, and provides export functionality.
Implementation steps (high‑level):
Front‑end: JavaScript builds form elements; each element has an EntryType (text, single‑choice, etc.) and a Choices array.
Back‑end: PHP receives the whole JSON payload, stores it with a random ID, and later renders the form based on the stored JSON.
Submission: Answers are posted as key‑value pairs, reordered, and saved as CSV.
Export: A special link returns the CSV for download.
Sample JSON for a single question:
{
"EntryId": 3,
"Composite": false,
"QuestionTitle": "无标题的问题",
"HelpText": "",
"EntryType": 4,
"Choices": [
{"SelectedByDefault": false, "Value": "选项 1", "Label": "", "GoToPage": -2},
{"SelectedByDefault": false, "Value": "选项 2", "Label": "", "GoToPage": -2}
],
"OtherOptionEnabled": false,
"Required": false,
"GoToPageEnabled": false,
"Position": 3
}QR‑Code Tool
Background: The author wanted a lightweight QR‑code generator without third‑party tracking and a way to generate short URLs for sharing.
Generation (pure JavaScript):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="http://jeromeetienne.github.io/jquery-qrcode/src/jquery.qrcode.js"></script>
<div id="qrcode"></div>
$('#qrcode').qrcode({ width: 64, height: 64, text: 'hello, world' });To obtain a downloadable <img> instead of a canvas:
<img id="qr_img"/>
function make_qrcode(text, width) {
width = width || 256;
var div = $('
');
div.qrcode({ width: width, height: width, text: text });
var url = div.find('canvas')[0].toDataURL();
$('#qr_img').attr('src', url);
}
make_qrcode('hello, world', 256);Parsing (jsqrcode library):
var reader = new FileReader();
reader.onload = function(e) { qrcode.decode(e.target.result); };
reader.readAsDataURL(file);Short‑URL generation is handled by a simple PHP script that calls api.t.sina.com.cn .
Map Search Utility
Background: Quickly locate company shuttle stops on a map.
Implementation uses Baidu Map API to geocode a city name and display markers. Key JavaScript snippet:
var city = '深圳';
var geocoder = new BMap.Geocoder();
var map = new BMap.Map('container');
geocoder.getPoint(city, function(point){
console.info('point:', point);
map.centerAndZoom(point, 11);
map.addControl(new BMap.MapTypeControl());
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT}));
});Xcode dmg / docset Download URL Retrieval
Background: Direct download of Xcode dmg and documentation packages is faster than using the App Store, but third‑party sources pose security risks.
Implementation (PHP + CFPropertyList):
$url = 'https://developer.apple.com/library/downloads/docset-index.dvtdownloadableindex';
$xml = file_get_contents($url);
$plist = new CFPropertyList\CFPropertyList();
$plist->parse($xml);
$docs = $plist->toArray();The script parses Apple’s CFPropertyList file and outputs a friendly list of download URLs.
Overall, the article serves as a practical guide for setting up a low‑cost cloud environment, deploying PHP/NGINX services, and building small, reusable web utilities.
Tencent Cloud Developer
Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.