Tag: Ubuntu 24.04 on google cloud platform

  • Complete WordPress Installation Guide: Easy Step-by-Step Setup with MySQL and Nginx on Ubuntu 24.04 GCP Server

    Complete WordPress Installation Guide: Easy Step-by-Step Setup with MySQL and Nginx on Ubuntu 24.04 GCP Server

    Installing WordPress on GCP Prerequisites

    • A GCP Ubuntu 24.04 VM instance (e.g., Compute Engine).
    • A domain name pointed to your VM’s public IP (optional but recommended).
    • SSH access to the VM (via GCP Console or an SSH client).
    • Sudo privileges for the user.
    • Basic familiarity with Linux terminal commands.

    Step 1: Set Up and Secure the Server

    1. SSH into Your VM:
      In GCP Console, go to Compute Engine > VM instances, select your instance, and click SSH to open a terminal.
    2. Update the System:
      Bash
      sudo apt update && sudo apt upgrade -y
      Important Warning
      Ensure HTTP (port 80) and HTTPS (port 443) are allowed in GCP’s firewall

    Step 2: Install Nginx

    1. Install Nginx:
      Bash
      sudo apt install nginx -y

    2. Start and Enable Nginx:
      Bash
      sudo systemctl start nginx sudo systemctl enable nginx

    3. Verify Nginx:
      Bash
      curl http://localhost
      Or open a browser and navigate to http://. You should see the Nginx welcome page.

    Step 3: Install MySQL

    1. Install MySQL Server:
      Bash
      sudo apt install mysql-server -y
    2. Secure MySQL Installation:
      Bash
      sudo mysql_secure_installation
      Follow prompts:
      – Set a root password (choose a strong one).
      – Remove anonymous users: Y.
      – Disallow root login remotely: Y.
      – Remove test database: Y.
      – Reload privilege tables: Y.
    3. Create a WordPress Database and User:
      Bash
      sudo mysql -u root -p
      In the MySQL prompt:
      sql
      CREATE DATABASE wordpress;
      CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘your_strong_password’;
      GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’;
      FLUSH PRIVILEGES;
      EXIT;
      Replace your_strong_password with a secure password.

    Step 4: Install PHP and Required Extensions

    1. Install PHP and Extensions: WordPress requires PHP and specific extensions for functionality.
      Bash
      sudo apt install php8.3-fpm php8.3-mysql php8.3-common php8.3-xml php8.3-curl php8.3-gd php8.3-mbstring php8.3-opcache php8.3-zip php8.3-intl -y

    2. Verify PHP:
      Bash
      php –version

    3. Configure PHP for WordPress:
    • Edit php.ini to increase upload limits:
      Bash
      sudo nano /etc/php/8.3/fpm/php.ini

      Find and set:
      Text
      upload_max_filesize = 64M
      post_max_size = 64M

    • Restart PHP-FPM:
      Bash
      sudo systemctl restart php8.3-fpm

    Step 5: Install WordPress

    1. Download WordPress:
      Bash
      cd /tmp
      wget https://wordpress.org/latest.tar.gz
      tar -xvzf latest.tar.gz
    2. Move WordPress Files:
      Bash
      sudo mv wordpress /var/www/html/wordpress
      sudo chown -R www-data:www-data /var/www/html/wordpress
      sudo chmod -R 755 /var/www/html/wordpress
    3. Configure WordPress Database Settings:
      Bash
      cd /var/www/html/wordpress
      sudo cp wp-config-sample.php wp-config.php
      sudo nano wp-config.php

      Update the following lines with your database details:
      Bash
      define(‘DB_NAME’, ‘wordpress’);
      define(‘DB_USER’, ‘wordpressuser’);
      define(‘DB_PASSWORD’, ‘your_strong_password’);
      define(‘DB_HOST’, ‘localhost’);

      Save and exit.

    Step 6: Configure Nginx for WordPress

    1. Create an Nginx Server Block:
      Bash
      sudo nano /etc/nginx/sites-available/wordpress

      Add the following configuration (replace example.com with your domain or server IP):
    server {
        listen 80;
        listen [::]:80;
        root /var/www/html/wordpress;
        index index.php index.html index.htm;
        server_name example.com www.example.com;
    
        client_max_body_size 64M;
    
        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;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.ht {
            deny all;
        }
    }

    Save and exit.

    2. Enable the Site:

    Bash
    sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

    3. Test and Reload Nginx:

    Bash
    sudo nginx -t
    sudo systemctl reload nginx

    Step 7: Secure with Let’s Encrypt SSL (Optional but Recommended)

    1. Install Certbot:
      Bash
      sudo apt install certbot python3-certbot-nginx -y
    2. Obtain and Install SSL Certificate:
      Bash
      sudo certbot –nginx –agree-tos –redirect –hsts –staple-ocsp –email your_email@example.com -d example.com -d www.example.com
      – Replace your_email@example.com and example.com with your email and domain.
      – This automatically configures Nginx for HTTPS and redirects HTTP to HTTPS.
    3. Verify HTTPS:
      – Visit https://example.com. You should see the WordPress setup wizard.

    Step 8: Complete WordPress Installation

    Access WordPress:

    • Open a browser and navigate to http://<your-server-ip>/wordpress or https://example.com (if SSL is configured).
    • Follow the WordPress setup wizard:
      • Select your language.
      • Enter site title, admin username (avoid “admin” for security), password, and email.
      • Click Install WordPress.

    Log In:

    • Go to http://<your-server-ip>/wordpress/wp-admin or https://example.com/wp-admin.
    • Log in with your admin credentials.

    Step 9: Post-Installation Steps

    1. Set Up DNS (if using a domain):
      – Point your domain’s A record to your GCP VM’s public IP in your DNS provider’s settings.
      – Wait for DNS propagation (may take up to 48 hours).
    2. Secure File Permissions:
      Bash
      sudo chown -R www-data:www-data /var/www/html/wordpress
      sudo chmod -R 755 /var/www/html/wordpress
      sudo chmod 640 /var/www/html/wordpress/wp-config.php
    3. Enable Caching (Optional):
      – Install a caching plugin like W3 Total Cache or WP Super Cache via the WordPress dashboard.
      – For advanced caching, configure Nginx FastCGI Cache or Redis (requires additional setup).

    Troubleshooting Tips

    Nginx Welcome Page Instead of WordPress:

    • Ensure the Nginx server block points to /var/www/html/wordpress and is enabled.
    • Remove the default Nginx site:
    Bash
    sudo rm /etc/nginx/sites-enabled/default
    sudo systemctl reload nginx

    Database Connection Error:

    • Verify wp-config.php credentials match the MySQL database/user settings.
    • Ensure MySQL is running:
    Bash
    sudo systemctl status mysql

    Wizard Not Loading:

    • Install missing PHP extensions:
    Bash
    sudo apt install php8.3-imagick php8.3-bcmath -y
    sudo systemctl restart php8.3-fpm

    Permission Issues:

    • Double-check ownership (www-data) and permissions (755 for directories, 644 for files, 640 for wp-config.php).
    Bash
    sudo chown -R www-data:www-data /var/www/html/wordpress
    sudo chmod -R 755 /var/www/html/wordpress
    Notes:
    Backup Strategy: Regularly back up your WordPress files (/var/www/html/wordpress) and MySQL database using tools like mysqldump or plugins like UpdraftPlus.
    Performance: Nginx is lightweight and ideal for high-traffic WordPress sites. Consider using a CDN (e.g., Cloudflare) for further optimization.
    Security: Keep your server, WordPress, and plugins updated. Use strong passwords and consider a security plugin like Wordfence.