How to Install WordPress on Ubuntu

How to Install WordPress on Ubuntu

Getting a WordPress site ready on Ubuntu starts with setting up the server that will host it. WordPress is a PHP content management system that stores site content in a database and provides an admin interface.

This guide walks through installing WordPress on Ubuntu. It also explains what to check after setup.

TL;DR

Install Apache, PHP with its MySQL extension, and MariaDB or MySQL, then give WordPress its own database and user before unpacking the upstream WordPress archive into an Apache document root.

  • Use WordPress.org’s current requirements as the compatibility target, not an old distribution package.
  • Use a strong, unique database password and keep it separate from the WordPress administrator login.
  • Finish setup at your server’s site URL and configure HTTPS before public use.

What Is WordPress on Ubuntu?

WordPress is a PHP content management system that stores site content in a database. A LAMP stack combines Linux, Apache, PHP and MySQL or MariaDB: Apache handles browser requests, PHP runs WordPress, and the database stores posts and settings.

Ubuntu and Debian package names can vary by release. WordPress currently recommends PHP 8.3 or newer, MariaDB 10.11 or newer or MySQL 8.0 or newer, plus HTTPS for public sites.

PartRoleWhat to verify
ApacheServes the site and routes requests to PHPIts document root points to WordPress
PHPRuns WordPress codeThe web-server PHP module and database extension are installed
MariaDB or MySQLStores WordPress contentA dedicated database and local user exist
WordPressSite application and admin interfaceBrowser installer can connect to the database

How to Install WordPress on Ubuntu Step by Step

Use a server you administer and a non-root account with administrative privileges. For public hosting, point a DNS name to the server. Review paths and replace example values before running these state-changing commands on your own Ubuntu or Debian server.

Step 1: Install Apache, PHP and database packages

Install Apache, MariaDB, PHP’s Apache module and its database extension. Add extensions required by your themes or plugins, using package names for your release, and review proposed package changes.

sudo apt update
sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql

Step 2: Create a database and restricted user

Log in to MariaDB or MySQL with your distribution’s administrative method. Create a database and a dedicated account.

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

Replace the example with a generated password and keep it separate from the WordPress admin password.

Step 3: Download and place WordPress files

Download and extract WordPress.org’s current archive, then place its files in the intended web root. This example uses /var/www/wordpress. Avoid overwriting another site’s files.

cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo install -d -o www-data -g www-data /var/www/wordpress
sudo cp -a wordpress/. /var/www/wordpress/

For multiple sites or maintainers, a per-site system user and separate PHP-FPM pool provide stronger isolation than shared www-data ownership.

Step 4: Configure Apache for the site

Set up an Apache virtual host for your domain and /var/www/wordpress. Allow WordPress rewrite rules, then enable the site and rewrite module.

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/wordpress
    <Directory /var/www/wordpress>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
sudo a2enmod rewrite
sudo a2ensite wordpress.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

Replace example.com and save this as a site file in Apache’s sites-available directory. Its DNS A or AAAA record must point to the server. If Apache’s default page appears, check the enabled virtual host and its ServerName.

Step 5: Complete WordPress in a browser

Open the domain or address for the virtual host. The installer requests site, administrator and database details.

Enter database wordpress, user wp_user, its password and host localhost. The installer can create wp-config.php if the web-server user can write the directory. Otherwise copy wp-config-sample.php and set the database values yourself.

Choose a separate administrator username and strong password, then sign in at /wp-admin/ and confirm the dashboard loads.

What Should You Check After Installation?

If the site fails, use the symptom to identify whether HTTP routing, PHP execution or database access needs attention before changing permissions.

SymptomCheckNext action
Apache default page or wrong siteHostname, enabled virtual host and DocumentRootCorrect ServerName or document root, then test the Apache configuration
PHP source appears in the browserApache PHP module and PHP handlerInstall or enable the PHP module and reload Apache after a valid config test
Database connection errorDatabase service, DB_NAME, DB_USER, DB_PASSWORD and DB_HOSTConfirm the user exists at localhost and has rights on the named database
Pretty links return 404Apache rewrite module and AllowOverrideEnable rewrite support and check the site’s permalink configuration
  • Enable HTTPS and redirect public traffic to the secure URL before entering admin credentials.
  • Back up both the WordPress files and database before updates or permission changes.
  • Use Nginx only with a matching PHP-FPM and server-block configuration. Apache directives above do not configure Nginx.

For follow-up server setup, see our LAMP stack guide, the Apache installation guide, and the MySQL guide for Debian and Ubuntu. The chown guide explains file ownership, and the cp guide covers copying files safely.

Conclusion

Keep Apache’s document root, WordPress files and database settings aligned to the same site.

Use WordPress’s current requirements and its official installation guide when adapting this process to another distribution release or deployment model.

FAQ

These answers cover the common setup choices that change the installation path.

Can I install WordPress on Ubuntu Server?

Yes. Install a web server, PHP with its database extension, and MySQL or MariaDB, then configure WordPress for the server’s hostname and document root.

Can I use Nginx instead of Apache?

Yes. WordPress supports Nginx, but Apache virtual-host directives and rewrite configuration do not apply. Configure Nginx with PHP-FPM and an appropriate server block.

How do I check whether WordPress is installed?

Open the site’s configured URL and check whether the WordPress page loads. For administrator access, visit /wp-admin/. If PHP source appears or the database connection fails, check the PHP handler or database credentials respectively.