Support > About cybersecurity > A detailed tutorial for setting up a personal WordPress site on Linux
A detailed tutorial for setting up a personal WordPress site on Linux
Time : 2025-02-21 10:47:04
Edit : Jtti

WordPress as a PHP language development of the blog platform, users can build their own personal blog website through WordPress. Building a personal WordPress site on Linux is a very practical skill that not only helps users better understand Web development and server administration, but also allows users to have a website that is completely their own. The following is a detailed building tutorial, suitable for novice reference.

During the preparation phase, ensure that the Linux system is installed and running. Ubuntu Server or CentOS are recommended because they have good community support and a wealth of packages.

WordPress requires a Web server, PHP, and a database to run. You can choose between LAMP (Linux, Apache, MySQL, PHP) or LNMP (Linux, Nginx, MySQL, PHP) stacks.

Install LAMP stack (recommended) Update system package:

sudo apt updatesudo apt upgrade -y

To install Apache:

sudo apt install apache2 -y

To install MySQL:

sudo apt install mysql-server mysql-client -ysudo mysql_secure_installation

To install PHP:

sudo apt install php libapache2-mod-php php-mysql -y

To restart the Apache service:

sudo systemctl restart apache2

Installing the LNMP stack (optional)

To install Nginx:

sudo apt install nginx -y

To install MySQL:

sudo apt install mysql-server mysql-client -ysudo mysql_secure_installation

To install PHP-FPM:

sudo apt install php-fpm php-mysql -y

Edit the Nginx configuration file /etc/nginx/sites-availables/default to configure nginx and add the following:

server {

listen 80;

server_name your_domain_or_IP;

root /var/www/html;

index index.php index.html;

location / {

try_files $uri $uri/ =404;

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix: /var/run/ph/php7.4-pfm.sock; # Adjust according to your PHP version

}}

To restart the Nginx service:

sudo systemctl restart nginx

Create a website directory:

sudo mkdir -p /var/www/html/wordpress

Download the latest version of WordPress:

cd /var/www/html/wordpresssudo wget https://wordpress.org/latest.tar.gzsudo tar -xzvf latest.tar.gzsudo mv wordpress/*  ./sudo rm -rf wordpress latest.tar.gz

Set file permissions:

sudo chown -R www-data:www-data /var/www/html/wordpresssudo chmod -R 755 /var/www/html/wordpress

Log in to MySQL:

sudo mysql -u root -p

Create WordPress database and users:

CREATE DATABASE wordpress_db; CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';

FLUSH PRIVILEGES; EXIT;

Copy the configuration file:

cd /var/www/html/wordpresssudo cp wp-config-sample.php wp-config.php

Edit the wp-config.php file:

sudo nano wp-config.php

Modify the following:

define('DB_NAME', 'wordpress_db'); define('DB_USER', 'wordpress_user'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');

Access the WordPress installation wizard. Open a browser and access your server IP address or domain name:

http://your_server_ip_or_domain

Follow the WordPress installation wizard to complete the installation: Select language. Enter the site title, administrator username, password, and email address. Click "Install WordPress".

If you have your own domain name, you can point it to your server IP address and update server_name in the Web server configuration file.

Edit /etc/apache2/sites-available/your_domain.conf:

<VirtualHost *:80>

ServerName your_domain.com

DocumentRoot /var/www/html/wordpress

<Directory "/var/www/html/wordpress">

AllowOverride All

</Directory>

</VirtualHost>

Start the site and restart Apache:

sudo a2ensite your_domain.confsudo systemctl restart apache2

Edit /etc/nginx/sites-available/your_domain:

server {

listen 80;

server_name your_domain.com;

root /var/www/html/wordpress;

index index.php index.html;

location / {

try_files $uri $uri/ =404;

}

location ~ \.php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix: /var/run/ph/php7.4-pfm.sock; # Adjust according to your PHP version

}}

To enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/sudo systemctl restart nginx

To improve security, you are advised to install an SSL certificate for your website. You can use a free certificate from Let's Encrypt. To install Certbot:

sudo apt install certbot python3-certbot-apache -y

To obtain and install an SSL certificate:

sudo certbot --apache -d your_domain.com

Automatic renewal: Certbot automatically configures a scheduled task to automatically renew certificates every two months.

Install security plug-ins such as Wordfence or Sucuri to enhance WordPress security.

Back up data: Back up database and website files regularly.

Optimize performance: Use caching plug-ins (like W3 Total Cache) and CDN services (like Cloudflare).

By following these steps, you can successfully set up a personal WordPress site on Linux. From installing the LAMP/LNMP stack to configuring WordPress to installing an SSL certificate, every step is critical. Hopefully, this tutorial will help you get your own WordPress site up and running.

Relevant contents

Specific scenarios for installing and configuring Samba in Ubuntu Linux mount command usage tutorial Factors to consider when choosing a DCIM solution Common uses of the Linux Touch command Procedure for installing Python PIP on Windows Streaming platforms migrate from client-side to server-side adaptive bitrate streaming The impact of artificial intelligence on power consumption in data centers High-defense CDN acceleration and DDoS attack defense Artificial intelligence is reshaping the data center, transforming everything from infrastructure to sustainability CDN acceleration principle and CDN acceleration technology
Go back

24/7/365 support.We work when you work

Support