◦ Comprehensive security
◦ 24/7 support
WordPress Guide → Admin → Install WordPress on Ubuntu
How to install WordPress on Ubuntu (+ a LAMP stack)
Want total control over your WordPress site setup? Installing it manually on an Ubuntu server with a LAMP stack (Linux, Apache, MySQL, PHP) is the way to go. It’s not as quick as using a one-click installer—but you’ll understand exactly how everything works and gain full flexibility.
Let’s walk through each step to get WordPress running on Ubuntu 22.04 with a fresh LAMP stack.
Get fast, reliable hosting for WordPress
Power your site with the industry’s fastest, most optimized WordPress hosting
Prerequisites
Make sure you have the following before you begin:
- An Ubuntu 22.04 server (local or hosted)
- A non-root user with sudo privileges
- Basic command line access
- Optional: a domain name pointed to your server’s IP address
Step 1: Update the server and install the LAMP stack
We’ll start by installing Apache (the web server), MySQL (the database), and PHP (the scripting language WordPress uses).
Update your package index
Open your terminal and run:
sudo apt update && sudo apt upgrade -y
This makes sure your system is running the latest software and security patches.
Install Apache
Install Apache with:
sudo apt install apache2 -y
Once installed, enable it to start on boot:
sudo systemctl enable apache2
sudo systemctl start apache2
To confirm Apache is running, visit your server’s IP address in a browser. You should see the default Apache welcome page.
Install MySQL and secure it
Install MySQL with:
sudo apt install mysql-server -y
Then run the built-in security script:
sudo mysql_secure_installation
Follow the prompts to:
- Set a root password (or confirm one already exists)
- Remove anonymous users
- Disallow remote root login
- Remove the test database
- Reload privilege tables
Create a database and user for WordPress
Log into the MySQL shell:
sudo mysql
Run the following commands to create a new database and user:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘strong_password’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
Replace ‘strong_password’ with a secure password.
Install PHP and required extensions
Install PHP along with the necessary modules for WordPress:
sudo apt install php php-mysql php-xml php-gd php-curl php-mbstring php-zip libapache2-mod-php -y
Then enable Apache’s rewrite module:
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 2: Download and configure WordPress
Now that your LAMP stack is ready, let’s install WordPress itself.
Download WordPress
Change to your temporary directory and download WordPress:
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz
Move WordPress files to the web root
Copy the extracted files to your Apache document root:
sudo cp -a /tmp/wordpress/. /var/www/html
(Optional: delete the default Apache index file to avoid conflicts)
sudo rm /var/www/html/index.html
Set correct file permissions
Run these commands to give Apache permission to read and write the files:
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 {} \;
This ensures security while still allowing WordPress to run properly.
Step 3: Configure WordPress to connect to the database
WordPress needs to know your database details to work correctly.
Create the config file
Copy the sample configuration to a working config:
cd /var/www/html
cp wp-config-sample.php wp-config.php
Edit the config file
Open the file in a text editor:
sudo nano wp-config.php
Update the following lines with your database info:
define( ‘DB_NAME’, ‘wordpress’ );
define( ‘DB_USER’, ‘wpuser’ );
define( ‘DB_PASSWORD’, ‘strong_password’ );
Save and exit (Ctrl+O, then Enter, then Ctrl+X).
Add security keys
Visit https://api.wordpress.org/secret-key/1.1/salt/ to generate a unique set of secret keys. Copy and paste them into the appropriate section of wp-config.php, replacing the placeholder lines.
These keys improve your site’s security by encrypting information stored in cookies.
Step 4: Complete the installation in your browser
At this point, WordPress is installed on your server. Time to finish the setup in your browser.
- Go to http://your_domain_or_IP
- Select a language
- Set your site title, username, password, and admin email
- Click Install WordPress
Once it finishes, you’ll be able to log into your WordPress dashboard at http://your_domain_or_IP/wp-admin.
Optional: Secure your WordPress site with HTTPS
If you’re using a domain name, adding HTTPS is essential.
Install Certbot
Install Certbot and the Apache plugin:
sudo apt install certbot python3-certbot-apache -y
Get a free SSL certificate
Run the interactive Certbot script:
sudo certbot –apache
Follow the prompts to choose your domain and automatically redirect HTTP to HTTPS.
Auto-renew SSL certificates
Certbot sets up auto-renewal by default. You can verify it with:
sudo systemctl status certbot.timer
Optional: Set up a custom Apache virtual host
If you’re hosting multiple sites or want cleaner domain-based access, create a virtual host config file.
Example:
sudo nano /etc/apache2/sites-available/example.com.conf
Add:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
</Directory>
</VirtualHost>
Then:
sudo a2ensite example.com.conf
sudo systemctl reload apache2
Make sure your domain’s DNS is pointed at your server IP.
Troubleshooting tips
Here are some common issues and fixes:
- “Error establishing a database connection” – Double-check your database name, username, and password in wp-config.php.
- Permission errors – Ensure Apache owns the files (www-data:www-data) and file permissions are correctly set.
- PHP showing as text – Make sure libapache2-mod-php is installed and Apache is restarted.
Next steps for installing WordPress on Ubuntu
Installing WordPress on Ubuntu with a LAMP stack gives you full control over performance, security, and scalability. It’s a great skill for developers, agencies, or anyone who wants to manage WordPress on their own terms.
From here, consider adding a firewall like UFW, enabling caching for speed, and setting up automated backups.
Ready to upgrade your WordPress experience? Professional hosting improves speeds, security, and reliability for a website and a brand that people find engaging and trustworthy.
Don’t want to deal with server management and maintenance either? Our fully managed hosting for WordPress is the best in the industry. Our team are not only server IT experts, but WordPress hosting experts as well. Your server couldn’t be in better hands.
Click through below to explore all of our hosting for WordPress options—including VPS and dedicated servers—or chat with a WordPress expert right now to get answers and advice.
Additional resources
How to use your WordPress admin login page →
How to find, use, and troubleshoot your admin page
Is WordPress scalable? (And how to do it right) →
Learn how to create a scalable WordPress admin experience for growing websites and teams.
Easy WordPress website maintenance tips →
7 simple steps to keep on regular rotation