This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Every 1 second delay costs up to 20% conversions. Learn how to fix it [Free • Mar 10–11]. Save My Spot→

How to Host PHP on DigitalOcean (2 Easy Methods)

Updated on February 23, 2026

15 Min Read
php digitalocean

Key Takeaways

  • Hosting PHP on DigitalOcean gives you a balance between dedicated server control and affordable cloud pricing.
  • You can deploy PHP applications in more than one way, depending on how much server level control you want.
  • Proper server setup, including web server, database, and PHP configuration, is essential for a secure and production ready environment.

Hosting a PHP application usually forces you to choose between two extremes: the frustrating limitations of shared hosting, or the steep learning curve of massive cloud providers like AWS or Google Cloud.

This is exactly why DigitalOcean remains a go-to choice for deploying PHP. It provides a highly practical middle ground. You get a dedicated virtual machine with full root access, predictable pricing, and reliable performance, all without the enterprise-level complexity.

In this guide, I’ll walk you through exactly how to host a PHP app on DigitalOcean. We will look at two different approaches:

  • Method 1 (The Manual Route): How to configure a raw DigitalOcean Droplet and install a complete LEMP stack directly from the command line.
  • Method 2 (The Managed Route): How to automate the server setup and deployment process using Cloudways.

Let’s get to it.

Why Choose DigitalOcean to Host PHP?

DigitalOcean is widely considered one of the best cloud computing providers in the developer community, and its infrastructure is exceptionally well-suited for PHP applications.

Whether you are deploying a simple custom script or a massive Laravel framework, here is why DigitalOcean stands out:

Predictable & Affordable Pricing

Unlike massive hyperscalers where monthly billing can be complicated, DigitalOcean offers straightforward pricing. You can spin up a Basic Droplet (a virtual machine) for as little as $4 a month. DO also offers per-second billing, ensuring you only pay for the exact compute time your application uses.

Raw Performance

PHP applications that rely on heavy database queries require fast processing. DigitalOcean uses high-speed SSD storage across its standard Droplets and incredibly fast NVMe storage on its Premium and Storage-Optimized plans. This ensures the rapid read and write speeds your MySQL or PostgreSQL databases need to run efficiently.

Ultimate Server Control

When you deploy a Droplet, you get full control to configure your environment. This means you have absolute freedom to configure your Nginx or Apache web server, install specific PHP extensions, and tweak firewall rules exactly how your application demands it.

Seamless Scalability

As your PHP application’s traffic grows, your server can effortlessly grow with it. DigitalOcean allows you to scale your Droplet’s compute capacity and memory seamlessly. If your app becomes highly resource-intensive, you can easily migrate to their dedicated CPU-Optimized or Memory-Optimized infrastructure.

Global Data Centers

DigitalOcean maintains 17 globally distributed datacenters. This includes hubs in New York, London, Singapore, and a newly opened facility in Atlanta. This allows you to deploy your PHP application in a geographic region that is closest to your primary user base, drastically reducing latency and improving page load times.

Deploy PHP on DigitalOcean Without the Sysadmin Work

Launch an optimized PHP server on DigitalOcean in minutes. Skip the command line and manage your environment directly from the Cloudways dashboard.

Method 1: How to Install PHP on DigitalOcean Manually (The LEMP Stack Route)

In this section, I’ll walk you through how to manually deploy a PHP application on a DigitalOcean Droplet from scratch. To do this, I’ll be setting up a reliable LEMP stack (Linux, Nginx, MySQL, and PHP) using Ubuntu 24.04 LTS.

Prerequisites

Before we dive into the setup, here is what you’ll need to follow along:

  • An active DigitalOcean account: You’ll need this to spin up your server.
  • A command-line application: If you are on macOS or Linux, you can use the built-in Terminal. If you are on Windows, PowerShell or Command Prompt will work perfectly.
  • Basic comfort with the command line: We will be copying and pasting a few Linux commands to get everything installed.

Step 1: Create Your DigitalOcean Droplet

To get started, I’ll log into my DigitalOcean dashboard and navigate to the top right corner to click Create > Droplets.

