How to Install WordPress with LEMP Stack on Debian 12
WordPress is a web content management system. It was originally created as a tool to publish blogs but has evolved to support publishing other web content, including more traditional websites, mailing lists and Internet forum, media galleries, membership sites, learning management systems and online stores.
Prerequisites
-
Root access to your Debian 12 server.
- LEMP Stack installed and running. Learn how to setup LAMP Stack.
Create Database
WordPress requires a database to store website files and data,
Login to MySQL using the below command,
mysql -u root -p
Create a new database.
CREATE DATABASE wordpressdb;
Create a new user.
CREATE USER "wpuser"@"localhost" IDENTIFIED BY "Password";
Replace the
Password
with a Strong unique password
Give the full read and write privileges to the database/user.
GRANT ALL PRIVILEGES ON wordpressdb.* TO "wpuser"@"localhost;
Refresh and Exit from MySQL.
FLUSH PRIVILEGES;
Exit
Configure Nginx
Create a new Nginx Virtual Host configuration file using your favourite1 editor,
nano /etc/nginx/sites-available/wordpress
Add the below content to the file,
Replace the
panel.domainhere.info
with the actual domain name
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
server_name panel.domainhere.info;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# Pass PHP requests to PHP_FPM
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location = /favicon.ico {
access_log off;
log_not_found off;
expires max;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Deny Access to Hidden Files such as .htaccess
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Disallow PHP files In the WordPress uploads directory
location /wp-content/uploads/ {
location ~ \.php$ {
deny all;
}
}
}
Save and exit the file.
Create a link to Activate the configuration file using the below command,
ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
Optionally, delete the default configuration file, if not in use,
rm /etc/nginx/sites-enabled/default
Validate Nginx configurations using the below command,
nginx -t
Output:
root@vps:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@vps:~#
Now, Restart the Nginx using the below command,
service nginx restart
Install and Configure WordPress
Download the latest WordPress version.
wget http://wordpress.org/latest.tar.gz
Extract files from the tar archive.
tar -xzvf latest.tar.gz
Move the downloaded file to the webroot directory /var/www/html
,
mv wordpress/* /var/www/html
Grant Nginx (running as www-data) full ownership rights to the directory.
chown -R www-data:www-data /var/www/html/
Restart Nginx to save the configuration,
systemctl restart nginx
Access WordPress
Navigate to your Domain name on your browser to launch the WordPress web installer and complete the installation,
Select Language,
Click on Let's Go to setup database configuration,
Fill the Database Configuration,
Click on Run the Installation,
Fill the New Site details,
Click to Log in,
Done!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS