2 thoughts on “How to host WordPress with Google Cloud Free”
Leave a Comment
You must be logged in to post a comment.
Running a WordPress blog can be free with some free services, the easy way is using WordPress.com. But there are many limitation with the free plan, for example use your own domain or some theme you like.
The minimum for which you can get a dedicated server hosting is for at least $4 a month to use own domain, but still you can’t use your own themes!
So, you want to run a WordPress blog with own domain and themes but still free?
Yes, there is a choice with Goolge Cloud Platform (GCP) Compute Engine and I’m going to help you setup a WordPress blog on it!
Google provided Always Free Tier of its cloud services. The free resources are not much but is more than enough to run a startup blog free for a month, every month. There is also a $300 trial credit across all their cloud services for a year.
We’re going to use this free Virtual Private Server (VPS) to run our WordPress site using the nginx high performance web server.
You can refer to GCP Free Tier Docs for more region and zone and the latest free resources quota
sudo apt-get purge apache2
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo add-apt-repository ppa:ondrej/nginx
sudo apt install nginx mysql-server php7.4 php7.4-fpm php7.4-curl php7.4-gd php7.4-intl php7.4-mbstring php7.4-soap php7.4-xml php7.4-xmlrpc php7.4-zip php7.4-mysql php7.4-imagick php7.4-cli nano
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo swapon --show
sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Password typed is hidden and no cursor indicator move, just press enter after done
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
sudo mysql -u root
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
EXIT;
cd /var/www/
sudo curl -LO https://wordpress.org/latest.tar.gz
sudo tar -xzvf latest.tar.gz
sudo mv wordpress/ yourdomain.com/
curl -s https://api.wordpress.org/secret-key/1.1/salt/
cd /var/www/yourdomain.com/
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
sudo chown -R www-data:www-data .
cd /etc/nginx/sites-available
sudo nano default
listen 80 default_server; -> listen 80;
listen [::]:80 default_server; -> listen [::]:80;
cd /etc/nginx/sites-available
sudo nano yourdomain.com.conf
server {
listen 80;
listen [::]:80;
root /var/www/yourdomain.com;
index index.php index.html index.htm index.nginx-debian.html;
server_name yourdomain.com www.yourdomain.com;
client_max_body_size 256M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri /index.php?$args;
}
location /wp-admin/ {
index index.php;
try_files $uri $uri/ /index.php$args;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_connect_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_send_timeout 300s;
}
location ~* \.(txt|xml|js)$ {
expires 365d;
}
location ~* \.(css)$ {
expires 365d;
}
location ~* \.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|mp4|m4v|ogg|webm|aac|eot|ttf|otf|woff|svg)$ {
expires 365d;
}
location ~* \.(jpg|jpeg|png|gif|swf|webp)$ {
expires 365d;
}
}
#Change to root path
cd
sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/
cd /etc/nginx/sites-enabled
ls -l
total 4
lrwxrwxrwx 1 root root default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root CorrectDomain.com.conf -> /etc/nginx/sites-available/CorrectDomain.com.conf
lrwxrwxrwx 1 root root sites-enabled -> /etc/nginx/sites-available/WrongDomain.com.conf
#Remove the error symlink with name
sudo rm sites-enabled
sudo nano /etc/nginx/nginx.conf
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 256M;
sudo nano /etc/php/7.4/fpm/php.ini
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 600
max_input_time = 400
max_input_vars = 10000
memory_limit = 256M
ctrl+w to search keyword, remember to remove “;” in front max_input_vars
sudo nginx -t
#output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo service php7.4-fpm restart
sudo service nginx restart
That’s all for the 3 steps and you just got your WordPress blog running on GCP!
If you have any issues in any of the steps above, feel free to drop a comment!
You must be logged in to post a comment.
Pingback: How To Install / Upgrade To PHP 7.4 On Ubuntu 18.04 LTS - Jimmy Beh
Pingback: Optimizing PHP-FPM Performance For High Load - Jimmy Beh