Create a Droplet from DigitalOcean Dashboard

  • Choose Region: First up, I need to select a region. I’ll pick a data center location that is geographically closest to my target audience (like New York, San Francisco, or London) to avoid any potential latency and ensure the fastest loading times for my visitors.

Select Region in DigitalOcean

  • Choose a Datacenter: I’ll pick a data center region that is geographically closest to my target audience to ensure the lowest possible latency for my visitors.

Select Datacenter location in DigitalOcean

  • Choose an Image: Next, for the operating system, I’ll go under the “OS” tab and select Ubuntu. I’ll make sure the version is set to an LTS (Long Term Support) release like 24.04, as this provides a highly stable, modern foundation for the web server.

Choose Ubuntu Image for Droplet

  • Choose a Size: Now, I need to pick my Droplet type and size. For a standard PHP app, I’ll select Shared CPU and then Basic. Under CPU options, I can pick Regular, Premium Intel, or Premium AMD. The low-cost plans are perfect for getting started and testing an environment, so I’ll go with a standard option.

Choose Droplet size and plan

  • Choose Authentication Method: Scrolling down past the optional storage and backups, I’ll set my authentication to SSH Key. This is much more secure than a standard password. If you don’t have an SSH key set up on your machine yet, DigitalOcean allows you to generate and add one right on this screen. I’ve covered the steps to generate an SSH Key in a separate guide so feel free to check it out.

Choose Authentication Method SSH Keys

  • Finalize Details: Finally, under “Finalize Details”, I’ll enter a recognizable Hostname for my Droplet (something simple like php-web-server instead of the long default string), and then I’ll click the Create Droplet button to spin up my server.

Finalize Droplet Details and Create

Step 2: Connect to Your Server via SSH

  • Once my Droplet finishes provisioning, DigitalOcean will display its public IP address. I’ll copy that IP address right from the dashboard.

Copy Droplet IP Address

  • Next, I need to connect to my new server. While DigitalOcean does have a web-based console you can launch from the dashboard, I prefer using the native terminal right on my computer (Command Prompt or PowerShell for Windows, or the Terminal app for Mac/Linux).
  • I’ll open up my Command Prompt and run the following command. Make sure to replace your_server_ip with the actual IP address you just copied:

ssh root@your_server_ip

  • Because this is my first time connecting to this specific server, the terminal will ask if I want to continue connecting and verify the server’s fingerprint. I’ll simply type yes and hit Enter.

Verify SSH Connection Fingerprint

  • Since I selected SSH Keys during the setup, I don’t even need to type in a password. Just like that, I am securely logged into my server as the root user and ready to start installing software.

Step 3: Update Your Server Packages

Before I install PHP or configure the web server, I always make sure my Ubuntu server has the latest security patches and software updates. To do this, I’ll run this combined command to update and upgrade the package lists:

sudo apt update && sudo apt upgrade -y

After running the command, during the update or installation process, your terminal might suddenly display a purple screen asking what to do with a modified configuration file. Simply select “Keep the local version currently installed” (which is the default) and press Enter. The process will pick right back up and finish the installation.

Keep the local version currently installed prompt

Step 4: Install the LEMP Stack

Now it’s time to install the actual software. Instead of doing this one by one, I’ll install the web server (Nginx), the database (MySQL), and the PHP components in a single, clean command.

This command pulls the default PHP-FPM package along with the module needed for PHP to communicate with MySQL:

sudo apt install nginx mysql-server php-fpm php-mysql -y

Step 5: Secure Your Database

At this point, my MySQL database is installed, but it’s using default, unsecured settings. To fix this, I’ll lock it down by running the built-in security script:

sudo mysql_secure_installation

The terminal will guide me through a series of prompts. Here is exactly how I’ll answer them to ensure my database is properly secured:

    • VALIDATE PASSWORD COMPONENT: The script will ask if I want to set up the validate password component. I’ll press y and hit Enter. This is a great feature that ensures any future database passwords I create are actually strong.
    • Password Validation Policy: Next, it asks for a strictness level (0 = LOW, 1 = MEDIUM, 2 = STRONG). I’ll type 1 and hit Enter. This is the perfect middle-ground for web servers, requiring at least 8 characters, numbers, mixed-case letters, and special characters.
    • New Password: It will now ask me to type and confirm a new password for the MySQL root user. (Pro-tip: When you type passwords in a Linux terminal, the characters won’t show up on the screen—no asterisks or dots. Just type your password blindly and hit Enter!)
  • The Remaining Prompts: For the final set of questions (Remove anonymous users? Disallow root login remotely? Remove test database? Reload privilege tables?), I will simply press y and hit Enter for every single one.

