Cloud Native 7 min read

How to Deploy a Pay‑Per‑Use WordPress Site on Alibaba Cloud Serverless

Learn step‑by‑step how to build a cost‑effective, pay‑per‑use WordPress website on Alibaba Cloud Serverless using Function Compute, NAS storage, RDS, and SLS, covering service activation, NAS setup, function configuration, custom domain binding, code deployment, and final verification.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
How to Deploy a Pay‑Per‑Use WordPress Site on Alibaba Cloud Serverless

Prerequisites

Enable the following Alibaba Cloud services in the same region and VPC:

Function Compute (FC)

NAS file storage

RDS relational database

Log Service (SLS)

All services should have a free tier or pay‑per‑use quota.

NAS Setup

Open the Alibaba Cloud NAS console and create a General‑purpose NAS file system (e.g., in the Hangzhou region).

The console automatically creates a mount point; no manual mount point creation is required.

NAS console screenshot
NAS console screenshot

Function Compute Configuration

Open the Function Compute console and select the same region used for NAS.

Create a new service :

Enable VPC access and public network access.

Select the VPC and switch that were used for the NAS file system.

Create a security group if none exists.

In the service details, edit the Storage Configuration , enable NAS, and choose Automatic Configuration .

Create a new blank function:

Runtime: PHP 7.2 Check “Handle HTTP requests”.

Add a trigger that matches all HTTP request methods.

Replace the default handler with the following PHP script, which forwards WordPress PHP requests to the built‑in CGI proxy and serves static assets directly from the NAS mount point /mnt/www.

getAttribute("requestURI");
$uriArr = explode("?", $uri); // default php / or /wp-admin/
if (preg_match('#/$#', $uriArr[0]) && !(strpos($uri, '.php'))) {
    $uriArr[0] .= "index.php";
    $uri = implode($uriArr);
}
$proxy    = $GLOBALS['fcPhpCgiProxy'];
$root_dir = '/mnt/www'; // NAS mount point
if (preg_match('#\.php.*#', $uri)) {
    $host = "www.example.com"; // replace with your domain
    $resp = $proxy->requestPhpCgi($request, $root_dir, "index.php",
        ['HTTP_HOST' => $host, 'SERVER_NAME' => $host, 'SERVER_PORT' => '80'],
        ['debug_show_cgi_params' => false, 'readWriteTimeout' => 60000]);
    return $resp;
} else {
    // static files (js, css, jpg, …)
    $filename = $root_dir . explode("?", $uri)[0];
    $filename = rawurldecode($filename);
    $handle   = fopen($filename, "r");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    $headers = [
        'Content-Type'  => $proxy->getMimeType($filename),
        'Cache-Control' => "max-age=8640000",
        'Accept-Ranges' => 'bytes',
    ];
    return new Response(200, $headers, $contents);
}

Custom Domain Binding

In the Function Compute console, go to Advanced Features → Domain Management .

Add the domain you have registered (must be ICP‑registered on Alibaba Cloud).

Select the service and function created above and confirm the binding.

Update the domain’s DNS record to point to the internal address provided by Alibaba Cloud.

Upload WordPress Files

For convenience, launch a temporary pay‑per‑use ECS instance, mount the NAS via NFS, and transfer the WordPress package using SFTP or SCP.

Mount command (replace the endpoint with your NAS file system ID):

mount -t nfs -o vers=4.0 16d3e4b609-cub21.cn-hangzhou.nas.aliyuncs.com:/ /mnt
WordPress upload screenshot
WordPress upload screenshot

Verification

Open the bound custom domain in a web browser. The WordPress site should load, confirming that the serverless deployment is functional.

References

Function Compute product page: https://www.aliyun.com/product/fc

NAS console: https://nasnext.console.aliyun.com/overview

Function Compute console: https://fcnext.console.aliyun.com/overview

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeServerlessPHPAlibaba CloudFunction ComputeNASWordPress
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.