WordPress is a free and open-source content management system (CMS) written in PHP and using a MySQL or MariaDB database. According to W3Techs data for July 2025, WordPress powers 43.1% of websites with a known CMS. Originally created as a blogging platform in 2003, WordPress has evolved into a powerful tool for creating any type of website. Its popularity stems from ease of use, flexibility, and an extensive developer community.
This article provides an up-to-date guide for installing WordPress on an Ubuntu server, considering modern security and performance requirements.
Prerequisites
Before installing WordPress, ensure your Ubuntu server meets these requirements:
- Apache web server: Installed with the mod_rewrite module enabled (for SEO-friendly URLs):
sudo a2enmod rewrite
sudo systemctl restart apache2 - PHP 8.0 or higher: With essential modules installed:
sudo apt install php-mysql php-curl php-gd php-xml php-mbstring php-zip
sudo systemctl restart apache2 - MySQL 8.0 or higher: With a database configured in utf8mb4 encoding:
mysql --version
Downloading WordPress
- Download the archive
wget https://wordpress.org/latest.tar.gz
- Extract the archive completely
tar -xzf latest.tar.gz
Database Configuration
Create a Unicode-compatible database and user with minimal privileges:
sudo mysql
CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX ON wordpress.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Important: Using mysql_native_password ensures compatibility with WordPress.
WordPress Configuration
- Copy the sample configuration
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
- Add salt keys
Generate unique keys at api.wordpress.org/secret-key/1.1/salt/ and paste them in wp-config.php replacing:define('AUTH_KEY', 'insert your unique phrase');
define('SECURE_AUTH_KEY', 'insert your unique phrase');
// ... remaining keys - Configure database access
Edit in wp-config.php:define('DB_NAME', 'wordpress');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'secure_password');
define('DB_HOST', 'localhost'); - Set secure permissions
cd /var/www/html
sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chown -R www-data:www-data /var/www/html
Running the Installation Script
- Access the installer in your browser
Navigate to http://your_IP_address or http://localhost - Enter site information
- Site title
- Username (avoid using "admin")
- Strong password
- Administrator email
- Complete installation
Click "Install WordPress" and log into the admin dashboard
Troubleshooting Installation Issues
Database connection error
- Verify MySQL user authentication:
SELECT plugin FROM mysql.user WHERE User = 'wp_user';
Should return: mysql_native_password
- Check MySQL status:
sudo systemctl status mysql
Permission issues
- Check file ownership:
ls -l /var/www/html
- Fix permissions:
sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;
Missing functionality
- Install required PHP modules:
sudo apt install php-json php-xmlrpc php-soap php-intl
sudo systemctl restart apache2
SEO-friendly URL issues (Pretty Permalinks)
- Enable mod_rewrite:
sudo a2enmod rewrite
- Add to .htaccess:
AllowOverride All
Installing WordPress on Ubuntu requires attention to modern security requirements, especially when using MySQL 8.0 and PHP 8.0+. By following this guide, you'll create an optimized and secure environment for your website. Regularly update WordPress and its components to maintain security.
Table: Essential WordPress Installation Commands
Command | Description |
---|---|
sudo a2enmod rewrite | Enables SEO-friendly URL support |
sudo apt install php-mysql php-curl | Installs required PHP modules |
cp -a wordpress/. /var/www/html/ | Copies all WordPress files |
CREATE USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password | Creates a compatible database user |
find . -type d -exec chmod 755 {} \; | Secure directory permissions |
find . -type f -exec chmod 644 {} \; | Secure file permissions |