Once the script outputs “All done!“, my database is fully locked down and protected from outside access.

MySQL Secure Installation Prompts

Step 6: Configure Nginx for PHP

Right now, my Nginx web server is running perfectly, but out of the box, it only knows how to serve plain HTML pages. It doesn’t know what to do with a PHP script. I need to dive into the server’s settings and point Nginx to the PHP-FPM processor I just installed.

To do this, I’ll open the default Nginx configuration file using the Nano text editor:

nano /etc/nginx/sites-available/default

Once the file opens in my terminal, I’ll use my keyboard’s down arrow to scroll through the text and make two very specific modifications:

1. Prioritize PHP Files

First, I need to tell Nginx to load index.php files before standard HTML files. I’ll scroll down until I find a line that looks exactly like this:

index index.html index.htm index.nginx-debian.html;

I’ll add index.php right after the word index, so the updated line looks like this:

index index.php index.html index.htm index.nginx-debian.html;

Configure Nginx to prioritize index.php

2. Enable PHP Processing

Next, I’ll keep scrolling down a bit further until I find a block of text that starts with # location ~ \.php$ {. The # symbols mean these lines are “commented out” or ignored by the server.

I need to delete the # symbol in front of a few specific lines to activate them.

Because Ubuntu 24.04 installs PHP 8.3 by default, I also need to make sure I am pointing to the php8.3-fpm.sock file.

I’ll carefully edit that block so it looks exactly like this:

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}

Enable PHP processing location block in Nginx

Once I’m confident my edits match the snippet above, I’ll save my changes and exit the Nano editor. To do this, I’ll press Ctrl+O (the letter O) to save, hit Enter to confirm the file name, and then press Ctrl+X to exit back to the command line.

3. Test and Restart Nginx

Before I restart the web server, it is a best practice to test the configuration file to make sure I didn’t accidentally leave out a semicolon or make a typo. I’ll run this command:

nginx -t

If it says syntax is ok and test is successful, I am good to go.

Nginx syntax test successful

To apply these new configurations, I’ll restart Nginx:

sudo systemctl restart nginx

Step 7: Test Your PHP Installation

Finally, I want to verify that everything is functioning correctly. I’ll do this by creating a simple PHP test file right in my server’s public web directory.

nano /var/www/html/info.php

I’ll paste the following PHP function into the empty file:

<?php
phpinfo();
?>

Create PHP info test file

I’ll save and exit the editor just like before (Ctrl+O, Enter, Ctrl+X).

Now for the moment of truth. I’ll open my web browser and navigate to http://your_server_ip/info.php.

If you see a screen detailing your PHP configuration and active modules, congratulations! You have successfully set up a complete, manual PHP environment on DigitalOcean.

PHP configuration success screen

Once you see that success screen, make sure to delete the test file by running sudo rm /var/www/html/info.php. While generating a PHP info page is the perfect way to verify your installation, leaving it active on a live server exposes all your sensitive backend configurations to anyone who visits that URL.

Method 2: How to Host PHP on DigitalOcean via Cloudways (The Managed Route)

Now that we’ve seen how many command-line inputs it takes to manually configure a DigitalOcean Droplet and deploy a PHP stack from scratch, I’m going to show you a much faster way.

If you are a developer, agency owner, or business owner who wants the raw performance of DigitalOcean but doesn’t want to act as a full-time system administrator, using Cloudways is the perfect middle-ground. Cloudways completely automates the time-consuming LEMP stack installation, database security, and Nginx configurations we just set up manually.

Prerequisites

For this method, I get to skip the Command Prompt and manual SSH commands entirely for the setup phase. All I need is:

  • A Cloudways Account: We offer a 3-day free trial (no credit card required), which is perfect for testing.

Step 1: Select Your PHP Application

