How To Install WordPress On Ubuntu 20.04 With Lamp/Apache


In this tutorial, We will discuss about how to install WordPress on Ubuntu 20.04 with LAMP Stack (Apache) web server. We all know LAMP or Apache web server is widely used to serve dynamic website. LAMP basically includes different software packages such as Linux, Apache, MySQL and PHP.

Speaking about WordPress, it’s a widely used open-source content management system that allows to make websites and blogs. Since this CMS offers great options or features to modify websites accordingly, it’s one of the best choice for those who are looking an easy way to make their website or blog.

So, through this article, we will learn here how to install WordPress on Ubuntu 20.04 that is ready to serve dynamic website through LAMP/Apache web server. At first, let’s learn about essential prerequisites to proceed with installation steps.


We hope you you might be ready with all above software packages installed on your Ubuntu server and have a sudo enabled user to follow installation steps properly.

Steps To Install WordPress On Ubuntu 20.04 With LAMP

Since WordPress CMS requires some PHP packages, a database with privileged MySQL user account and some configuration in Ubuntu server, we will discuss every elements here.

Step 1: Install Essential PHP Extensions

While installing LAMP stack on Ubuntu server, we have just installed minimal set of extensions to allow PHP communicating with MySQL. But, WordPress requires some more additional PHP extensions to work smoothly.

So, download and install some essential PHP extensions required by WordPress with the commands below:

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

This will install the essential PHP extensions on your server which the WordPress basically requires to run. In case if you need more set of extensions which are specifically required by WordPress plugins (If you require), you can install them similarly as mentioned above.

Now, restart the Apache to load these newly installed extensions.

sudo systemctl restart apache2

Step 2: Creating MySQL Database and User

After installing PHP extensions, the next is to create a database and a user account to handle the database. Since WordPress need a database to serve dynamic content, and MySQL is the best option that the CMS supports. You might have already installed MySQL server on your Ubuntu 20.04, so we just need to create a database for your new WordPress installation.

Also Read:   How To Install and Secure PhpMyAdmin With Lemp Stack (Ubuntu 20.04)

If you have not yet installed MySQL, read here how to install it.

So, we first need to log in to MySQL with a user having root access. Just run the commands below:

sudo mysql (If MySQL is configured to use Unix_socket)


sudo mysql -u root -p (If MySQL is configured to use native_password)

The above command will let you open MySQL prompt where you can run queries to create database, users and manage them. For more information about how to create database and users, read the instructions here.

Run the command below to create a database for your WordPress:

Note: We have used servo_database, and servo_user as the name for database and user account as example. You should change them according to your own requirements.

mysql> CREATE DATABASE servo_database DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Now, we will create a MySQL user account that will be assigned with privileges to access and manage the above created database. Change servo_password with your own password:

mysql> CREATE USER 'servo_user'@'%' IDENTIFIED WITH mysql_native_password BY 'servo_password';

We will now assign servo_user with complete privileges to access above created database with command below:

mysql> GRANT ALL ON servo_database.* TO 'servo_user'@'%';

Thus, we have successfully created a database, and user account to access the database for your WordPress. Now, just flush privileges to load new changes and exit MySQL server with commands below:

mysql> EXIT;

Step 3: Creating Apache Virtual Host For WordPress

Obviously, we need now to create and configure Apache virtual host to serve WordPress site with your desired domain ( is taken as example).

To do so, we will create a new virtual host file under /etc/apache2/sites-available/ directory, and the file will be named as

sudo nano /etc/apache2/sites-available/

in the opened file, copy and paste the following code. Do make sure to change the highlighted values to your own required values.

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/>
AllowOverride All

Once done, save and close the file by hitting CTRL + S and CTRL + X respectively.

In order to check the new Apache virtual host file for syntax error, run the command below:

sudo apache2ctl -t

If the test detects no errors, you can enable the new virtual host and reload Apache2 service to apply new changes with commands below. Otherwise, check your host file to any issues and fix it.

sudo a2ensite
sudo systemctl reload apache2

Do make sure to delete default virtual host to make sure if the new site loading properly. In order to do this, run the commands here:

sudo a2dissite 000-default.conf
sudo systemctl reload apache2

Also, run the command below to enable mod_rewrite so as the WordPress can utilize the permalink feature easily:

sudo a2enmod rewrite
sudo systemctl restart apache2

So, here you have successfully created virtual host for your WordPress site and enabled it as well to run properly.

Also Read:   How To Install NVIDIA Graphics Drivers In Linux- Ubuntu/Debian/Fedora

