How to Install WordPress with LAMP Stack on Debian 9

Table of Contents
Install WordPress with LAMP Stack on Debian 9
WordPress is the most popular and widely used content management system or blogging platform in the world. WordPress can be used as a Blog, eCommerce platform, Portfolio Website. At the backend, WordPress uses a MySQL database for storage and works on PHP processing. WordPress provides a lot of features and these features can also be extended by using a wide variety of available plugins for it. In this tutorial, you are going to learn how to install WordPress with LAMP (Linux, Apache, MySQL, and PHP) stack on Debian 9.
Prerequisites
Before you start to install WordPress with LAMP (Linux, Apache, MySQL, and PHP) stack on Debian. You must have a non-root user account on your server with sudo privileges. Also, you should have:
- Apache Installed on your Debian system using this tutorial.
- Your Domain must be pointed to your Debian server on which you are going to install WordPress.
- You should also have installed the LetsEncrypt SSL certificate by using this tutorial.
- Install MySQL or MariaDB for the backend database.
Install PHP
Currently at the time of writing this tutorial PHP 7.2 is the latest stable version available of PHP language. If you want you can also check the latest version for installation on PHP official website.
First, update the apt package manager index and upgrade the packages by typing below command:
sudo apt update && sudo apt upgrade
Now to install PHP and all the required modules run below command in the 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 confirm PHP installation by typing below command:
php -v
Now you should restart the apache service, you can do so by running below command:
sudo systemctl restart apache2
Create MySQL Database and Grant Permissions
You should have MySQL installed on your system if it is not installed you can install it by this tutorial.
First log in to your MySQL database using below command:
mysql -u root -p
The above command will ask you to enter the password for the root user. Enter the password to go ahead.
Create the MySQL database for your WordPress typing below command:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Now create a MySQL user and grant permissions for it using below command:
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'enter-password-here';
Now flush the database so the current MySQL version will know about these changes:
FLUSH PRIVILEGES;
Exit MySQL using below command:
EXIT;
Download and Setup WordPress
Now navigate to /tmp
directory using below command:
cd /tmp
Download the latest WordPress setup using below wget
command, you can also use curl
command here:
curl -O https://wordpress.org/latest.tar.gz
You should extract the downloaded file using below command:
tar xzvf latest.tar.gz
Now create the configuration file for WordPress using below command:
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
Then copy all the files to example.com
directory using below command:
sudo cp -a /tmp/wordpress/. /var/www/example.com
Now change the ownership of example.com
directory using below command:
sudo chown -R www-data:www-data /var/www/example.com
To set up the WordPress configuration file you should generate some configuration files for it. Do so by running below command:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
The generated output keys should be:
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$N<aZ18jy|^0n#[email protected]#dJy2M-|jUruu[T+ cYfJ^@2-'); define('LOGGED_IN_KEY', '>i*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)b<A6(JNuPIGv2SV5ZiHV])[email protected]$4{[email protected]*fj8[ *Uc-'); define('LOGGED_IN_SALT', 'K$i5b^g?TK4M|w;mqlh>m9ZJ5eVAq0X;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/');
Now open the /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:

Now you should also update configuration file as given below for database connection by replacing password-you-provided
with the password you entered in above instructions:
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
Now open /etc/apache/sites-available/example.com.conf
file:
sudo nano /etc/apache/sites-available/example.com.conf
And paste the following code in 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
Next, to create a symlink from the directory sites-available
to sites-enabled
:
sudo a2ensite example.com
Restart Apache by using the following command:
sudo systemct restart apache2
Test WordPress
Now open the browser and navigate to your websites URL.
It will show you below window:

Now it will also prompt you for database configuration and authentication setup. Enter the proper inputs and you will be welcome to WordPress:

Conclusion
You have successfully learned how to install WordPress with LAMP stack on Debian 9. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to Install IntelliJ IDEA IDE on Ubuntu 18.04
-
How to Install phpMyAdmin on Linux Mint 19
-
How to Safely Remove Files and Directories Using Linux Command Line
-
How to Install Nginx on Debian 10
-
How to Install Netbeans on Debian 9
-
How to migrate MySQL database between two servers
-
How to Install Apache on Debian 10
-
How to List Installed Packages on Linux Mint 18
-
How to install Pip on Ubuntu 18.04
-
How to Install Docker Compose on Debian 10
-
How to Install Microsoft PowerShell 6.2.0 on Ubuntu 18.04
-
How to install LAMP stack on Ubuntu 18.04