Install WordPress on LAMP with Ubuntu 20.04 LTS
Introduction
WordPress is an open-source content management system that powers millions of personal blogs, corporate websites, and portals. Because it's written in PHP and MySQL/MariaDB, the WordPress installation steps can be completed by most developers in a few minutes. You can use the WordPress editor to fully customize your web pages without any HTML knowledge. In addition, WordPress allows you to take control of your website's look and feel by installing different themes and plugins.
This tutorial explains how to set up a WordPress site with a LAMP stack on your Ubuntu 20.04 LTS server at Vultr.
Prerequisites
To complete this tutorial, you need:
- A non-root sudo user.
- A LAMP Stack on Ubuntu Server 20.04 LTS.
A domain name such as example.com
is optional. You can use the public IP address of your server for testing purposes.
1. Install PHP Extensions and Enable mod_rewrite
SSH to your server as a non-root user and update the package information index.
$ sudo apt update -y
Install the PHP extensions required by WordPress.
$ sudo apt install -y php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
Use the
a2enmod
command to enable Apache'smod_rewrite
module. WordPress requires this to craft user-friendly URLs.$ sudo a2enmod rewrite
Restart Apache to load the new changes.
$ sudo systemctl restart apache2
2. Create Database and User Account
WordPress uses MySQL or MariaDB as the database server.
Log in to your database server as root.
$ sudo mysql -u root
When prompted, enter your root password and press Enter to proceed.
Create a
wordpress
database.> CREATE DATABASE wordpress;
Create a
wp_user
account for your WordPress database. ReplaceEXAMPLE_PASSWORD
with a strong value.If you use MySQL, run these commands:
> CREATE USER 'wp_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'EXAMPLE_PASSWORD'; > GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost'; > FLUSH PRIVILEGES;
If you use MariaDB, use this command:
> GRANT ALL PRIVILEGES on wordpress.* TO 'wp_user'@'localhost' identified by 'EXAMPLE_PASSWORD';
Exit the database server.
> quit;
Make note of these credentials, you'll need them later for the WordPress configuration file.
3. Create the WordPress Directory and Virtual Host File
Create a
wordpress
directory under the root of your web server/var/www/
.$ sudo mkdir /var/www/wordpress
Disable the default virtual host file that ships with Apache.
$ sudo a2dissite 000-default.conf
Create a new configuration file using
nano
. This architecture separates the WordPress site configuration file to make troubleshooting easier in case a configuration problem occurs. This step is also mandatory if you intend to run multiple websites on your server.$ sudo nano /etc/apache2/sites-available/wordpress.conf
Enter the information below into the file. Replace
example.com
with the domain name or public IP address of your server. The lineAllowOverride All
instructs Apache to allow the use of a.htaccess
file in the/var/www/wordpress
directory to override the web server's default configuration.<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/wordpress <Directory /var/www/wordpress> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
Save and exit the file.
Enable the configuration file.
$ sudo a2ensite wordpress.conf
Restart the web server to load the new changes.
$ sudo systemctl restart apache2
3. Download WordPress
Navigate to the
tmp
directory.$ cd /tmp
Download the latest WordPress package.
$ curl -O https://wordpress.org/latest.tar.gz
Extract the archive.
$ tar xzvf latest.tar.gz
Copy the extracted files to the WordPress home folder.
$ sudo rsync -rtv /tmp/wordpress/ /var/www/wordpress/
By default, WordPress ships with a sample configuration file named
wp-config-sample.php
. Copy the sample towp-config.php
.$ sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
Create an
upgrade
directory under thewp-content
directory to allow WordPress to install upgrades without permission issues.$ sudo mkdir /var/www/wordpress/wp-content/upgrade
Set the appropriate permissions for WordPress files.
$ sudo chown -R www-data:www-data /var/www/wordpress $ sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \; $ sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;
5. Edit the WordPress Configuration
For security, WordPress uses security keys and salts. To create a new set of secure values, use the WordPress secret key generator.
$ curl -s https://api.wordpress.org/secret-key/1.1/salt/
Copy the output to your clipboard.
Edit your WordPress configuration file.
$ sudo nano /var/www/wordpress/wp-config.php
Locate the block below and replace it with the values from the WordPress secret key generator.
... 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' ); ...
Locate these database configuration settings.
/** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' );
Replace the
DB_NAME
,DB_USER
, andDB_PASSWORD
values with the database details you created in section 2.Save and close the file.
6. Finish WordPress Setup
In a web browser, navigate to your server by name or IP address. Follow the on-screen prompts to complete the WordPress installation.
More Information
- How to Install WordPress at WordPress.org
- WordPress support