To secure your site with free Let’s Encrypt SSL, read this article.

Step 4: Downloading WordPress and Configuring Its Directory

Since you have configured the virtual host for your WordPress, you can now download the CMS source code from its official website and configure the WordPress directory.

At first, change into a /tmp directory and download the compressed WordPress file:

cd /tmp
curl -O

Now, extract the compressed file and create .htaccess in the de-compressed directory with the commands below:

tar xzvf latest.tar.gz
touch /tmp/wordpress/.htaccess

Next is to copy wp-config-sample.php into wp-config.php and create a directory named “upgrade” within /tmp/wordpress/wp-content/ directory.

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
mkdir /tmp/wordpress/wp-content/upgrade

So, we can now copy and paste all entire content in wordpress directory into /var/www/ Just execute the command below. Do mention to replace the highlighted field as per your need.

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

Till now, we have copied wordpress files into required domain root directory, still we need to change some ownership and permissions before we start setting-up WordPress configuration file.

To change ownership of files to www-data and file’s permission, run the following commands:

sudo chown -R www-data:www-data /var/www/
sudo find /var/www/ -type d -exec chmod 750 {} \;
sudo find /var/www/ -type f -exec chmod 640 {} \;

Step 5: WordPress Configuration File Set-up

In order to set-up wp-config.php file, first we need to adjust some secret keys to provide a level of security for our WordPress site. You can grab these keys from a secure generator which you can copy and paste in site’s configuration file. To retrieve the keys, run the command below:

curl -s

here’s the output example you would receive on screen:

define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9 DO NOT COPY THESE VALUES c_j{iwqD^<+c9.k<[email protected]');
define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7X DO NOT COPY THESE VALUES {Ka(f;rv?Pxf})CgLi-3');
define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF DO NOT COPY THESE VALUES 2;y&,2m%3]R6DUth[;88');
define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+ DO NOT COPY THESE VALUES #`DXF+[$atzM7 o^-C7g');
define('AUTH_SALT', 'koMrurzOA+|L_lG}kf DO NOT COPY THESE VALUES 07VC*Lj*lD&?3w!BT#-');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VY DO NOT COPY THESE VALUES C-?y+K0DK_+F|0h{!_xY');
define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3 DO NOT COPY THESE VALUES t6**bRVFSD[Hi])-qS`|');
define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q7 DO NOT COPY THESE VALUES 1% ^qUswWgn+6&xqHN&%');

Note: The above mentioned values are just for an instance, we suggest you to copy the values you just received. It’s recommended to generate new values each time while installing new WordPress website.

So, copy the output you received on your screen, and open the WordPress configuration file to modify its values:

sudo nano /var/www/

Scroll down the file to find the section that appears to be like the one mentioned in example below:

. . .

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

. . .

Delete these lines and paste the ones you have copied. Once done, you can feed the database and user details which we have created earlier. The sample is here:

. . .

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'servo_database' );

/** MySQL database username */
define( 'DB_USER', 'servo_user' );

/** MySQL database password */
define( 'DB_PASSWORD', 'servo_password' );

/** 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', '' );

. . .

Also, we need to set the filesystem method to “direct”. If not, the normal setting will ask you to enter FTP credentials while installing themes and plugins, or even while updating them. So, to setup filesystem as aforementioned, add the line below in wp-config.php file before it says, “That’s all. Happy blogging.”

define('FS_METHOD', 'direct');

Now, save and close the file.

Also Read:   How To Install A Device Driver On Linux- 2 Methods

Step 6: Complete WordPress Installation Through Web Interface

In order to complete the WordPress installation through web interface, we need to open server’s domain name or public IP address of Ubuntu 20.04 server in any browser. or Public IP Address

Select your preferred language and click on “Continue” button as mentioned in the image below:

wordpress 1

After this, the site will open the main setup page, where we need to enter a name for WordPress site, username, password, and admin email like details. After you input all those information, click on the Install WordPress button at the bottom.

wordpress 2

After clicking the button as aforementioned, you will be redirected to a page asking you to log in to your WordPress site with created login credentials.

Just click on “Log In” button on the page, and you will be taken to Worpdress login page. Just enter the login credentials you have created for your WordPress site, and the dashboard will appear before you like this.

wordpress 3

So, your WordPress installation is finished here, and you can start designing your site with installing new themes. Also, you can add various functions by adding new plugins.

Thus, we hope you have successfully learned how to install WordPress on Ubuntu 20.04 with LAMP/Apache web server. If you need to suggest any edit to this tutorial or need more additional help, you can visit Suggest Us page or share your issue in the comments section below


Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.