Setting Up an Ubuntu Server: Step by Step to a Secure Setup

Titelbild: Ubuntu Server einrichten: Schritt für Schritt zum sicheren Setup

When you set up an Ubuntu server for WordPress, you are choosing the most popular Linux foundation for production websites—and for good reason: thorough documentation, five years of security updates per LTS release, and a huge community. This practical guide leads you step by step to a hardened, fast setup—from the first SSH login to a production-ready web stack with HTTPS, monitoring, and off-site backups.

A fresh Ubuntu server is a blank slate. It contains only the bare essentials, and everything else is up to you. That is an advantage, because nothing unnecessary runs in the background. But it is also a responsibility: anyone who puts a new cloud server online unprepared is often scanned by automated bots for open SSH ports and default logins within just a few minutes. That is why the right setup sequence matters.

In this article we show how to set up an Ubuntu server and secure it. It builds on the general overview in the article Setting up a Linux server and goes into more detail on Ubuntu. If you want to hand the work over, take a look at our offer Set up server and VPS page.

Which Ubuntu version should you choose?

Every two years Ubuntu releases a version with long-term support (LTS) that receives security updates for five years. For production WordPress servers, you should always choose a current LTS version, such as 24.04 LTS or 26.04 LTS. The interim versions only receive updates for about nine months and are unsuitable for production sites. Before choosing, check until when the version is supported, and plan the switch in good time before the end.

Requirements

  • A VPS or root server with Ubuntu Server LTS
  • At least 2 GB RAM for WordPress, better 4 GB
  • Access via SSH, ideally with a key
  • A domain whose DNS points to the server IP
  • About one to two hours for the basic setup
Infographic: Setting up an Ubuntu server securely
Click to enlarge
Ubuntu Server sicher einrichten: Beitragsbild

Step 1: First login and system update

Log in via SSH. The first step is always updating the packages: sudo apt update and then sudo apt upgrade. If a new kernel was installed, restart the server. Then set the time zone with timedatectl (for example, timedatectl set-timezone Europe/Berlin) so that logs, backups, and WP-Cron jobs run at the right local time. This seems unremarkable, but saves you confusion later when reading logs.

Long row of server cabinets in a data center

Step 2: Create a sudo user

Do not work as root permanently. Create a new user with adduser along with a strong password, grant administrative privileges with usermod -aG sudo, and test logging in with this user in a second terminal. Only when that works do you continue. This step is the basis for being able to disable root login later.

Step 3: Set up SSH keys and harden SSH

Generate a key pair on your computer and copy the public key to the server with ssh-copy-id. Then you edit the file /etc/ssh/sshd_config and set PasswordAuthentication to no, PermitRootLogin to no and optionally AllowUsers to your user. Reload the service and test the login in a second window before you close the old session.

Optional: change the SSH port

A port other than 22 reduces the noise in the logs, but is not real security. Keys and Fail2ban are more important. If you change the port, adjust the firewall accordingly before you reload the service.

Step 4: Enable the firewall with UFW

Ubuntu comes with UFW, the Uncomplicated Firewall. Set the default rules to deny incoming, allow outgoing. Allow SSH first, then HTTP and HTTPS, and only then enable the firewall. Otherwise you lock yourself out. With ufw status you check the rules. In addition, you should, if possible, use a cloud firewall at the provider, as described in the article Cloud firewall describes.

USB stick on a laptop on a dark desk

Step 5: Fail2ban against brute force

Fail2ban reads log files and blocks IP addresses that repeatedly fail logins. Install the package, copy the default configuration into a local file and enable the SSH jail. Typical values are three to five failed attempts within ten minutes and a ban of at least one hour. For WordPress you can add additional rules for wp-login.php later.

Step 6: Automatic security updates

Install unattended-upgrades and enable it with dpkg-reconfigure. This way security patches are installed automatically. Decide whether the server may restart automatically if needed, and if applicable set a time window at night. Add an email notification so that you can see what was changed.

Step 7: Web server, PHP and database

For WordPress you need three components:

  • Web server: Nginx is lean and fast, Apache is flexible and widespread. Both work very well.
  • PHP: Install PHP-FPM in a currently supported version (such as PHP 8.3 or 8.4) along with the extensions WordPress needs, including php-mysql, curl, gd, imagick, intl, mbstring, xml, and zip.
  • Database: MariaDB or MySQL. Run mysql_secure_installation, bind the service to localhost (127.0.0.1), and create a dedicated database and user for the site.