Once I log into my Cloudways dashboard, I’ll click the Launch Now (or + Add Server) button.

Launch a server on Cloudways

This brings me to the server configuration screen.

First, I need to tell Cloudways what kind of environment I want to spin up. Under the Application & Server Details section, I’ll open the dropdown menu and select Custom App (PHP).

I’ll also give my managed app and server recognizable names, like My-PHP-App and DigitalOcean-Web-Server.

Select Custom PHP App and Name Server

Step 2: Choose DigitalOcean & Configure Specs

Next, I need to configure exactly how my server will run. The Cloudways dashboard makes this incredibly straightforward:

  • Application Stack: Cloudways now gives me the option to choose my server’s architecture. I’ll leave it on the pre-selected Lightning Stack, which is a fast, Nginx-focused setup with built-in caching. (If you want to know why this is the recommended default, check out our announcement blog on the new Lightning Stack).

Select Cloudways Lightning Stack

  • Select your Server & Database: Under the cloud provider options, I’ll click the DigitalOcean logo. Right below that, I can also select my preferred Database Type to ensure it aligns perfectly with my custom PHP app’s compatibility.

Choose DigitalOcean and Select Database Type

Now, I’ll configure the server’s compute resources, making sure I have the right amount of CPU and RAM for my app:

  • Server Type: I can choose between Basic (cost-effective for small sites), General Purpose (dedicated CPU for growing sites), or CPU Optimized (for high-traffic or media-heavy apps). Since this is a brand-new application, a Basic or General Purpose server is plenty of power to start.

Choose server type and scale size

  • Server Size: I’ll use the slider to select my specific RAM and CPU limits. The best part is I can instantly scale this slider up later if my app’s traffic spikes.
  • Location: Just like in the manual method, I’ll choose a data center location (like New York) that is geographically closest to my target audience for optimal loading speeds.

Select Cloudways Data Center Location

Step 3: Launch the Server

At the bottom of the screen, Cloudways shows me exactly what my estimated hourly and monthly costs will be. With everything looking good, I’ll click the Launch Now button.

Launch Now button with pricing

And… that’s it!

I don’t need to touch a single command-line interface. I’ll just wait a few minutes while Cloudways provisions the DigitalOcean Droplet, installs the latest Nginx and PHP packages, configures the firewalls, and secures my MySQL database in the background.

Step 4: Verify the PHP Installation (The Easy Way)

Once my server is ready, I’ll go ahead and set it so that it too displays the PHP info page we saw in the manual method.

Server deployment completing in Cloudways

I’ll click on the Applications tab in the top menu and select the PHP app I just created. This takes me to the Access Details screen, which is essentially the control panel for this specific application.

Navigating to Applications in Cloudways

Under the “Application URL” section, Cloudways has already generated a temporary live web address for me.

Cloudways temporary application URL

If I click this URL right now, it takes me to the default Cloudways PHP welcome page, which simply displays a list of supported frameworks and CMSs to prove the server is live.

Default Cloudways Application Welcome Page

But since I want to view the actual PHP info page just like we did in Method 1, I’ll use the built-in Cloudways SSH terminal to quickly create that test file:

  • I’ll launch the SSH Terminal from the Master Credentials tab.

Launch SSH Terminal from Cloudways Master Credentials

  • To log in, I’ll use the Username and Password from the Master Credentials tab.

Enter Master Credentials into SSH Terminal

  • I’ll navigate to my application’s public HTML folder using the cd (change directory) command along with my specific application folder name (which in my case is ppmvhjyyae):

cd applications/ppmvhjyyae/public_html

  • I’ll create that exact same info.php test file using one quick command:

echo "<?php phpinfo(); ?>" > info.php

This will create the file.

Now, when I click my live Application URL and add /info.php to the end of it, I can look at the exact same PHP configuration screen that took me nearly a dozen manual steps to achieve in Method 1. And with that, My DigitalOcean PHP server is live, fully secured, and ready for code.

PHP configuration successful view via Cloudways

After you’re done testing, just like we did in the manual method, make sure to delete the test file by running rm info.php in the Cloudways SSH terminal terminal.

Manage Your DigitalOcean PHP Servers With Ease

