What is Google Cloud Platform – you can read on Wikipedia. We will not waste time on this. Back in 2017, I found out that Google gives a year of free use (balance of $ 300) to their service. But it so happened that I used hosting all the time, and there was no need to launch the web server from scratch.
Since I chose to create a website on WordPress, I need to use the web server with LAMP stack. To start using Google Cloud Platform we have to authorize in Google and sign up (it is required to provide credit card info). After sign up is done, we see the dashboard:
Then, we need to create a VM instance (Left sidebar -> Compute Engine -> VM instances). First of all, we have to name our VM, add an optional label and choose the region and zone (these parameters are permanent). After that, let’s move on to setting up our VM configuration: I choose the general-purpose type, N1 series (powered by Intel Skylake CPU platform or one of its predecessors) and g1-small (1 vCPU, 1.7 GB memory) machine type. Then, we need to configure our boot disk: I usually use Ubuntu as operating system, boot disk type – SSD persistent disk and 10 GB size (it’s enough for our purposes, I guess). Also, we have to configure our firewall to allow the HTTP/HTTPS traffic, so we mark that buttons. Finally, click on “Create” button and wait for minute or three.
It is important to note that depending on the configuration chosen in your case, the price will vary. It is located on the left, on the VM instance configuration page. This is my case:
Our VM instance:
Then, we have to make our IP address’s type static and assign it to our server (Left sidebar -> VPC network -> External IP addresses).
In next step we attach our domain name to our server (it is still nothing about web server, pure Ubuntu). Navigate to Cloud DNS (Left sidebar -> Network services -> Cloud DNS) and create a zone.
In addition to existing two records, we add two more: A-type, leave empty DNS Name and put our IP address in IPv4 Address field and CNAME-type, add “www” to DNS Name field and your domain (ex.: domain.com) to Canonical name field.
Go to the next step – installing Apache Web Server, MySQL Database Server and PHP. We connect to our server via SSH.
Then, magic happens by typing these commands and pressing enter:
apt-get update // Updating our server apt-get upgrade // Upgrading our server apt-get install apache2 // Install the Apache Web Server systemctl start apache2 // Start Apache Web Server systemctl enable apache2 // Enable Apache Web Server systemctl status apache2 // Check the status of your Apache Web Server and make sure it works
Now, if you type your domain name in URL line of your browser and you done everything correctly, you should see:
Ups. Looks like I found the welcome page image for Debian OS. It is not important – the difference will be only in logo – you will see the Ubuntu logo.
apt-get install mysql-server // Installing MySQL Database Server
During the installation, you have to enter a strong password. Also, for better security you can run mysql_secure_installation script. After answering all the questions type:
systemctl start mysql // Start MySQL Web Server systemctl enable mysql // Enable it to automatically start upon boot
apt-get install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
To test the correct work of PHP:
nano /var/www/html/info.php // Create info.php file, which will be available at mydomain.com/info.php # // Type this code in newly created file; press CTRL+X and then Y to save changes
If it’s ok, you should see something like that:
We pass to the finish line – installing WordPress CMS.
cd /var/www/html // Navigate to directory of our website wget -c http://wordpress.org/latest.tar.gz // Download the latest WordPress installation from the official site tar -xzvf latest.tar.gz // Extract the file chown -R www-data:www-data /var/www/html/wordpress // Give ownership of the WordPress files to Apache Web Server mysql -u root -p // Login to MySQL Database Server CREATE DATABASE db_name_here; GRANT ALL PRIVILEGES ON db_name_here.* TO 'user_name_here'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD_HERE'; FLUSH PRIVILEGES; exit; // Create a new database for WordPress
Well, after the database created, we need to tell our wp-config.php file about it:
mv wp-config-sample.php wp-config.php // Rename the sample configuration file nano wp-config.php // Open file in text editor // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'db_name_here'); /** MySQL database username */ define('DB_USER', 'user_name_here'); /** MySQL database password */ define('DB_PASSWORD', 'STRONG_PASSWORD_HERE'); /** MySQL hostname */ define('DB_HOST', 'localhost'); /** Database Charset to use in creating database tables. */ define('DB_CHARSET', 'utf8'); /** The Database Collate type. Don't change this if in doubt. */ define('DB_COLLATE', ''); // Replace needed information respectively systemctl restart apache2 // Restart Apache Web Server systemctl restart mysql // Restart MySQL Database Server
Done! Finally, now we have to configure Apache Virtual Host.
nano /etc/apache2/sites-available/mydomain.com.conf // Create the virtual host configuration file <VirtualHost *:80> ServerAdmin admin@mydomain.com ServerName mydomain.com ServerAlias www.mydomain.com DocumentRoot /var/www/html/wordpress ErrorLog ${APACHE_LOG_DIR}/mydomain.com_error.log CustomLog ${APACHE_LOG_DIR}/mydomain.com_access.log combined </VirtualHost> // Of course, replace domain.com with your a2ensite mydomain.com.conf // Enable the virtual host's configuration
That’s it.