How to Install WordPress with Apache on Google Cloud with Let’s Encrypt SSL. In this article you are going to learn how to setup and install WordPress on Google Cloud with Ubuntu 18.04 LTS, Apache, PHP 7.3 and Cloud SQL.


  1. Your Compute Engine Instance running.
  2. For setting up Compute Engine, see the Setting up Compute Engine Instance.
  3. For installing Apache, see how to install Apache in Compute Engine Instance.
  4. Install PHP 7.3 for Apache on Google Cloud Platform.
  5. Set up Cloud DNS, see the Setting up Google Cloud DNS for your domain.
  6. Google Cloud SQL Setup, see Setup Cloud SQL and connect with Compute Engine.

Setup your website

Once you have installed PHP 7.3 and Apache you can proceed to setup your directories.

Your website will be located in the home directory and have the following structure.

Replace with your original domain name.

---- logs
---- public

The public directory is your website’s root directory and logs directory for your error logs

Now we create these directories and set correct permissions

You need to SSH into your VM Instance and run these commands

mkdir -p
sudo chmod -R 755

Now create a new V host configuration for your website in the sites-available directory.

sudo nano /etc/apache2/sites-available/

Copy and paste the following configuration, ensure that you change the server_name, error_log and root directives to match your domain name. Hit CTRL+X followed by Y to save the changes.

<VirtualHost *:80>

DocumentRoot /home/username/

<Directory /home/username/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted

ErrorLog ${APACHE_LOG_DIR}/yourdomainname.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomainname.com_access.log combined </VirtualHost>

To enable this newly created website configuration, symlink the file that you just created into the sites-enabled directory.

sudo a2ensite

Check your configuration and restart Apache for the changes to take effect

sudo systemctl restart apache2

Install SSL certificate

HTTPS is a protocol for secure communication between a server (instance) and a client (web browser). Due to the introduction of Let’s Encrypt, which provides free SSL certificates, HTTPS are adopted by everyone and also provides trust to your audiences.

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-apache

Now we have installed Cert bot by Let’s Encrypt for Ubuntu 18.04, run this command to receive your certificates.

sudo certbot --apache -m -d -d

Select all the domains you need to receive the certificate and hit Enter

The Cert bot client will automatically generate the new certificate for your domain.

Now you will be asked to create a redirection to https

Select the appropriate option and hit Enter

Renewing SSL Certificate

Certificates provided by Let’s Encrypt are valid for 90 days only, so you need to renew them often. Now you set up a cronjob to check for the certificate which is due to expire in next 30 days and renew it automatically.

sudo crontab -e

Add this line at the end of the file

0 0,12 * * * certbot renew >/dev/null 2>&1

Hit CTRL+X followed by Y to save the changes.

This cronjob will attempt to check for renewing the certificate twice daily.

Download WordPress

Now that our server software is configured, we can download and set up WordPress.

It is always recommended to get the latest version of WordPress from their website.

cd ~/
curl -LO

This command will download the latest version and it needs to be extracted.

tar xzvf latest.tar.gz

Now, you can copy the entire contents of the directory into our document root.

sudo cp -a ~/ ~/

Next cleanup your root directory by deleting the wordpress folder and the downloaded tar file.

sudo rm -r ~/
sudo rm -f ~/

Set correct permissions for the root folder. Don’t forget to replace the with your domain name

sudo chown -R www-data:www-data ~/

Installing WordPress and setting up Configuration File

Now visit your website in the browser and select the language you would like to use and click continue.

You will be prompted to enter your database, user, password, and hostname.

Enter the database name we created in Cloud SQL and the user assigned with the database with the password. Finally, enter the IP address of Cloud SQL as the hostname.

Now you can run the installation.

Once the Installation is complete we need to set the method that WordPress should use to write to the file system. Since we’ve given the web server permission to write where it needs to, we can explicitly set the file system method to “direct”. Failure to set this with our current settings would result in WordPress prompting for FTP credentials when we perform some actions like WordPress update, plugin updates, file upload, etc. This setting can be added below the database connection settings in the configuration file.

sudo nano ~/

Find the line define('DB_PASSWORD', 'password'); and paste the following line below it.

define('FS_METHOD', 'direct');

Hit Ctrl+X and Y to save your configuration file.

Now your WordPress is installed and ready to use.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Like this post...

Signup for FREE Cloudbooklet Newsletter
Please help us get 1000 likes in Facebook. Thank You!

Stay Connected!

Get latest tutorials on Google Cloud and Open Source topics