Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install WordPress on Ubuntu 18.04 with a LAMP stack

This guide shows you how to set up WordPress on an Ubuntu 18.04 server. It needs root access, so it fits VPS and dedicated server customers.

WordPress2 min read11 steps

What is a LAMP stack?

LAMP is a set of four programs that work together. L is Linux, the operating system. A is Apache, the web server that sends pages to visitors. M is MySQL, the database that stores your content. P is PHP, the language WordPress runs on.

A command line is a text window where you type instructions. You use it for every step below. Log in to your server over SSH as root, or as a user who can run sudo.

Tip: Ubuntu 18.04 is old. Newer Ubuntu versions use almost the same steps, though some package names differ.

Steps

  1. Update the package list.
    sudo apt update && sudo apt upgrade -y
    This refreshes the list of software and installs updates.
  2. Install Apache, MySQL and PHP.
    sudo apt install apache2 mysql-server php php-mysql php-curl php-gd php-mbstring php-xml php-zip libapache2-mod-php -y
    This installs the whole stack and the PHP parts WordPress needs.
  3. Open the MySQL prompt.
    sudo mysql
  4. Create a database and a user. Replace the name and password with your own.
    CREATE DATABASE wpdb DEFAULT CHARACTER SET utf8mb4;
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
    GRANT ALL ON wpdb.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    This makes a database and a user who may use only that database.
  5. Download WordPress.
    cd /tmp
    curl -O https://wordpress.org/latest.tar.gz
    tar -xzf latest.tar.gz
    This fetches and unpacks the newest WordPress files.
  6. Copy the files to the web folder.
    sudo cp -a /tmp/wordpress/. /var/www/html/
    sudo rm /var/www/html/index.html
  7. Give Apache ownership of the files.
    sudo chown -R www-data:www-data /var/www/html
  8. Turn on pretty links.
    sudo a2enmod rewrite
    sudo systemctl restart apache2
    For pretty links to work, set AllowOverride All for /var/www/html in your Apache site file, then restart Apache again.
  9. Open your server's IP address or domain in a browser.
  10. Enter the database name, user and password from step 4. Use localhost as the host.
  11. Choose a site title, admin username and strong password, then click Install WordPress.

After the install

  • Set up a firewall so only needed ports are open.
  • Add an SSL certificate so your site uses https.
  • Take regular backups.

Quick recap

  • LAMP means Linux, Apache, MySQL and PHP.
  • Install the stack, create a database, then copy WordPress to /var/www/html.
  • Set the right file owner, then finish the setup in your browser.
  • You need root access for these steps.