Introduction:
Here, in this blog, we will discuss about installing WordPress on Google Cloud Platform(GCP). WordPress is a free and open-source content management system based on PHP and MySQL. For installing it on GCP, you need to have a registered GCP account. First you need to setup a LAMP server to create the required environment for installation.
Create a VM on GCP and Setup LAMP server:
For installing wordpress on GCP, we need to first create a Linux VM on GCP and setup a LAMP server.
In this blog we will use the following configurations:
- OS: Ubuntu 16.04
- Database: MySQL 5.7
- PHP: php v7.0
First, we need to create a Compute Engine VM on GCP along with a MySQL database on SQL service of GCP. Then you need to setup LAMP server on it for installing wordpress. You can follow my blog for the steps for creating a Compute engine VM and setting up a LAMP server on GCP.
Download WordPress:
Download the latest source code as shown below.
1 2 3 |
curl -O https://wordpress.org/latest.tar.gz sudo tar xzf latest.tar.gz -C /var/www rm -f latest.tar.gz |
Configure Apache:
Configure the Apache with the below configuration. If you need to run the wordpress on a domain , uncomment the ServerName and ServerAlias section and update your domain name. Else you can leave it as it is.
1 |
sudo vim /etc/apache2/sites-enabled/000-default.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<VirtualHost *:80> #ServerName mydomain.com #ServerAlias www.mydomain.com DocumentRoot /var/www/wordpress <Directory /var/www/wordpress> Options Indexes FollowSymLinks MultiViews Require all granted AllowOverride all </Directory> ErrorLog /var/log/apache2/error.log CustomLog /var/log/apache2/access.log combined </VirtualHost> |
Restart Apache server.
1 |
sudo service apache2 restart |
Create a MySQL Database and User:
Login to your MySQL server and create a user and database for your wordpress application. Change the database name, database user and password as per your need.
1 |
mysql -h <mysql-instance-public-ip> -u root -p |
1 2 3 4 5 |
> CREATE DATABASE wordpress; > CREATE USER 'wp_user'@'%' IDENTIFIED BY 'user_pwd'; > GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'%'; > FLUSH PRIVILEGES; > exit |
Configure WordPress:
Create a wp-config.php file on the document root from the sample configuration file.
1 2 |
cd /var/www/wordpress/ sudo cp wp-config-sample.php wp-config.php |
Update the database details in the wp-config.php file.
1 |
vim wp-config.php |
Update the details of the below lines in the file.
1 2 3 4 5 6 7 8 |
/** The name of the database for WordPress */ define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here'); /** MySQL hostname */ define('DB_HOST', 'localhost'); |
Also update the unique phrase in the wp-config.php file to secure the installation. Find and update the “unique phrase” in the file. You can simply generate it and copy paste to update it from here.
1 2 3 4 5 6 7 8 9 |
define('AUTH_KEY', 'put your unique phrase here'); define('SECURE_AUTH_KEY', 'put your unique phrase here'); define('LOGGED_IN_KEY', 'put your unique phrase here'); define('NONCE_KEY', 'put your unique phrase here'); define('AUTH_SALT', 'put your unique phrase here'); define('SECURE_AUTH_SALT', 'put your unique phrase here'); define('LOGGED_IN_SALT', 'put your unique phrase here'); define('NONCE_SALT', 'put your unique phrase here'); |
You can also use curl command using terminal like:
1 |
curl -s https://api.wordpress.org/secret-key/1.1/salt/ |
1 |
sudo chown -R www-data:www-data /var/www/wordpress |
Installing WordPress:
To install, enter the IP of the GCP VM in the web browser and hit enter. An installation page will be displayed as below:
Select your preferred language and click on continue. On the next page you need to provide the information like Site title, username and password and email ID. Note the username and password as you will need it late to login.
Provide the necessary information and click on install wordpress. On the next page, you will see a success message with the username that you entered in the previous page. Click on the login button to login to the wordpress admin. On the admin login page, enter the username and password and the admin dashboard page will be displayed as below.
Congrats, your wordpress site is now installed and you can start exploring it.
Stay Connected!
In case of any help or query, please contact us or raise a ticket at support@webkul.com.