Get the raw performance of a DigitalOcean Droplet combined with built-in PHP configuration tools, automated backups, and 1-click scaling.

Why Host PHP Apps on DigitalOcean Using Cloudways

We just walked through both methods, and it’s pretty obvious which one is the more streamlined approach. But the benefits of using Cloudways to host your DigitalOcean server go well beyond just saving time during the initial setup.

Here are a few practical reasons why you might want to take the managed route for your PHP applications:

Latest PHP Versions

Cloudways supports the most recent PHP versions, including PHP 8.2, 8.3, and 8.4. Instead of manually updating packages via the command line, you can upgrade or downgrade your server’s active PHP version directly from the dashboard.

PHP Version Supported Applications
8.2 WordPress 5.6+
Laravel 6.20+
8.3 WordPress 5.6+
Laravel 10.x+
8.4 WordPress 6.x+
Laravel 11.x+

Upgrade PHP version easily in Cloudways

PHP Worker Control

Instead of digging into terminal configurations, you can dynamically adjust the number of active PHP workers directly in the user interface. Once you establish a baseline for your application’s traffic volume, easily scaling these workers helps prevent your app from bottlenecking under heavy load.

PHP Memory Limits

Changing memory limits usually requires SSH access to manually edit your php.ini file. The managed dashboard gives you a clean interface to modify these basic PHP settings directly, saving you time during deployment and troubleshooting.

Adjust PHP Memory Limits from dashboard

Automated Backups and Restores

You get a straightforward console to manage backup frequencies and execute manual restores. Cloudways automatically stores these backups off-site, which adds an essential layer of redundancy without requiring you to write custom cron jobs. You can learn more about how to back up an entire WordPress website in our detailed guide.

Schedule automated backups for your application

Server and Application Cloning

If you need to test version compatibility or verify new server resources, you can clone an entire application or server directly from the panel. This makes spinning up a staging environment significantly faster than migrating files and databases manually.

Clone a server easily in Cloudways

Clone an application directly from the panel

Cloudflare Enterprise Integration

Setting up a CDN and web application firewall from scratch takes time. Cloudways includes a native Cloudflare Enterprise integration that routes your traffic through their global network for edge caching and DDoS protection. Instead of paying thousands for a direct enterprise contract, the Cloudflare Enterprise pricing on Cloudways starts at $4.99/month per domain, and drops as low as $1.99/month if you host multiple sites.

Enable Cloudflare Enterprise add-on

Wrapping Up

You now have two clear ways to host a PHP application on DigitalOcean.

If you prefer full control and do not mind working in the terminal, setting up a Droplet and configuring the LEMP stack manually gives you a solid, hands on foundation. You manage every component yourself and understand exactly how your server is structured.

If you would rather avoid server level configuration and focus more on your application code, using a managed platform simplifies the setup and ongoing maintenance.

Both approaches are valid. The right choice depends on your technical comfort level, the time you can dedicate to server management, and how much control you want over your environment.

If you have any questions or need help, let us know in the comments.

Q1. How do I migrate an existing PHP website to DigitalOcean via Cloudways?

Launch a DigitalOcean server on Cloudways and create a new PHP application. Next, upload your existing files via SFTP/SSH, import your database, update your application’s database credentials, and point your domain’s DNS to the new server IP.

Q2. Does DigitalOcean support PHP?

Yes, DigitalOcean fully supports PHP. Its Droplets provide the raw Linux environments needed to install any PHP version, framework, or web server stack your application requires.

Q3. How do I upgrade my PHP version on Cloudways?

Navigate to Server Management > Settings & Packages in your Cloudways dashboard. Under the Packages tab, select your desired PHP version and click save. The system will automatically update the packages and restart your web server.

Q4. Which web servers run PHP?

PHP runs on all major web servers. It is most commonly paired with Apache or Nginx on Linux distributions, but it is also compatible with IIS on Windows environments.

Q5. How do I install PHP on an Ubuntu DigitalOcean Droplet?

Access your Droplet via SSH and update your packages using sudo apt update. Then, run sudo apt install php to install the base package, or use sudo apt install php-[extension-name] to add any specific extensions your app needs.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour