How to Install WordPress with LAMP on Ubuntu 18.04

How To Install WordPress with LAMP on Ubuntu 18.04

WordPress, the world’s leading content management system, powers millions of websites, from personal blogs to large news outlets. It’s a versatile platform that can be customized to meet a wide range of needs, making it a popular choice for both beginners and experienced web developers. One of the most common ways to run WordPress is on a LAMP stack on an Ubuntu server.

LAMP is an acronym for Linux, Apache, MySQL, and PHP. This stack of software provides all the necessary components to run a dynamic website like WordPress. Linux is the operating system, Apache is the web server, MySQL handles the database, and PHP is the scripting language that ties everything together. When installed on a server, these four components work together to deliver web content to your visitors.

Ubuntu, a user-friendly and powerful Linux distribution, is a great choice for hosting your WordPress site. It’s secure, robust, and offers a large community of users for support. In this tutorial, we’ll guide you through the process of installing WordPress with a LAMP stack on Ubuntu 18.04. Whether you’re setting up a dedicated server, a virtual server, or even a home server, this guide will help you get your WordPress site up and running.

Before we begin, it’s important to note that this guide assumes you have some basic knowledge of Linux commands and the terminal interface. If you need a refresher, check out our server tutorials and how-tos.

Let’s get started!


Before we start with the installation process, there are a few things you need to have:

  • An Ubuntu 18.04 server: You can use a dedicated server, a VPS, or even a home server.
  • Root access or a user with sudo privileges: You’ll need to be able to install software and make changes to system files.
  • A basic understanding of Linux commands: We’ll be using the command line to install and configure the software.

Once you have these ready, we can move on to the first step: installing the LAMP stack.

Installing LAMP Stack on Ubuntu 18.04

The first step in getting your WordPress site up and running is to install the LAMP stack on your Ubuntu server. Here’s how to do it:

Update Your System

Before installing any new software, it’s a good idea to update your system’s package list. Open a terminal window and enter the following command:

sudo apt-get update

Install Apache

Apache is one of the most popular web servers in the world, known for its robustness and flexibility. To install Apache, use the following command:

sudo apt-get install apache2

This command installs Apache and starts the service automatically. You can verify that Apache is running by typing your server’s IP address into your web browser. You should see the default Ubuntu Apache web page.

Install MySQL

MySQL is a powerful database management system used for managing the data of web applications like WordPress. To install MySQL, use the following command:

sudo apt-get install mysql-server

During the installation, you’ll be prompted to create a root password. Make sure to choose a strong password, as the root account has full control over the database.

Install PHP

PHP is a server-side scripting language that is used to create dynamic web pages. WordPress is written in PHP, making it an essential component of the LAMP stack. To install PHP, use the following command:

sudo apt-get install php libapache2-mod-php php-mysql

This command installs PHP and also the necessary modules for Apache and MySQL.

With the LAMP stack installed, we’re now ready to move on to setting up the MySQL database for WordPress.

Setting Up MySQL Database and User for WordPress

WordPress uses MySQL to manage and store site and user information. Here’s how to set up a MySQL database for your WordPress site:

Login to MySQL

First, log in to MySQL with the following command:

mysql -u root -p

You’ll be prompted to enter the root password you created during the MySQL installation.

Create a New Database

Once you’re logged in to MySQL, you can create a new database for your WordPress site. In this example, we’ll name the database ‘wordpress’:


This command creates a new database named ‘wordpress’. You can replace ‘wordpress’ with a different name if you prefer.

Create a New User

Next, you’ll want to create a new user that will have access to the ‘wordpress’ database. In this example, we’ll create a new user named ‘wordpressuser’:

CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';

This command creates a new user named ‘wordpressuser’ with the password ‘password’. Be sure to replace ‘password’ with a strong password.

Grant Permissions to the User

Now, you’ll need to give the ‘wordpressuser’ permissions to the ‘wordpress’ database. You can do this with the following command:

GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';

This command grants all privileges to the ‘wordpressuser’ on the ‘wordpress’ database.

Flush Privileges and Exit MySQL

After granting the permissions, you should flush the privileges so that MySQL can recognize the changes. Then, you can exit MySQL:


With the MySQL database and user set up, we can now move on to installing the additional PHP extensions required by WordPress.

Installing Additional PHP Extensions

WordPress requires certain PHP extensions to function correctly. Here’s how to install these extensions:

sudo apt-get install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

This command installs several PHP extensions that WordPress requires or recommends. Once the installation is complete, you should restart the Apache service to recognize the new extensions:

sudo systemctl restart apache2

With the PHP extensions installed, we’re now ready to download and set up WordPress.

Downloading and Setting Up WordPress

Now that our server is ready, we can download and set up WordPress. Here’s how:

Download WordPress

First, navigate to the /tmp directory and download the latest version of WordPress:

cd /tmp
curl -O

This command downloads the latest version of WordPress from the official WordPress site.

Extract the WordPress Files

Once the download is complete, you can extract the WordPress files:

tar xzvf latest.tar.gz

This command extracts the WordPress files from the .tar.gz file.

See also  How to Install phpMyAdmin on CentOS 6/7 / RHEL 6/7

Move the WordPress Files

Next, move the WordPress files to the Apache document root, which is the directory where Apache serves files from:

sudo cp -a /tmp/wordpress/. /var/www/html

This command copies the WordPress files to the /var/www/html directory.

Adjusting the Ownership and Permissions

One of the crucial steps in setting up a secure WordPress installation is adjusting file permissions and ownership. This process ensures that the Apache web server, which runs as the www-data user and group, can read and write WordPress files, enabling the website to function correctly and perform automatic updates.

Start by changing the ownership of all the files to the www-data user and group using the chown command:

sudo chown -R www-data:www-data /var/www/html

Next, set the correct permissions on the WordPress directories and files using the find command:

sudo find /var/www/html/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/ -type f -exec chmod 640 {} \;

These commands set directories to 750 and files to 640, providing a reasonable permission set to start with. Some plugins and procedures might require additional tweaks.

Set Up the wp-config.php File

WordPress uses a configuration file called wp-config.php to manage its settings. You’ll need to create this file and add your database information to it:

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

This command copies the sample configuration file to create a new wp-config.php file.

Next, open the wp-config.php file in a text editor:

sudo nano /var/www/html/wp-config.php

Find the section that contains the database settings and replace ‘database_name_here’, ‘username_here’, and ‘password_here’ with your database name, username, and password, respectively:

define('DB_NAME', 'database_name_here');
define('DB_USER', 'username_here');
define('DB_PASSWORD', 'password_here');

You’re almost done.

Secure the Configuration File

While you have your wp-config.php file open, it’s an opportune time to bolster the security of your WordPress installation. This can be achieved by setting unique secret keys for your installation.

WordPress uses these secret keys, known as ‘salts’, to ensure better encryption of information stored in user’s cookies. A salt is a string of random content that is used to enhance the security of encrypted passwords. By changing these values, you add an extra layer of complexity to your authentication keys and hashed passwords, making your site harder to hack and more secure.

To generate unique secret keys for your WordPress installation, you can use the WordPress API. Run the following command:

curl -s

This command will return a unique set of secret keys that you can use for your site. It should look something like this:

define('AUTH_KEY',         '-e9O5o/tuA1Nm;a@&bE|^*G2%ut-Et#iu#Pt9RE7^+`@|9K%=8tWyboUQ+[We:+D');
define('SECURE_AUTH_KEY',  '(r^>1YS2;KM^Rq *-Tv!>]L{;_[SW--:hu-g={_1nmiL^-L:$ntSMeSyuZN%yl|+yW`Ek5');
define('SECURE_AUTH_SALT', '`3h}ed3g|0F#^~n8kh=W5[K?C:N4Mc9~Zp[5uv{Y@A{OmrQ}!=3d7wN(}3$Fy&0x');
define('LOGGED_IN_SALT',   '~P:UQoQ`A}RODd)-,EDY7IS%b}QVBG:;tF!NZl*a(C-E@JUl>Q79]KP$CN=LLGQ!');
define('NONCE_SALT',       '=l%%XN)pq#-0U[.mjK|FZra~TE#7+*jJ9Qqwe;L,).4KX?9=.duFltcI.+8{n-$,');

