How to install WordPress with LAMP stack on Ubuntu 18.04

How to install WordPress with LAMP stack on Ubuntu 18.04

Install WordPress with LAMP stack on Ubuntu 18.04

WordPress is the world’s most popular and widely used content management system or blog platform. WordPress can be used as a blog, e-commerce platform, or portfolio website. On the back end, WordPress uses a MySQL database for storage and works with PHP processing. WordPress has many features, and these features can also be extended using the various plugins available. In this tutorial, you will learn how to install WordPress on Ubuntu 18.04 with a LAMP (Linux, Apache, MySQL, and PHP) stack.

Prerequisites

Before installing WordPress on Ubuntu with a LAMP (Linux, Apache, MySQL, and PHP) stack. The server requires a non-root user account with sudo privileges. You also need the following:

  • I used this tutorial to install Apache on an Ubuntu system.
  • The domain must point to the Ubuntu server where WordPress will be installed.
  • You also need to install a LetsEncrypt SSL certificate using this tutorial.
  • Install MySQL or MariaDB for the backend database.

Install PHP

At the time of this writing, PHP 7.2 is currently the latest stable version of the PHP language. If necessary, you can also check the official PHP website for the latest version installation.

First, enter the following command to update the apt package manager index and upgrade packages.

sudo apt update && sudo apt upgrade

Now, to install PHP and all required modules, run the following command in a terminal:

sudo apt install php7.2 php7.2-opcache php7.2-gd php7.2-mysql php7.2-json php7.2-mbstring php7.2-curl php7.2-cli php7.2-xml

You can check the PHP installation by entering the following command:

php -v

Now you need to restart the apache service. You can restart by running the following command:

sudo systemctl restart apache2

Create MySQL database and grant privileges

If MySQL is not installed on your system, you can install it with this tutorial.

Log in to the MySQL database first using the following command:

mysql -u root -p

The above command will prompt for the root user password. Enter your password to continue.

Enter the following command to create a MySQL database for WordPress.

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Next, create a MySQL user and grant permissions using the following command:

GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'enter-password-here';

Flush the database so that the current MySQL version is aware of these changes.

FLUSH PRIVILEGES;

Exit MySQL using the following command:

EXIT;

WordPress download and setup

Go to /tmp Directory using the following command:

cd /tmp

Download the latest WordPress setup using wget Command, you can also use curl Here the command:

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

You need to extract the downloaded file using the following command:

tar xzvf latest.tar.gz

Create a WordPress configuration file using the following command:

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

Then, copy all files example.com Directory using the following command:

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

Change ownership now example.com Directory using the following command:

sudo chown -R www-data:www-data /var/www/example.com

To set up a WordPress configuration file, you need to generate some configuration files for it. Execute the following command:

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

The generated output keys are as follows:

define('AUTH_KEY',         'm=w)!7{-EEc&[email protected]/?!>_hcF*BmQ+S2Do!QP>>O-|OI21');
define('SECURE_AUTH_KEY',  'S?lk-{RG 5K~sd*1$Ni*8?IA#h/[email protected]?6MezjmoBWm&&b+h1YP?T.]Y=&*^h9[Bm`ThdbJ5zepb824LUd;-');
define('NONCE_KEY',        'cPim1L6}H1rQLtLj|FrN1DO:LZVsh`rr}5 `}k,f~%u)papX4|_J^Q%PKJ44uF[l');
define('AUTH_SALT',        ',+Aa_iZ/%yj5?-0F.O>Ogd6jCLU+2_2M$+1Zo-hUog70lLa$)[email protected]<~v!Acd');
define('SECURE_AUTH_SALT', '-9sQ8iLS}1-iEX)bm9ZJ5eVAq0X;we}jvw:JNkKm-O|-=GdH-{I><`J(ZgKB'); define('NONCE_SALT', 'c_VY?z=E}2r0A&r!F/qk*rtM3>K-Id+z*qG*^2g#4/-sR2%GP>b|{<97nL4uP8K/');

Open now /var/www/example.com/wp-config.php File,

sudo nano /var/www/example.com/wp-config.php

Find below the section and replace it with the above data.

How to install WordPress using LAMP stack in Ubuntu 18.04 -configuration How to install WordPress with LAMP stack on Ubuntu 18.04 – Settings

Now, you need to update the database connection configuration file as follows: password-you-provided With the password entered in the above steps:

define('DB_NAME', 'wordpress');

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

/** MySQL database password */
define('DB_PASSWORD', 'password-you-provided');

define('FS_METHOD', 'direct');

Configure Apache

In session /etc/apache/sites-available/example.com.conf File:

sudo nano /etc/apache/sites-available/example.com.conf

Paste the following code into the above file.

  ServerName example.com

  Redirect permanent / https://example.com/

  DirectoryIndex index.html index.php
  DocumentRoot /var/www/example.com

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem

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

  Options FollowSymLinks
  AllowOverride All
  Require all granted

Then create a symbolic link from the directory sites-available To sites-enabled:

sudo a2ensite example.com

Restart Apache using the following command:

sudo systemct restart apache2

Test WordPress

Now open your browser and go to the website URL.

Appears at the bottom of the window:

How to install WordPress using LAMP stack on Ubuntu 18.04-How to Install WordPress on LAMP Stack on Ubuntu 18.04 – Language Selection

You are now also required to configure the database and set up authentication. Enter the appropriate input and welcome to WordPress:

How to install WordPress using LAMP stack on Ubuntu 18.04-WordPress Home How to install WordPress with LAMP stack on Ubuntu 18.04 – WordPress Home

Conclusion

You learned how to install WordPress on Ubuntu 18.04 using the LAMP stack. If you have any questions, don't forget to comment them out.

Sidebar