Table of Contents
Learn how to Install WordPress with MySQL Nginx on Ubuntu 24.04 GCP server. Step-by-step guide covering database setup, web server configuration, and WordPress deployment on Google Cloud Platform.
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
- SSH into Your VM:
In GCP Console, go to Compute Engine > VM instances, select your instance, and click SSH to open a terminal. - Update the System:[note type=”warning” title=”Important Warning” icon=”fa-exclamation-triangle”]Ensure HTTP (port 80) and HTTPS (port 443) are allowed in GCPโs firewall[/note]Bash
sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx
- Install Nginx:Bash
sudo apt install nginx -y
- Start and Enable Nginx:Bash
sudo systemctl start nginx sudo systemctl enable nginx
- Verify Nginx:Or open a browser and navigate to http://. You should see the Nginx welcome page.Bash
curl http://localhost
Step 3: Install MySQL
- Install MySQL Server:Bash
sudo apt install mysql-server -y
- Secure MySQL Installation:Follow prompts:Bash
sudo mysql_secure_installation
– Set a root password (choose a strong one).
– Remove anonymous users: [inline_code type=”success”]Y[/inline_code].
– Disallow root login remotely: [inline_code type=”success”]Y[/inline_code].
– Remove test database: [inline_code type=”success”]Y[/inline_code].
– Reload privilege tables: [inline_code type=”success”]Y[/inline_code]. - Create a WordPress Database and User:In the MySQL prompt:Bash
sudo mysql -u root -p
Replace [inline_code type=”warning”]your_strong_password[/inline_code] with a secure password.sqlCREATE DATABASE wordpress; CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘your_strong_password’; GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’; FLUSH PRIVILEGES; EXIT;
Step 4: Install PHP and Required Extensions
- 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
- Verify PHP:Bash
php –version
- Configure PHP for WordPress:
- Edit [inline_code type=”warning”]php.ini[/inline_code] to increase upload limits:Bash
sudo nano /etc/php/8.3/fpm/php.ini
Find and set:Textupload_max_filesize = 64M post_max_size = 64M
- Restart PHP-FPM:Bash
sudo systemctl restart php8.3-fpm
Step 5: Install WordPress
- Download WordPress:Bash
cd /tmp wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz
- 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
- 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:Bashdefine(‘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
- Create an Nginx Server Block:Bash
sudo nano /etc/nginx/sites-available/wordpress
Add the following configuration (replace [inline_code type=”warning”]example.com[/inline_code] 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:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
3. Test and Reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 7: Secure with Letโs Encrypt SSL (Optional but Recommended)
- Install Certbot:Bash
sudo apt install certbot python3-certbot-nginx -y
- Obtain and Install SSL Certificate:– Replace [inline_code type=”warning”]your_email@example.com[/inline_code] and [inline_code type=”warning”]example.com[/inline_code] with your email and domain.Bash
sudo certbot –nginx –agree-tos –redirect –hsts –staple-ocsp –email your_email@example.com -d example.com -d www.example.com
– This automatically configures Nginx for HTTPS and redirects HTTP to HTTPS. - Verify HTTPS:
– Visit [inline_code type=”warning”]https://example.com[/inline_code]. You should see the WordPress setup wizard.
Step 8: Complete WordPress Installation
Access WordPress:
- Open a browser and navigate to [inline_code type=”warning”]http://<your-server-ip>/wordpress[/inline_code] or [inline_code type=”warning”]https://example.com[/inline_code] (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 [inline_code type=”warning”]http://<your-server-ip>/wordpress/wp-admin[/inline_code] or [inline_code type=”warning”]https://example.com/wp-admin[/inline_code].
- Log in with your admin credentials.
Step 9: Post-Installation Steps
- 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). - 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
- Enable Caching (Optional):
– Install a caching plugin like [inline_code type=”success”]W3 Total Cache[/inline_code] or [inline_code type=”success”]WP Super Cache[/inline_code] 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 [inline_code type=”warning”]/var/www/html/wordpress[/inline_code] and is enabled.
- Remove the default Nginx site:
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl reload nginx
Database Connection Error:
- Verify [inline_code type=”warning”]wp-config.php[/inline_code] credentials match the MySQL database/user settings.
- Ensure MySQL is running:
sudo systemctl status mysql
Wizard Not Loading:
- Install missing PHP extensions:
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).
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
[note type=”success” title=”Notes:” icon=”fa-check-circle”]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.[/note]