October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Install WordPress on Ubuntu With Nginx or Apache (2026 Guide)

Set up WordPress on Ubuntu with the supported PHP and database versions, configure Apache or Nginx, create a dedicated database user, enable HTTPS, and troubleshoot common installation failures.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can run WordPress on Ubuntu with either Apache or Nginx. The complete installation consists of preparing a supported PHP and database stack, downloading the current WordPress archive from WordPress.org, configuring the web server, creating a dedicated MySQL or MariaDB database account, enabling HTTPS, and finishing the browser-based installer.

WordPress currently recommends PHP 8.3 or newer, MariaDB 10.11 or newer or MySQL 8.0 or newer, and HTTPS. Apache is the fully documented route in Ubuntu’s official walkthrough; Nginx is equally supported but requires an explicit PHP-FPM socket and server-block configuration.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What you need before installing

Use a supported Ubuntu Server release on a host where you have shell access and sudo privileges. The commands below assume a fresh server and a site name such as example.com; replace that name with your real DNS name or local hostname.

Component Requirement and why it matters
Ubuntu A supported Ubuntu Server release with package updates enabled.
Web server Apache HTTP Server or Nginx. WordPress describes both as robust, featureful choices.
PHP PHP 8.3 or greater is the current WordPress recommendation. Install the matching database connector and extensions required by your site.
Database MariaDB 10.11 or greater or MySQL 8.0 or greater, with a separate database and account for the site.
Network and DNS A DNS record or local hostname that resolves to the server, plus firewall rules allowing web traffic.
HTTPS A valid certificate and automatic renewal plan before treating the site as production.
Administration tools A text editor and shell-based file transfer. FTP is optional when you deploy over SSH.

Check the exact PHP version supplied by your Ubuntu release before you begin. If the distribution does not provide a supported version, resolve that packaging decision first rather than silently deploying an obsolete PHP runtime.

Apache or Nginx: which path should you choose?

Choose the server whose conventions you already operate. There is no universal performance winner for every WordPress workload, and no authoritative benchmark establishes one for this exact Ubuntu deployment.

Decision point Apache Nginx
Configuration model Site files in /etc/apache2/sites-available, enabled with a2ensite. Server blocks, commonly under /etc/nginx/sites-available, linked into sites-enabled.
URL rewriting The rewrite module and WordPress’s .htaccess rules can be used when directory overrides are allowed. Routing is declared directly with try_files in the server block; Nginx does not read .htaccess.
PHP connection Use the PHP integration provided by the Ubuntu packages and your chosen Apache setup. Pass requests to the installed PHP-FPM socket or upstream; the socket name varies with the PHP version.
Best operational fit A natural choice if your team follows the Ubuntu Apache tutorial or already manages Apache sites. A natural choice if the rest of your fleet uses Nginx and PHP-FPM.

Prepare Ubuntu and install the common software

1. Update package indexes

Start with current package metadata and security updates:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt upgrade

Reboot if the upgrade requests it, then reconnect over SSH.

2. Install PHP, the database connector, and extensions

Install the web server you selected along with PHP and the extensions used by the Ubuntu WordPress walkthrough. The package names below follow Ubuntu’s versioned PHP metapackages; verify availability with apt policy on your release.

# Apache path
sudo apt install apache2 php php-mysql php-curl php-imagick php-intl php-mbstring php-xml php-zip php-bcmath

# Nginx path instead of Apache
sudo apt install nginx php-fpm php-mysql php-curl php-imagick php-intl php-mbstring php-xml php-zip php-bcmath

bcmath is included where the application stack needs it. Keep the PHP-FPM package and the PHP command-line version aligned; a mismatched FPM socket is a common cause of Nginx errors.

3. Create a web root and obtain WordPress

Create a dedicated location rather than placing the site in a personal home directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo mkdir -p /srv/www
cd /tmp

Download the latest stable archive from WordPress.org using your preferred shell transfer method, then extract it into /srv/www. The resulting directory in the Ubuntu example is /srv/www/wordpress. If you download as an administrator, inspect the extracted ownership and permissions before the site is exposed publicly.

sudo tar -xzf latest.tar.gz -C /srv/www
sudo chown -R $USER:$USER /srv/www/wordpress