Adjust key PHP settings in php.ini—proven starting values are memory_limit = 256M, upload_max_filesize = 64M, post_max_size = 64M, and max_execution_time = 120. Also enable Opcache, which noticeably improves performance. Check the configuration after each step with the respective test command before you reload the service.

Step 8: Install WordPress

  1. If not already done in the previous step: create a dedicated database and database user with strong credentials.
  2. Download WordPress, unpack it and put it in the web directory.
  3. Set the file owner to the web server user (typically www-data on Ubuntu) and apply proper permissions: 755 for directories and 644 for files.
  4. Adjust wp-config.php and enter unique keys (salts).
  5. Configure the web server for the domain.
  6. Complete the installation in the browser.

Instead of doing everything by hand, you can also use a management panel such as Plesk. How that works is described in the article Installing Plesk. That saves time, but brings additional software with its own updates.

Step 9: HTTPS with Let’s Encrypt

Install Certbot and request a certificate for your domain. Enable the automatic redirect from HTTP to HTTPS and test automatic renewal with a dry run. Certificates expire after about 90 days, and a renewal that does not work is a classic reason for sudden warning pages in the browser.

Step 10: Set up backups

A WordPress backup consists of files and database. Back up both regularly and store them in a different place than the server, for example in external object storage. Add snapshots of the entire server if your provider offers them. Test the restoration at least once before you need it. What this looks like for WordPress is described on our page on Backups.

Step 11: Monitoring and logs

Right after going live, set up an external uptime check that pings your domain every few minutes and alerts you by email or push notification in case of an outage. Also monitor disk space, RAM, and CPU load with a lightweight monitoring tool (such as Netdata or Prometheus), while Logrotate ensures log files do not fill up your disk. Occasionally look at the access and error logs to recognize unusual patterns.

Security checklist for Ubuntu

  1. LTS version, system up to date
  2. Own sudo user, root login disabled
  3. SSH only with key
  4. UFW active, only necessary ports open
  5. Fail2ban running
  6. Automatic security updates active
  7. Database only reachable locally
  8. HTTPS with automatic renewal
  9. Backups external and tested
  10. Monitoring with notification

Common mistakes in Ubuntu server setup

  • Firewall enabled, SSH forgotten: You lock yourself out. Always allow SSH first.
  • File permissions set to 777: Convenient, but a big security risk.
  • Database publicly reachable: The database port should only listen locally.
  • Backups not tested: A backup that has never been restored is only a hope.
  • Unnecessary services: Switch off everything that is not needed, or do not install it in the first place.
  • No plan for end of support: Switch to the next LTS at the latest half a year before.

Set it up yourself or have it set up?

Setting up an Ubuntu server yourself is a great project if you want to learn and the site is not business-critical. For production sites, setup by professionals is usually the better choice, because the configuration is right from the start. With ongoing care you can concentrate on your content. Our maintenance package costs $99 a month, managed hosting starts at $21 a month. We are happy to discuss which variant fits in the free check.

Additional knowledge: running an Ubuntu server day to day

The basic setup is done, but a server lives on. The following sections show what you should pay attention to in ongoing operation so that your system stays secure and fast in the long run.

Plan updates properly

Security updates run automatically, everything else you should carry out deliberately. Plan a maintenance window once a month in which you update packages, perform restarts and then test the site. Create a snapshot of the server before larger updates. That way, if there are problems, you can return to the previous state with a few clicks. Pay special attention to PHP versions: switching to a newer version brings speed and security, but can break old plugins. So test beforehand in a staging environment. What this looks like for WordPress itself, we have described in the article on safe WordPress updates describes.

Measure and improve performance

A server is only as good as its configuration. Typical adjustments for WordPress on Ubuntu are:

  • PHP-FPM: The number of processes (pm.max_children) should match the available memory. Too many processes lead to swapping, too few to long waiting times.
  • Opcache: Keeps compiled PHP code in memory and saves computing time with every request.
  • Database: With the InnoDB buffer pool you determine how much data stays in RAM. Moderate values are enough for small servers.
  • Caching: A page cache at server or plugin level relieves PHP and the database considerably.
  • Compression and HTTP/2: Gzip or Brotli and modern protocols reduce transfer time.