Copy these unique values. Next, in your wp-config.php file, locate the section that contains the dummy values for the secret keys. It will look like this:

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');

Replace these lines with the unique secret keys you copied earlier:


By replacing the default secret keys with unique ones, you significantly enhance the security of your WordPress installation. This step ensures that your encryption keys are unique and secure, making your site more resilient against hacking attempts.

Save and close the file when you’re done.

With WordPress downloaded and set up, we can now move on to configuring Apache for WordPress.

Configuring Apache for WordPress

Apache needs to be configured to serve your WordPress site. Here’s how to do it:

Create a New Virtual Host File

Apache uses virtual host files to manage multiple sites on a single server. You’ll need to create a new virtual host file for your WordPress site:

sudo nano /etc/apache2/sites-available/wordpress.conf

This command opens a new file named wordpress.conf in a text editor.

In this file, add the following configuration:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

<Directory /var/www/html/>
AllowOverride All

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Replace ‘’ with your domain name. Save and close the file when you’re done.

Enable the Virtual Host File

After creating the virtual host file, you’ll need to enable it:

sudo a2ensite wordpress.conf

This command enables the wordpress.conf virtual host file.

Enable the Apache Rewrite Module

WordPress uses the Apache rewrite module to manage permalinks. Enable this module with the following command:

sudo a2enmod rewrite

This command enables the rewrite module.

Restart Apache

Finally, restart Apache to apply the changes:

sudo systemctl restart apache2

With Apache configured, we can now complete the installation through the web interface.

Completing the Installation Through the Web Interface

The final steps of the WordPress installation process are done through the web interface. This is where you’ll configure the basic settings of your WordPress site. Here’s a detailed walkthrough:

Open the WordPress Installation Page

Open your preferred web browser and navigate to your domain name. If you’ve correctly followed the previous steps, you should see the WordPress installation page. This page is also known as the “5-minute install” page. It’s a simple, user-friendly interface that guides you through the final steps of the installation process.

Select a Language

The first thing you’ll be asked to do is select a language for your WordPress site. This language will be used for the default text and messages on your site. WordPress supports many languages, so you can choose the one that you and your audience are most comfortable with. After selecting a language, click the ‘Continue’ button to proceed.

Fill Out the Setup Form

Next, you’ll be presented with a setup form. This form asks for the following details:

  • Site Title: This is the name of your website. It can be anything you like and can be changed later in the WordPress settings.
  • Username: This is the username you’ll use to log into the WordPress admin area. It should be something unique and not easily guessable.
  • Password: This is the password for your WordPress admin account. It should be strong and secure to prevent unauthorized access to your site.
  • Email Address: This is where WordPress will send notifications and password reset links, so make sure it’s an email address that you have access to.

After filling out the form, click the ‘Install WordPress’ button to start the installation process. WordPress will now install using the details you’ve provided.

Login to WordPress

Once the installation is complete, you’ll see a success message along with a button to log in to your new WordPress site. Click this button and log in using the username and password you created in the previous step.

After logging in, you’ll be taken to the WordPress dashboard. This is the control panel where you can manage your site’s content, appearance, functionality, and more.

With WordPress installed, there are a few more things you should do to secure and configure your site. These include choosing a theme, installing plugins, creating content, and optimizing your site for search engines. Remember, the key to a successful website is not just in its setup, but in its ongoing maintenance and improvement.

Post-Installation Tips

After installing WordPress, there are a few things you should do to secure and configure your site:

Update WordPress

First, make sure your WordPress installation is up to date. WordPress regularly releases updates to fix bugs, add new features, and patch security vulnerabilities. To check for updates, go to your WordPress dashboard and click on ‘Updates’. If there are any available updates, you’ll see them listed here. Make sure to backup your site before applying updates, just in case anything goes wrong.

Choose a Theme

Next, choose a theme for your site. WordPress comes with a few default themes, but there are thousands of free and premium themes available online. To choose a theme, go to ‘Appearance’ > ‘Themes’ in your WordPress dashboard. You can search for themes by keyword, or filter by features, layout, and more. Once you’ve found a theme you like, you can preview it and install it directly from the dashboard.

