Whether you want to test a particular configuration or you want to self-host your website, installing a WordPress instance on Linux has lots of advantages. The good news is that it won’t cost you a dime, and once you have ironed out the process, it won’t even take you that long to go from zero to a full-blown working website running on your local network. Here’s how to get started.
Why hosting your own website?
Hosting WordPress on your own Linux server gives you maximum control, better security, custom performance tuning, scalability, and cost savings at scale—with the added benefit of gaining deeper technical expertise:
- Full control and customization: you decide the server configuration, installed software, PHP versions, caching layers, and security hardening. You will no longer be limited by shared hosting providers.
- Better security posture: you control firewalls, intrusion detection, SSH access, and patch management. It's easier to implement custom security measures like fail2ban, mod_security, or WAF rules.
- Performance optimization: you can configure Nginx/Apache, PHP-FPM, and databases (e.g., MySQL, MariaDB, PostgreSQL) for maximum speed. Use server-side caching (Varnish, Redis, Memcached) without host-imposed restrictions.
- Cost efficiency at scale: for multiple websites or high-traffic sites, running your own server can be more economical than managed hosting. You only pay for the server resources you provision (especially with VPS or bare-metal).
- Scalability and flexibility: You can resize your VPS, add load balancing, or deploy containerized environments (Docker, Kubernetes) as needed. You also have the ability to run additional services alongside WordPress (e.g., mail servers, analytics tools).
- Learning and skill development: managing your own Ubuntu server deepens your Linux, networking, and security expertise.
What you need
WordPress is a free CMS that you can download and install on your server. On Linux systems, the most popular choice is Ubuntu server with either Apache or Nginx. Here’s what you’ll need:
- A physical computer or a virtualization environment to create a virtual machine (VM), such as VirtualBox or UTM (freeware), or VMware or Parallels Desktops (paid options).
- A stable Internet connection.
For the purposes of this installation, we’ll use UTM on a Mac-native laptop, Ubuntu Server 2025, and Apache2.
Step 1 - Install Ubuntu Server
If you’re using a virtualization environment, create a VM with the latest available version of Ubuntu Server. If you’re using a physical machine, follow the bare metal instructions from this page: Bare Metal Ubuntu.
In the video below, we show you how we created the VM on UTM.
Step 2 - Install a graphical interface
The next step is to install a graphical interface on your Ubuntu server, as you will need to access the WordPress admin interface from the browser.
First, update and upgrade your newly installed Ubuntu server:
sudo apt update && sudo apt upgrade -y
Next, install the type of login manager you prefer: Ubuntu’s default is GDM and is pre-installed. In this demo, we show you how to install Slim as an alternative to GDM (the process is similar for other login managers, just change its name in the command):
sudo apt install slim
Next, we install Ubuntu desktop (our graphical interface). This might take a few minutes:
sudo apt install ubuntu-desktop
At some point during the installation, you will be asked to select the preferred login manager: as we installed Slim, that was our choice.
When the installation is complete, we reboot the system:
sudo reboot
At this point, your graphical interface will boot up, and you will be able to insert your username and password as created in the installation process.
After logging in, Ubuntu will open the setup wizard for the basic system settings. Follow the wizard. When finished, you will be able to continue configuring other options, such as the wallpaper and the aspect of your environment.
In the next demo, we switched back to GDM for ease of use. We have also installed Pluma, a code and text editor, which we will use in combination with nano. If you wish to install it as well, use the following command:
sudo apt install pluma
Step 3 - Install WordPress on Ubuntu Server
We can now install WordPress on our Ubuntu Server. You will find the updated procedure on the Ubuntu Server official documentation. Open a new Terminal from your Ubuntu Server apps.
First, install the dependencies needed by WordPress:
sudo apt update
sudo apt install apache2 \
ghostscript \
libapache2-mod-php \
mysql-server \
php \
php-bcmath \
php-curl \
php-imagick \
php-intl \
php-json \
php-mbstring \
php-mysql \
php-xml \
php-zip
Now we create the folder to host WordPress, assign the appropriate permissions, and install it:
sudo mkdir -p /srv/www
sudo chown www-data: /srv/www
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www
Next, we configure Apache for WordPress. First, create the following text file:
nano /etc/apache2/sites-available/wordpress.conf
In the text file, paste the following lines:
DocumentRoot /srv/www/wordpress
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
Options FollowSymLinks
Require all granted
Save the file, enable it, and disable the default Apache welcome page. Finally, reload the Apache server:
sudo a2ensite wordpress
sudo a2enmod rewrite
sudo a2dissite 000-default
sudo service apache2 reload
Next, set up and configure the database:
sudo mysql -u root
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpress@localhost IDENTIFIED BY '';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
mysql> FLUSH PRIVILEGES;
mysql> quit
sudo service mysql start
Now we need to configure WordPress to connect to the database. Copy and paste the following command lines as they are, except for line #4, where you will need to substitute <your password> with your actual password in the command:
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/database_name_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here//' /srv/www/wordpress/wp-config.php
sudo -u www-data nano /srv/www/wordpress/wp-config.php
Now, find the following lines in the wp-config.php file:
define( 'AUTH_KEY', 'put your unique phrase here' );
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
define( 'NONCE_KEY', 'put your unique phrase here' );
define( 'AUTH_SALT', 'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
define( 'NONCE_SALT', 'put your unique phrase here' );
Delete those lines (ctrl+k will delete a line each time you press the sequence). Then replace with the content of https://api.wordpress.org/secret-key/1.1/salt/. (This address is a randomizer that returns completely random keys each time it is opened.) This step is important to ensure that your site is not vulnerable to “known secrets” attacks.
Save and close the configuration file by typing ctrl+x followed by y then enter.
Step 4 - Configure your WordPress website
Open http://localhost/ in your browser. You will be asked for the title of your new site, username, password, and email address.
Note that the username and password you choose here are for WordPress, and do not provide access to any other part of your server – choose a username and password that are different to your MySQL (database) credentials, that we configured for WordPress’ use, and different to your credentials for logging into your computer or server’s desktop or shell.
Now your WordPress is installed, and you can view it through the browser on your local network from http://localhost or your local address 127.0.0.1. To access the login page, add /wp-login or /wp-admin (example: http://localhost/wp-login).
How to address WordPress configuration issues
Now that everything is up and running, is time to choose a theme for your blog and customize it.
However, as you do that, you will easily run into a few problems. For instance, when you try to upload your theme.zip file or media files, you will run into errors due to exceeding the maximum file size. It’s better to address these configuration issues now, so you can focus on your content later.
To address WordPress configuration issues, keep the locations of these file handy:
- wordpress root: /srv/www/wordpress/
- wp-config file: /srv/www/wordpress/wp-config.php
- htaccess file: /srv/www/wordpress/.htaccess
- php.ini file: /etc/php/x.x/apache2/php.ini
Keep in mind that different installation methods exist, and these locations are valid based on the one detailed here.