In this article, we will have explained the necessary steps to install and configure WordPress on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
WordPress is the world’s leading content management system. Used by tens of millions of web pages and internet creators alike, WordPress is the backbone of most blogs and news outlets. Webpage performance with WordPress is also typically one of the fastest available.
Install WordPress on Ubuntu
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Install LAMP Stack.
WordPress is build with PHP. You can host it like you would any other web app written in PHP. So, you’re going to need to set Ubuntu up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide to set up Ubuntu to serve PHP before you continue.
Step 2. Creating MySQL database for WordPress.
WordPress uses MySQL database to store all its data like posts, pages, users, plugins and themes settings. Log in to your MySQL server with the following command and enter your MySQL root password:
mysql -u root -p
Once you’re in the MySQL console, create a new database:
CREATE DATABASE wordpress; GRANT ALL PRIVILEGES ON wordpress.* TO 'admin_wp'@'localhost' IDENTIFIED BY 'YourStrongPassword'; FLUSH PRIVILEGES; exit;
Step 3. Install WordPress on Ubuntu 18.04.
Run the following commands to download and extract the latest WordPress installation files in the default web server document root directory:
cd /var/www/html wget -c http://wordpress.org/latest.zip unzip latest.zip chown -R www-data:www-data wordpress rm latest.zip
Next, run the following command to rename the sample configuration file:
cd /var/www/html/wordpress mv wp-config-sample.php wp-config.php
Now open the wp-config.php file with your favorite text editor, for example:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'admin_wp'); /** MySQL database password */ define('DB_PASSWORD', 'YourStrongPassword'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', '');
Step 4. Configuring Apache for WordPress.
We can now create our virtual host files. Run the following command to create the virtual host configuration file for your domain, my_domain.com:
nano /etc/apache2/sites-available/your_domain.com.conf
And add the following content to the file:
<VirtualHost *:80> ServerAdmin [email protected]_domain.com ServerName your_domain.com ServerAlias www.my_domain.com DocumentRoot /var/www/html/wordpress <Directory /var/www/html/wordpress> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/your_domain.com_error.log CustomLog ${APACHE_LOG_DIR}/your_domain.com_access.log combined </VirtualHost>
To enable the virtual host we have just created, run the following command:
ln -s /etc/apache2/sites-available/your_domain.com.conf /etc/apache2/sites-enabled/my_domain.com.conf
For the new configuration to take effect, restart the Apache service by typing:
sudo systemctl restart apache2
Step 5. Completing the WordPress Installation.
In the last step of this guide, we need to access the WordPress Web Interface and finish the installation. To finish the installation, open your browser and navigate to:
http://your_domain.com/
That’s all you need to do to install WordPress on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.