The second command is only an example of retaining deployment ownership. Do not blindly make the entire tree owned and writable by www-data; that can be unsafe when several sites or maintainers share the host. Grant the web process only the write access the application actually needs, usually in selected upload or cache paths.

Configure Apache for WordPress

Apache is the route covered by Ubuntu’s official walkthrough. The following virtual host gives WordPress a document root, a default PHP index, access to the directory, and the override permissions needed for its rewrite rules.

1. Create the virtual-host file

sudo editor /etc/apache2/sites-available/wordpress.conf

Insert a block like this, replacing the server name and path if you used different values:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /srv/www/wordpress

    DirectoryIndex index.php

    <Directory /srv/www/wordpress>
        AllowOverride FileInfo Options
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
    CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>

AllowOverride FileInfo Options permits the rewrite-related settings WordPress writes to .htaccess without making unrelated server configuration editable from the site directory. If your security policy forbids overrides, translate the generated WordPress rules into the virtual host instead.

2. Enable the site and rewrite module

sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo a2dissite 000-default.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

apache2ctl configtest must report a valid configuration before reloading. Keep the default site enabled only when you deliberately want it to answer unmatched hostnames.

3. Check the service

systemctl status apache2 --no-pager
ss -ltnp | grep ':80'

If Apache fails to start, inspect the error log named in the virtual host and run apache2ctl configtest again. Typical causes are a misspelled directive, a duplicate listener, or a path that does not exist.

Configure Nginx with PHP-FPM

Nginx uses the same WordPress files, database, and HTTPS plan, but it does not process Apache’s .htaccess. You must express the front-controller routing and PHP handoff in the server block.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. Find the installed PHP-FPM socket

ls -l /run/php/

Look for the socket belonging to the installed PHP version, such as php8.3-fpm.sock. Do not copy a version number from another server: the socket path must match the package actually installed on this Ubuntu host.

2. Create the server block

sudo editor /etc/nginx/sites-available/wordpress

Use a block equivalent to the following and replace the hostname, root, and socket path:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    root /srv/www/wordpress;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

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

    location ~ /.ht {
        deny all;
    }
}

The try_files rule serves existing files and sends WordPress permalinks to index.php. The PHP location must include the distribution’s FastCGI parameters and point to the live FPM socket. Confirm directive syntax against the Nginx and PHP-FPM package documentation for your Ubuntu and PHP versions before production use.

3. Enable the site and reload Nginx

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx
sudo systemctl enable --now php8.3-fpm

Change php8.3-fpm to the service name installed on your host. If nginx -t reports an unknown socket or directive, fix that configuration before reloading.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create a dedicated database and account

WordPress stores posts, users, settings, and plugin data in MySQL or MariaDB. A separate database and least-privilege account makes backups, migration, and incident response safer than sharing an administrator login.

1. Open the database client as an administrator

sudo mysql

2. Create the database and user

Use a unique database name, username, and long random password. The following example grants access only to this site’s database:

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_site'@'localhost' IDENTIFIED BY 'replace-with-a-long-random-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_site'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Do not reuse the database administrator password in the WordPress installer. If the database is remote, replace localhost with the permitted source host and restrict firewall access accordingly.

Shared database considerations

Separate databases are preferable for separate installations. When multiple WordPress sites must share one database, assign every installation a different table prefix in its wp-config.php; otherwise tables can collide. A unique prefix is not a substitute for separate credentials and careful backup boundaries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the browser installer

  1. Point the DNS record or local hostname at the server’s address. Confirm that the hostname resolves from the client where you will open the installer.
  2. Visit the hostname over HTTP for the initial setup if HTTPS is not configured yet. WordPress should display its language and database setup screen rather than a directory listing or server welcome page.
  3. Enter the database name, database username, database password, and database host. For the local account above, the host is normally localhost.
  4. Choose a site title, an administrator username that is not simply “admin,” a unique administrator password, and an email address you monitor.
  5. Complete the installation, sign in, and immediately confirm that the dashboard, media upload, and a sample permalink work.

During setup WordPress writes wp-config.php, which contains the core database connection settings. Protect this file with filesystem permissions and server rules; it should never be downloadable as plain text.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Enable HTTPS before launch

