How To Install WordPress on Ubuntu 18.04 With LAMP

WordPress and LAMP

WordPress is a popular open-source technology used for making websites and blogs on the internet. LAMP stack, on which most WordPress sites run is just a combination of software packages that includes Linux, Apache, MySQL, and PHP.

Installing WordPress on Ubuntu 18.04 using a LAMP stack

Before starting, you need the following setup:

  • LAMP stack: It needs a web server, a database engine, and PHP for serving dynamic content.
  • SSH access to the server.

Step 1: Create a database for WordPress user

The first step for installing WordPress is to set up a MySQL database to store WordPress files.

To do this, log in to MySQL as a root user by using the below command:

mysql -u root -p

After you have logged in, now create a new database to accommodate WordPress files during and after the installation process. Let’s name it wordpressdb.

To create the database, run the following command

mysql> CREATE DATABASE wordpressdb;

After creating a database, you need to create a new MySQL user account that will have access to the database. Grant the user full access to the database and set a strong password. Let’s create a user named admin-user.

Use the following command

mysql> GRANT ALL ON wordpress.* TO 'admin-suser'@'localhost' IDENTIFIED BY 'PASSWORD';

At this point, we’ve created a database and a user account specifically for WordPress.

To apply the changes in the MySQL instance, we need to run the command below

mysql> FLUSH PRIVILEGES;

Then we’ll exit the MySQL instance by running the command

mysql>   EXIT;

Step 2: Install additional PHP extensions

LAMP stack requires fewer sets of extensions for PHP to communicate with the MySQL database server. However, WordPress and many of its plugins require additional extensions.

Let’s update the system first using:

# sudo apt update

Next, install the additional PHP extensions:

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

To load these extensions, restart the Apache webserver by using the below-mentioned command:

# sudo systemctl restart apache2

Step 3: Downloading WordPress

It is highly recommended  to download WordPress from its official repository due to security reasons:

First Navigate to /var/www/ directory

# cd  /var/www/```

Now download the zip folder

# curl -O https://wordpress.org/latest.tar.gz

Extract the tarball file

# tar -xvf latest.tar.gz

The extraction of the tarball file releases a folder named WordPress.

This is the folder that has all the WordPress configuration files. Now, you can safely delete the tarball file that was just downloaded from the WordPress repository.

# rm latest.tar.gz

Step 4: Configure the WordPress directory

Before moving on to the next step, we need to make changes in the ownership and file permissions of the WordPress directory.

You can assign file ownership to all the files in the WordPress directory using the command:

# sudo chown -R www-data:www-data /var/www/wordpress

Next, correct the permissions as:

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

Rename the sample configuration file in the WordPress directory to a filename it can read from:

# cd /var/www/wordpress
# mv wp-config-sample.php wp-config.php

Next, open the wp-config.php file using the default text editor Vim.

# vim  wp-config.php

Locate the database settings as displayed below. Fill in the WordPress database name, database user, database password and hostname.

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');
/** MySQL database username */
define('DB_USER', 'admin-user');
/** MySQL database password */
define('DB_PASSWORD', 'StrongPassword');



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

Save and exit the configuration file.

For WordPress installation, you need to generate security by using. automatic generator provided by WordPress.

To generate values from the WordPress generator, use the below syntax:

# curl -s https://api.wordpress.org/secret-key/1.1/salt/

define('AUTH_KEY',      'UV>...SAMPLE ONLY...COPY YOUR OWN VALUES...mL)');
define('SECURE_AUTH_KEY',  'bn(UV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emL)zx');
define('LOGGED_IN_KEY',    '-naUV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emL{fY');
define('NONCE_KEY',     '{xNwUV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emL8Fq');
define('AUTH_SALT',        'j+;UV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emLZpu');
define('SECURE_AUTH_SALT', '0M=UV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emL*xC');
define('LOGGED_IN_SALT',   'G&2UV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emLps+');
define('NONCE_SALT',    '2gZUV>...SAMPLE ONLY...COPY YOUR OWN VALUES...emLh/L');

Copy the unique output that you’ve generated.

Open the WordPress configuration file wp-config.php

# vim  wp-config.php

Scroll and locate the section that consists of  dummy values, as 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 those values and place the security keys generated by WordPress.

Save and exit the configuration file.

Step 5: Modify Apache configuration

Make a few adjustments to the default configuration file 000-default.conf in the path /etc/apache2/sites-available.

Open the default configuration file using the command below:

# vim  /etc/apache2/sites-available/000-default.conf

Locate the DocumentRoot attribute and change it from /var/www/html to /var/www/wordpress.

In the same file, copy and paste the following lines inside the Virtual Host block.

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

wordpress install

Save and exit the configuration file.

Enable the mod_rewrite so that you can use the WordPress Permalink feature.

# sudo a2enmod rewrite

Execute the command to verify everything went well:

# sudo apache2ctl configtest

Output: Ok

Restart the Apache webserver to check changes.

# sudo systemctl restart apache2

Step 6: Run WordPress installation using the web browser

The final step is to complete the installation through a web browser.

Launch the web browser you are using and the browser server’s IP address or domain name

http://server_IP_address or http://YOUR-DOMAIN

The first page will ask you to select the language.

Select your preferred language and then click ‘Continue’.

Next, fill in the additional information required like ‘Site Name’, ‘Username’ , ‘Password’, and ‘Email address’.

wordpess install

Fill in the required fields, click on ‘Install WordPress’

If everything goes fine, then you will be directed to the Login Page.

Click the ‘Login’ button and you’ll see the WordPress dashboard that you see below:

wordpress install

If you are new to WordPress, there are many free resources for learning and customization. If you were able to install LAMP on your server and successfully execute the WordPress setup, then WordPress will be easy to use.