Measure the effect with real values: response time of the home page, utilization with simultaneous visitors and the Core Web Vitals. Our Pagespeed Boost.

Several sites on one server

If you run several WordPress sites on one server, you should separate them from each other. Each site gets its own system user, its own directory, its own PHP-FPM pool and its own database. That way a hacked site cannot automatically access the others. Resources can also be limited per site. Management panels such as Plesk take this separation partly off your hands.

Typical disruptions and how to find them

  • 502 Bad Gateway: PHP-FPM is not running or is overloaded. Check service status and error log.
  • Database error when establishing the connection: Database service stopped, often due to lack of memory. Check logs and free memory.
  • Site very slow: CPU or RAM full, a plugin causes load or a bot attack is running. Look at the access logs.
  • Certificate warning: Renewal failed. Check the Certbot log and renew manually.
  • Disk full: Clean up old logs, backups and cache files and set up rotation.

If a WordPress error occurs, our article on the critical error often helps.

Realistically assessing costs and effort

A small VPS starts at around $5 to $11 a month, while a more powerful server for WooCommerce or high traffic quickly costs $25 to $65 monthly. On top of that comes your own time or the time of a service provider for setup and maintenance. Do the math honestly: if you spend at least two hours a month on updates, checks, and backups, a maintenance package for $99 a month is often cheaper than your own working time. For many smaller sites, managed hosting starting at $21 a month is also more economical because server administration is completely taken off your plate. The best solution depends on your needs, not on a principle.

When switching is worthwhile

Running your own Ubuntu server is worthwhile if you want to consolidate multiple projects, need custom software such as Redis or background workers, or are hitting the performance limits of shared hosting. It is less worthwhile if you only run one site and have no desire for administration. Decide on the basis of three questions: do I need the additional control? Do I have the knowledge or someone who has it? How expensive would an outage be? If you answer the first question with no, managed hosting is usually better. You can find more on this in the article Managed WordPress hosting and on the page on the topic of server and hosting.

Additional hardening: further useful measures

After the basic setup you can secure the server further without making it unnecessarily complicated.

  • Check services: With ss or netstat you check which services listen on which ports. Switch off everything that is not needed.
  • Kernel parameters: Some sysctl settings reduce the attack surface, such as ignoring source routing and broadcast pings as well as protection against SYN flooding.
  • AppArmor: Ubuntu comes with this access control system. Leave it active, it limits what services can do in the event of an attack.
  • Auditd or similar tools: Log security-relevant events such as changes to system files.
  • Rootkit and malware scans: Tools like rkhunter or ClamAV regularly check for known threats.
  • Two-factor login for SSH: With additional PAM modules you can require a second factor.
  • Separate service accounts: Every service runs under its own user with minimal rights.

Understanding logs: where to look

When something does not work, log files help with troubleshooting. The most important places on Ubuntu: /var/log/auth.log contains login attempts, /var/log/syslog general system messages, /var/log/nginx or /var/log/apache2 access and error logs of the web server, and the PHP-FPM logs show errors in the application. With journalctl you read the logs of the system services. In an outage you first check whether the service is running (systemctl status), then the error log and finally the system resources. Many problems can be narrowed down this way in a few minutes. Anyone who regularly looks at the logs also recognizes unusual patterns early, such as many requests to wp-login.php or xmlrpc.php.

WordPress-specific hardening at server level

  • Protect wp-config.php: Place the file outside the web root or with strict permissions, forbid access via the web server.
  • Disable file editing: With the constant DISALLOW_FILE_EDIT you prevent editing of code in the backend.
  • Restrict xmlrpc.php: If you do not need the interface, block it at server level.
  • Secure the login: Limiting login attempts, two-factor authentication, changed login URL optional.
  • Secure uploads: Strictly block the execution of PHP files inside the wp-content/uploads directory via Nginx or Apache rules.
  • Database prefix and user: Separate database users with minimal rights per site.

You can find further measures in our Security package.

Testing and acceptance: is the server really finished?

