Deploy Wordpress with LEMP Stack Ubuntu 24.04
Install Nginx
sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
Install MariaDB
sudo apt install mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
Create a Database for WordPress
sudo mysql -u root -p
Then in the MariaDB shell:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Install PHP and Required Extensions
sudo apt install php-fpm php-mysql php-xml php-mbstring php-curl php-gd php-zip
Configure Nginx for WordPress
Create a server block config:
sudo nano /etc/nginx/sites-available/wordpress
Insert the following, updating your_domain
accordingly:
server {
listen 80;
server_name your_domain;
root /var/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Download and Set Up WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo rsync -avP wordpress/ /var/www/wordpress/
sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress/ -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 644 {} \;
Configure wp-config.php
cd /var/www/wordpress
cp wp-config-sample.php wp-config.php
Edit these lines in wp-config.php
:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
Complete WordPress Installation
Visit http://your_domain
in your web browser to finish the installation via the WordPress web interface.
You now have a LEMP stack with MariaDB and WordPress running on Ubuntu 24.04.