如何为我的Digital Ocean服务器部署cPanel并按项目配置PHP版本?
Hey there, let’s break down exactly how to get cPanel up and running on your DigitalOcean Droplet so you can manage PHP versions and other project-specific configs with ease.
First off, make sure your Droplet meets cPanel’s system requirements—this is non-negotiable for a smooth install:
- Use a supported OS: AlmaLinux 8, CentOS 7, or CloudLinux 8 (cPanel doesn’t fully support Ubuntu/Debian, so stick to these).
- Allocate at least 2GB of RAM (1GB works but might cause performance hiccups) and 20GB of disk space.
- If you’re using an existing Droplet, stop and disable any pre-installed web servers (Apache/Nginx) since cPanel will deploy its own stack:
systemctl stop httpd nginx systemctl disable httpd nginx
Log into your Droplet as root via SSH, then run the official installation script. Grab a coffee—this takes 15-30 minutes depending on your Droplet’s speed:
cd /home && curl -o latest -L https://securedownloads.cpanel.net/latest && sh latest
Once the script finishes, reboot your Droplet to lock in all changes:
reboot
After rebooting, access WHM by navigating to https://your-droplet-ip:2087 (note the HTTPS and port 2087—you’ll see a security warning, just proceed since it’s your server).
Walk through the initial setup wizard:
- Set a valid hostname (e.g.,
server.yourdomain.com) and make sure it points to your Droplet’s IP via DNS. - Configure nameservers (you can use DigitalOcean’s default ones or set up custom ones through WHM).
- Enter an admin email to receive server alerts and updates.
This is the part you care about—tweaking PHP versions for individual projects:
- In WHM, go to EasyApache 4 (under the Software section). Here, install all the PHP versions you need (e.g., 7.4, 8.1, 8.2).
- Create a cPanel account for each project (use Create a New Account in WHM).
- Log into the project’s cPanel dashboard, then head to Select PHP Version under Software:
- Pick the exact PHP version for that project.
- You can also customize php.ini settings (like memory limit, upload max size) directly from this interface.
- For even more control (per-directory PHP versions), add this line to your project’s
.htaccessfile:
Just replaceAddHandler application/x-httpd-php81 .phpphp81with the version you want to use for that directory.
Now get your site onto the cPanel server:
- Use cPanel’s File Manager to upload files directly to the
public_htmlfolder of your project’s account. - Or enable FTP/SFTP access (via FTP Accounts in cPanel) to transfer files from your local machine.
- Finally, update your domain’s DNS records to point to your Droplet’s IP so visitors can reach your site.
- cPanel requires a license. You can grab a 15-day free trial from cPanel, or add a license directly through DigitalOcean when creating your Droplet.
- Keep WHM/cPanel updated regularly (check Update Preferences in WHM) to stay secure and get new features.
- If you hit snags during install, check the log file at
/var/cpanel/logs/install_logfor troubleshooting clues.
内容的提问来源于stack exchange,提问作者Vikas Ukani

