To install WordPress on an Ubuntu LAMP stack, set up Apache, MySQL or MariaDB, and PHP, create a database and user, then download WordPress and configure Apache to serve it. The steps below use Ubuntu’s package manager and a browser-based setup; commands that change the system should be run from an account with sudo access.
What a LAMP stack provides
LAMP stands for Linux, Apache, MySQL (or MariaDB), and PHP. Ubuntu supplies the operating system, Apache handles web requests, the database stores WordPress content and settings, and PHP runs the application. WordPress also needs supporting PHP extensions and a writable location for its files.
A server described as a “LAMP stack” may already have some or all of these components installed. Check before adding packages, especially on a managed server. The commands below are a general starting point; package names and available versions can vary with the Ubuntu release.
Install Apache, the database, and PHP
Refresh package information, then install the core services and commonly required PHP modules:
sudo apt update
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip php-intl
For a MariaDB-based setup, install MariaDB in place of MySQL, for example with the mariadb-server package. Do not install both database servers without a specific reason. Start and enable the services, then check their status:
sudo systemctl enable --now apache2
sudo systemctl enable --now mysql
sudo systemctl status apache2 mysql
If you installed MariaDB, use mariadb instead of mysql in the service command. Visit the server’s IP address in a browser: the Apache default page should appear if the web server is reachable. If it does not, check the service status and any host or cloud firewall rules before proceeding.
Create a WordPress database and user
WordPress should have its own database account rather than using the database administrator account. On a typical local MySQL installation, open the database shell with:
sudo mysql
At the SQL prompt, replace the example database name, username, and password with values you choose. Use a unique, strong password and keep it available for the WordPress configuration:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
The database name, user, and password must match the values entered later in WordPress. The account is limited to the WordPress database, which is preferable to granting it broad administrative privileges. If your database requires a different authentication method or runs on another host, adapt the account and connection settings accordingly.
Download and configure WordPress files
Install the download and archive utilities if they are not already present, then fetch and unpack WordPress in a temporary directory:
sudo apt install curl tar
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
Copy the application into Apache’s usual document root and assign ownership to the web-server account:
sudo mkdir -p /var/www/wordpress
sudo cp -a /tmp/wordpress/. /var/www/wordpress/
sudo chown -R www-data:www-data /var/www/wordpress
WordPress can create its configuration file during the browser setup if the directory permissions allow it. If that does not work, copy wp-config-sample.php to wp-config.php and edit the database name, username, password, and host. The usual host for a database on the same machine is localhost. Avoid making the entire WordPress directory broadly writable just to get past a permissions error; correct ownership and grant only the access needed.
Configure Apache and finish in the browser
Create a site configuration file:
sudo nano /etc/apache2/sites-available/wordpress.conf
Add a virtual host, replacing example.com with your domain. For initial testing without a domain, use the server’s IP address in your browser; the virtual host’s ServerName should ultimately match the name visitors use.
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
Enable the site and Apache’s rewrite module, check the configuration, and reload the service:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo apache2ctl configtest
sudo systemctl reload apache2
The configuration test should report that syntax is valid. Open the domain or server IP in a browser and follow the WordPress installation prompts. Choose a site name and administrator login, and enter the database name, database user, and password created earlier. Do not use the database credentials as the WordPress administrator password.
Security and maintenance after installation
A working installation is not the same as a production-ready website. Before using a public domain, point its DNS records to the server and configure HTTPS with a trusted certificate. Serve the site over HTTPS, keep Ubuntu packages, WordPress, themes, and plugins updated, and use strong, distinct passwords for server, database, and WordPress accounts.
- Back up both the database and the WordPress files. A file-only backup does not preserve posts and settings stored in the database.
- Install themes and plugins only when needed, and remove those that are no longer used.
- Do not leave temporary setup files or credentials in publicly accessible locations.
- For a public server, review firewall access and ensure only necessary services are exposed.
Ubuntu’s package-managed PHP and WordPress downloads may not always be the newest upstream releases. That is not automatically a problem: a supported distribution release can provide maintained packages, while downloading WordPress from its official project site provides a separate update path. Choose a maintenance approach you can keep current rather than mixing installation methods without a plan.
Common installation problems
If the browser shows an Apache default page, the WordPress virtual host may not be enabled, or the request may be reaching a different host configuration. Check sudo apache2ctl -S, confirm the domain points to the server, and reload Apache after configuration changes.
A database connection error usually means the database service is stopped or the database name, username, password, or host does not match. Recheck those values and verify that the account can connect locally. A “not found” page for WordPress links can indicate that Apache rewrite support is disabled or AllowOverride All is missing; run a2enmod rewrite, check the virtual host, and reload Apache.
File upload or update failures often point to ownership, permissions, PHP limits, or insufficient disk space. Check the Apache error log at /var/log/apache2/wordpress_error.log and the PHP configuration used by Apache. Avoid using chmod 777; it grants excessive access and does not address the underlying configuration safely.
Frequently Asked Questions
Can I install WordPress if LAMP is already installed?
Yes. Confirm Apache, the database server, PHP, and required PHP extensions are available, then start with the database and WordPress setup steps. Avoid reinstalling components that are already configured.
Should I use MySQL or MariaDB?
Either can run WordPress. Use one database server, follow its Ubuntu service and administration commands, and keep it supported and updated.
Can I install WordPress without a domain name?
Yes. You can test using the server’s IP address. A domain is needed for a conventional public site address, and DNS must point to the server before visitors can use it.
Why does WordPress say it cannot write to a file?
Check that files are in the configured document root and that ownership and permissions allow the web-server process the required access. Do not solve this by making all files writable by everyone.
Do I need HTTPS before installing WordPress?
You can complete a local or initial setup over HTTP, but configure HTTPS before sending real login credentials or operating the site publicly. HTTPS protects connections between visitors and the server.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Error 0x80072f76 0x20016 in Windows
- How to Backup and Restore Drivers in Windows 11
- Fix Windows Couldn’t Complete the Requested Changes
- Move to iOS Stuck? Fixes That Actually Work
- USB Bluetooth Dongle: What It Is and How It Works
- ADB Device Not Found Error on Windows: Fixed