Wordpress installation in Raspberry Pi using Nginx

Amal Satheesan - Sep 2 - - Dev Community

We will be continuing from were we left off. Disclaimer: You can use apache if you want. Apache is easier to setup compared to Nginx.

Keywords used in the guide:

  • Raspberry Pi
  • NGINX server
  • WordPress
  • MySQL
  • PHP

Step 1: Update the Raspberry Pi

First, make sure your Raspberry Pi is up-to-date:

sudo apt update 
sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Step 2: Install NGINX

NGINX will serve as your web server.

  1. Install NGINX:

    sudo apt install nginx -y
    
  2. Start and enable NGINX:

    sudo systemctl start nginx
    sudo systemctl enable nginx
    
  3. Verify NGINX is running:

    sudo systemctl status nginx
    
  4. Check in a browser by typing your Raspberry Pi's IP address (e.g., http://192.168.x.x).

Step 3: Install MySQL (MariaDB)

WordPress needs a database, so we will install MariaDB.

  1. Install MariaDB server:

    sudo apt install mariadb-server -y
    
  2. Secure the installation:

    sudo mysql_secure_installation
    

    Follow the prompts to secure your database (set root password, remove anonymous users, disable root login remotely, etc.).

  3. Log in to MariaDB:

    sudo mysql -u root -p
    
  4. Create a database for WordPress:

    CREATE DATABASE wordpress;
    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    

Step 4: Install PHP

PHP will be used to process dynamic content for WordPress.

  1. Install PHP and necessary extensions:

    sudo apt install php-fpm php-mysql php-curl php-gd php-xml php-mbstring -y
    

Step 5: Configure NGINX to Use PHP

  1. Create an NGINX server block for WordPress:

    sudo nano /etc/nginx/sites-available/wordpress
    
  2. Add the following configuration:

    server {
        listen 80;
        server_name _;
        root /var/www/wordpress;
    
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ =404;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php-fpm.sock;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }
    
  3. Enable the configuration:

    sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
    sudo rm -r /etc/nginx/sites-enabled/default
    
  4. Test and restart NGINX:

    sudo nginx -t
    sudo systemctl restart nginx
    

Step 6: Download and Configure WordPress

  1. Install wget and unzip (if not installed):

    sudo apt install wget unzip -y
    
  2. Download WordPress:

    cd /var/www
    sudo wget https://wordpress.org/latest.zip
    sudo unzip latest.zip
    sudo mv wordpress /var/www/
    
  3. Set correct permissions:

    sudo chown -R www-data:www-data /var/www/wordpress
    sudo chmod -R 755 /var/www/wordpress
    
  4. Configure WordPress to connect to your database:

    cd /var/www/wordpress
    sudo cp wp-config-sample.php wp-config.php
    sudo nano wp-config.php
    

    Update the database settings in wp-config.php:

    define( 'DB_NAME', 'wordpress' );
    define( 'DB_USER', 'wpuser' );
    define( 'DB_PASSWORD', 'password' );
    define( 'DB_HOST', 'localhost' );
    

Step 7: Complete WordPress Installation

  1. Open your web browser and navigate to http://your_domain_or_IP.
  2. Follow the on-screen instructions to complete the WordPress installation.

After these steps, your Raspberry Pi should be hosting a fully functional WordPress site using NGINX, PHP, and MariaDB.

In the next blog, we will be hosting the site to public using a secure tunnel. Stay tuned for that....!

. . . . . . . .
Terabox Video Player