Install Plugins

Plugins extend the functionality of your WordPress site. There are plugins for SEO, security, backups, forms, and more. To install a plugin, go to ‘Plugins’ > ‘Add New’ in your WordPress dashboard. Like themes, you can search for plugins by keyword, or filter by popular, recommended, and favorites. Be careful not to install too many plugins, as this can slow down your site. Always check the reviews and ratings of a plugin before installing it.

Configure Permalinks

Permalinks are the URLs of your posts and pages. You can configure the structure of your permalinks in the WordPress settings. To do this, go to ‘Settings’ > ‘Permalinks’ in your WordPress dashboard. There are several options to choose from, including ‘Day and name’, ‘Month and name’, ‘Numeric’, and ‘Post name’. Choose the one that best fits your site’s needs. Remember, changing your permalink structure can affect your SEO, so choose carefully.

Secure Your Site

Finally, take steps to secure your site. This includes using strong passwords, keeping WordPress and your plugins up to date, and installing a security plugin. There are several security plugins available, such as Wordfence and Sucuri, that can help protect your site from hacks and malware. Additionally, consider implementing an SSL certificate to encrypt data between your site and your users, and set up regular backups of your site in case anything goes wrong.

By following these post-installation tips, you can ensure that your WordPress site is secure, optimized, and ready for your visitors.

Now, you’re well on your way to building a successful WordPress site on your Ubuntu server.


If you encounter any issues during the installation process, here are a few common problems and their solutions:

Error Establishing a Database Connection

This error usually means that WordPress is unable to connect to your MySQL database. This could be due to incorrect database credentials in your wp-config.php file. To resolve this, open your wp-config.php file and check the DB_NAME, DB_USER, and DB_PASSWORD values. Make sure they match the name of your MySQL database, the username, and the password you created. If any of these values are incorrect, WordPress will not be able to connect to your database.

404 Page Not Found Errors

If you’re getting 404 errors when trying to access your site, it could be a problem with your permalinks. Permalinks are the permanent URLs to your individual pages and posts, as well as your category and tag archives. A permalink is the web address used to link to your content. WordPress provides several permalink settings for you to choose from in the Settings > Permalinks panel. If these settings are incorrect, it could lead to 404 errors. Try resetting your permalinks in the WordPress settings to resolve this issue.

White Screen of Death

If your site is just showing a white screen, it could be a problem with a plugin or theme. This issue is often caused by a PHP error that stops the page from loading. One way to troubleshoot this is to deactivate all your plugins and switch to a default theme. If this resolves the issue, reactivate your plugins one by one until you find the one causing the problem. Then, you can decide whether to replace the plugin or contact the plugin author for support.

Unable to Upload Images

If you’re unable to upload images, it could be a permissions issue. WordPress needs permissions to write to files in the wp-content/uploads directory. This is where your images and other media files are stored. If WordPress doesn’t have the necessary permissions, you won’t be able to upload images from the WordPress admin. To resolve this, check the permissions of the wp-content/uploads directory. The directory should be writable by the web server.

Memory Exhausted Error

This error means that WordPress has exhausted the maximum amount of memory that can be used. WordPress, like all software, requires memory to run. The more complex your site and the more plugins you have, the more memory it will require. If WordPress reaches the maximum memory limit, it will display a “memory exhausted” error. You can increase the memory limit by editing the wp-config.php file. Add the line define(‘WP_MEMORY_LIMIT’, ‘256M’); to increase the memory limit to 256MB.

If you’re still having trouble, don’t hesitate to seek help from the WordPress community or your hosting provider. They can provide additional troubleshooting tips and help you resolve any issues you’re experiencing.

Further Reading

For more information on WordPress, LAMP, and Ubuntu, check out the following resources:

Glossary of Terms

Here are some terms you might come across in this tutorial:

  • LAMP: An acronym for Linux, Apache, MySQL, and PHP. It’s a stack of software that can be used to serve websites.
  • WordPress: A popular content management system used to create websites.
  • Apache: A widely used web server software.
  • MySQL: A database management system used to store and retrieve data for websites.
  • PHP: A server-side scripting language used to create dynamic web pages.
  • Ubuntu: A popular distribution of the Linux operating system.

Frequently Asked Questions

  1. What is a LAMP stack?

    A LAMP stack is an acronym for a suite of open-source software — Linux (operating system), Apache (HTTP Server), MySQL (relational database management system), and PHP (programming language). This software stack is widely used for web development, as it provides a robust platform for building and deploying web applications and websites. The LAMP stack is highly customizable and can be optimized for different hardware configurations and various types of web apps.

  2. Why use WordPress?

    WordPress is a versatile content management system (CMS) that powers over 30% of the web. It’s favored for its flexibility and ease of use, allowing users to create anything from personal blogs to complex e-commerce sites. WordPress offers a vast library of themes and plugins, enabling extensive customization to suit different needs. Its large, active community contributes to continuous development and support, making it a reliable platform for many.

  3. Why choose Ubuntu for your server?

    Ubuntu is a highly respected Linux distribution known for its robustness, user-friendliness, and extensive software repositories. As a server operating system, Ubuntu offers long-term support (LTS) versions that receive security updates for five years, making it a secure choice. Its predictable release cycle and upgrade path, coupled with its widespread usage in the cloud, make Ubuntu a reliable choice for server environments.

  4. What is Apache?

    Apache, officially known as Apache HTTP Server, is a free and open-source web server software that plays a key role in the growth of the World Wide Web. It’s highly configurable and can be tailored to meet the needs of many different environments by using extension modules. Apache provides a range of features, including CGI, SSL, and virtual domains. Its robustness, rich feature set, and active community support make it a popular choice for serving web content.

  5. What is MySQL?

    MySQL is an open-source relational database management system (RDBMS) that uses Structured Query Language (SQL) for accessing and managing data. It’s widely used in web applications to store data, including WordPress where it holds and manages posts, user profiles, and other critical information. MySQL is known for its speed, reliability, and flexibility. It supports a broad range of apps, from personal projects to high-volume websites.

Commands Mentioned

  • sudo apt-get update – Updates the list of available packages and their versions, but it does not install or upgrade any packages.
  • sudo apt-get install apache2 – Installs the Apache web server.
  • sudo apt-get install mysql-server – Installs the MySQL database system.
  • sudo apt-get install php libapache2-mod-php php-mysql – Installs PHP and the necessary modules for Apache and MySQL.
  • mysql -u root -p – Logs in to MySQL with the root user.
  • CREATE DATABASE wordpress; – Creates a new MySQL database named ‘wordpress’.
  • CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘password’; – Creates a new MySQL user named ‘wordpressuser’.
  • GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’; – Grants all privileges to the ‘wordpressuser’ on the ‘wordpress’ database.
  • FLUSH PRIVILEGES; – Flushes the privileges so that MySQL can recognize the changes.
  • EXIT; – Exits MySQL.


Installing WordPress on a LAMP stack on Ubuntu 18.04 may seem like a daunting task, especially if you’re new to server administration.

By following the steps outlined in this tutorial, you should now have a fully functioning WordPress site running on your Ubuntu server. From here, the possibilities are endless. You can start customizing your site with themes and plugins, create content, and start sharing your site with the world.

Remember, this is just the beginning of your WordPress journey. There’s a whole world of resources and community support available to help you along the way. Whether you’re building a personal blog, an online store, or a corporate website, WordPress offers the flexibility and power to meet your needs.

Finally, don’t forget that maintaining a website is an ongoing process. Keep your WordPress site secure by regularly updating your software, using strong passwords, and following best security practices. And most importantly, don’t forget to have fun and be creative with your new website!

We hope you found this guide helpful. If you have any questions or run into any issues, don’t hesitate to reach out for help. Happy WordPressing!

For more tutorials and guides on web servers and hosting, be sure to check out our server tutorials and how-tos and our list of the best web servers.

Any suggestions? Welcome to the comments!


Leave a Reply

Your email address will not be published. Required fields are marked *