HTTPS protects administrator credentials, session cookies, and visitors’ traffic. Set DNS first, obtain a certificate through your chosen certificate authority or hosting control plane, and configure the web server to redirect HTTP to HTTPS. Enable automatic renewal and test renewal before the first certificate expires.

After HTTPS works, verify that the WordPress Address and Site Address use the HTTPS scheme, that media and theme assets load without mixed-content warnings, and that both the bare hostname and any intended www alias reach the same canonical site. Keep port 80 available when your renewal method needs an HTTP challenge.

Permissions and hardening decisions

Keep ownership intentional

The Ubuntu tutorial warns that assigning the whole WordPress tree to www-data can be insecure on a host with multiple sites or maintainers. Prefer a per-site deployment owner, a controlled group for the web process, and narrowly scoped write permissions for uploads and caches. Review permissions after installing plugins because some installers attempt to make additional directories writable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Protect configuration and administration

  • Keep wp-config.php readable by the PHP process but not broadly writable or downloadable.
  • Use separate Unix and database identities for separate sites where practical.
  • Limit SSH and database ports with the firewall; expose only the services your architecture requires.
  • Use strong, unique administrator and database passwords and enable any available multifactor protection.
  • Remove unused themes, plugins, sample content, and default virtual hosts.

Patch every layer

Keep Ubuntu, Apache or Nginx, PHP, MySQL or MariaDB, WordPress core, themes, and plugins patched. Before upgrades, back up both the database and uploaded files. A file-only backup cannot restore posts and settings, while a database-only backup cannot restore media.

Verify the installation after first login

  • Open the home page, an individual post, a category archive, and a nonexistent URL. All should use the intended hostname and HTTPS.
  • Upload an image larger than a thumbnail and confirm it appears in the Media Library. If it fails, inspect PHP upload limits and available disk space.
  • Visit Settings → Permalinks and save the chosen structure once. Test a fresh permalink afterward.
  • Check that scheduled posts and maintenance tasks run. WordPress’s pseudo-cron depends on visits unless you configure a real system cron job.
  • Confirm DNS records, firewall rules, certificate renewal, system time, and log rotation.
  • Take a test backup and verify that you can restore it to a non-production location.

Troubleshooting common failures

The browser shows the wrong site or a default page

DNS may still point elsewhere, or the default Apache/Nginx site may be answering first. Check the hostname’s resolved address, confirm the ServerName or server_name, and disable the default site when it is not needed. Reload only after the configuration test passes.

Nginx returns 502 Bad Gateway

This almost always means Nginx cannot reach PHP-FPM. Verify that the FPM service is running, list /run/php/, and make the fastcgi_pass socket exactly match the installed version. Check the Nginx error log and PHP-FPM journal for permission or startup errors.

Apache returns a 500 error after enabling permalinks

Run apache2ctl configtest, confirm that a2enmod rewrite was executed, and check that the WordPress directory allows the required FileInfo and Options overrides. Inspect the virtual-host error log for the specific directive or permission failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

WordPress cannot connect to the database

Recheck the four installer values: database name, username, password, and host. Test the account from the server with the MySQL client, verify that the database service is running, and confirm that the account’s host component matches the connection source. Do not solve an authentication error by using the database administrator account.

Uploads fail or exceed the size limit

Check PHP’s effective upload_max_filesize and post_max_size, the web server request-size limit, available disk space, and write permission on the uploads directory. After changing PHP settings, restart or reload the relevant PHP-FPM or Apache service and test from the dashboard again.

The site works on the server but not from the Internet

Confirm the public DNS record, cloud or host firewall, Ubuntu firewall rules, router forwarding if applicable, and that Apache or Nginx is listening on the public interface. Certificate issuance also requires the certificate authority to reach the expected hostname and challenge port.

Apache versus Nginx: practical decision checklist

  • Choose Apache when you want to follow Ubuntu’s documented WordPress sequence, manage per-directory overrides, or already operate Apache modules and site files.
  • Choose Nginx when your fleet standardizes on server blocks and PHP-FPM, and you are comfortable maintaining routing and socket paths explicitly.
  • Choose neither on the basis of an assumed speed advantage. Measure your own PHP version, plugins, caching layer, traffic pattern, and storage on a representative workload.
  • Whichever you choose, keep the database account dedicated, HTTPS enforced, ownership reviewed, and all software patched.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.