[ see also: Install guide for installing LAMP stack ]

[ jump to the WordPress Installation instructions ]

Prepare Your System

Welcome to your complete step-by-step guide to install NGINX, PHP, and MySQL on Linux (aka. the LEMP stack). This tutorial assumes a Debian-based system (Ubuntu, Mint, MX Linux, Kali, WSL, etc.).

I like the terminal-based text editor Micro, so I’ve included it here along with cURL and net-tools.

More on Micro

You may prefer Nano or VIM instead of Micro. There are many terminal editor options.

Nano exits with Ctrl+X, while Micro uses Ctrl+Q. To save in Micro: Ctrl+Esave.

Under WSL, clipboard behavior may differ. Nano is generally more predictable for copy/paste.

Before making system changes, update your package lists:


sudo apt update
sudo apt upgrade -f
sudo apt install micro curl net-tools

Line-by-line above :: All-in-one below


sudo apt update && sudo apt upgrade -f && sudo apt install -y micro curl net-tools

Install the “M” of LEMP: MariaDB / MySQL


sudo apt install mariadb-client mariadb-server mariadb-common dbconfig-common | tee ~/LXMP_install_mysql.txt
sudo service mariadb start
sudo mysql -u root

Line-by-line above :: All-in-one below


sudo apt install -y mariadb-client mariadb-server mariadb-common dbconfig-common \
&& sudo service mariadb start \
&& sudo mysql -u root

MySQL Root Password

Verify MySQL / MariaDB is running


MySQL >

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('*M*y*P*a*s*s*');

Create a secondary user:


GRANT ALL ON *.* TO 'USER02'@'%' IDENTIFIED BY '*U*S*R*2*pw*';
FLUSH PRIVILEGES;
exit;

Install NGINX and PHP

Install NGINX, PHP, and common extensions. Note the PHP version during installation.


sudo apt install -y nginx php-fpm php-curl php-imagick php-zip php-xml \
php-mysqli php-pdo php-gd php-mbstring php-xdebug php \
| tee ~/LXMP_install_nginx-php.txt

php -v | tee -a ~/LXMP_install_nginx-php.txt

Configure NGINX server_name


cd /etc/nginx/sites-available
ls -la

server {
    listen 80;
    server_name example.local;
    root /var/www/html;

    index index.php index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.(php|phtml)$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

Ensure the fastcgi_pass socket matches your installed PHP version.


php -v

Install WordPress with NGINX


sudo mkdir -p /var/www/html/wpcurl
sudo chown www-data: /var/www/html/wpcurl
sudo chmod 755 -R /var/www/html/wpcurl
cd /var/www/html/wpcurl

curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx
sudo mv wordpress/* .

If you prefer to keep the /wordpress subdirectory, omit the final mv command.

If you did not install phpMyAdmin, you can use Adminer by placing a single PHP file in your web root.