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:Bash
sudo apt update && sudo apt upgrade -y
Important WarningEnsure HTTP (port 80) and HTTPS (port 443) are allowed in GCP’s firewall
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:Y
.
– Disallow root login remotely:Y
.
– Remove test database:Y
.
– Reload privilege tables:Y
. - Create a WordPress Database and User:In the MySQL prompt:Bash
sudo mysql -u root -p
ReplacesqlCREATE DATABASE wordpress; CREATE USER ‘wordpressuser’@’localhost’ IDENTIFIED BY ‘your_strong_password’; GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpressuser’@’localhost’; FLUSH PRIVILEGES; EXIT;
your_strong_password
with a secure password.
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
php.ini
to increase upload limits:Bashsudo 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 (replaceexample.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)
- Install Certbot:Bash
sudo apt install certbot python3-certbot-nginx -y
- Obtain and Install SSL Certificate:– ReplaceBash
sudo certbot –nginx –agree-tos –redirect –hsts –staple-ocsp –email your_email@example.com -d example.com -d www.example.com
your_email@example.com
andexample.com
with your email and domain.
– This automatically configures Nginx for HTTPS and redirects HTTP to HTTPS. - Verify HTTPS:
– Visithttps://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
orhttps://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
orhttps://example.com/wp-admin
. - 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 likeW3 Total Cache
orWP 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.
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.
Leave a Reply