Before you take a site into production, you should check the setup systematically. Run a port scan from outside to see whether only 80, 443 and possibly a restricted SSH port are open. Test the SSL configuration with an online test for protocols and encryption. Check whether HTTP redirects to HTTPS and whether the security headers are set. Make sure automatic updates run and restarts work. Restore a backup as a test, and simulate an outage to see whether monitoring notifies you. Store the results in documentation with IP addresses, users, services, versions, backup plan and contacts. This documentation is the key for operation and for switching.

Ongoing operation: updates and monitoring after setup

Initial setup is not the end of server management. A production system only stays reliable when you establish fixed maintenance routines: review logs and resource usage weekly, apply package updates monthly, and test a real backup restore every quarter.

Do not rely blindly on one-time automation: regularly verify the status of unattended-upgrades and check for pending kernel reboots (for example via /var/run/reboot-required). You should always carry out major release upgrades deliberately after creating a fresh snapshot.

Add simple monitoring to the setup. These building blocks make sense:

  • An uptime monitor that warns you of outages by email
  • Fail2ban, which automatically blocks repeated login attempts
  • Regular review of log files for suspicious access
  • A warning when disk space is low or load is high

Also check every few months whether the backups work and whether users or services you no longer need can be removed. Every open port and every unnecessary account enlarges the attack surface.

If you do not want to run the server yourself, you can hand these tasks over to us. We take care of updates, monitoring and backups so that your website stays reliably available.

Conclusion

A secure Ubuntu setup follows a clear sequence: update, create a user, harden SSH, enable firewall and Fail2ban, install the web stack, set up HTTPS, add backups and monitoring. If you keep to this order, you have a stable foundation for WordPress. If you would rather hand over the setup, we are happy to help: Set up server and VPS.

Fingers on a lit keyboard with a glowing terminal

Frequently asked questions about setting up an Ubuntu server

Which Ubuntu version is suitable for WordPress?

A current LTS (Long-Term Support) version, such as Ubuntu 24.04 LTS or 26.04 LTS. It receives five years of standard security updates.

Is a VPS with 1 GB RAM enough?

For very small sites this can work, but at least 2 GB, better 4 GB, is recommended so that PHP, database and cache have enough room.

Nginx or Apache?

Both are suitable. Nginx is resource-friendly, Apache is often easier for WordPress plugins because of the .htaccess files. Decide according to your needs.

Do I need Plesk?

No, but it makes management easier, especially with several sites. For a single site, a manual setup is enough.

How do I secure the server against brute-force attacks?

With SSH keys, disabled password login, Fail2ban and a firewall.

How do I keep Ubuntu up to date?

With unattended-upgrades for security updates and regular, planned updates for everything else.

How often should I make backups?

At least once daily for websites with regular updates; for active WooCommerce stores, hourly or near-real-time database backups are recommended, always combined with off-site storage (such as S3-compatible object storage).

Can I move WordPress to another server later?

Yes, with a backup and clean planning. We take care of this as part of the WordPress migration.

What does setup by you cost?

That depends on the scope. Write to us via the Contact page, and you will get a clear offer.

How do I recognize whether my server is being attacked?

Typical signs are many failed logins in the logs, unusual load, unknown processes or unexpected file changes. Monitoring and Fail2ban help to detect this early.

Amine Boudounite

About the author

Amine Boudounite

Amin is the founder of Boudmedia and builds WordPress websites, online shops and business sites. In his guides he explains technology, loading speed and visibility so that you can apply them without any prior knowledge.

Contents
Help with your WordPress site?

We take a free look and tell you honestly what is needed and what it costs.

Share post

You might also be interested in

WordPress Backend Slow? How to Speed Up the Dashboard

Wenn das WordPress-Dashboard träge ist: Ursachen und Maßnahmen im Überblick.

Finding and Fixing a WordPress Plugin Conflict

So findest du den Plugin-Konflikt in WordPress und löst ihn ohne Datenverlust.

Google Shopping with WooCommerce: How to Make Your Feed Error-Free

Wie ein sauberer Produktfeed für Google Shopping aussieht und welche Fehler du in WooCommerce vermeiden kannst.

Problems with your WordPress site? We fix them at a fixed price.

  • Free check of your site
  • Honest assessment of what is needed
  • Fixed price before we start
  • Reply within 24 hours on business days
Scroll to Top