This post shows steps for students and new users to install PHP on Google Cloud servers running Ubuntu Linux.
If you want to run a website online, you’ll need a web server. You’ll probably also need a PHP server-side programming language script installed on your server. PHP is the most popular open-source side-side script used today and runs on most websites online.
This is the fifth post in this series, which can be used as a beginner’s guide to learning how to create a website domain, set up a Google Cloud server with Ubuntu Linux, and install software and packages to build and run a website online.
In this series:
- How to create a website domain
- How to set up a Google Cloud server with Ubuntu Linux
- How to install Apache on a Google Cloud server (alternative to Nginx)
- How to install Nginx on a Google Cloud server (alternative to Apache)
Now that you’ve learned how to create a website domain and set up a Google Cloud server, this post shows you how to install PHP on a Google Cloud server with Ubuntu Linux.
A web server allows content to be published and served to clients and your audience browsing your website. A PHP server-side script will enable you to run a complex and dynamic website with advanced functionality.
A web server and PHP or other side-side processing scripts are needed to run a dynamic and successful website today.
In our first post, we mentioned that after you create a domain name, it can’t be used until forwarded or pointed to a server. The second post showed you how to point a domain to a server we created.
At this point, we’re ready to connect to our Google Cloud server and begin installing software and additional packages that will be used to run a website online.
How to connect to the Google Cloud server
Google Cloud server (Compute Engine) allows users to connect using SSH from the browser window to their virtual machine (VM) instance within the Google Cloud Console.
SSH from the browser supports the following:
- Web browsers
- The latest version of Google Chrome
- Firefox
- Microsoft Edge
- Microsoft Internet Explorer 11 and later
- Safari 8 and later. Note that Safari is not supported in private browser mode.
- Virtual machine configurations
- All Linux VM images are natively available in Google Cloud.
No additional software or browser extensions are needed. Simply login to Google Cloud Console and go to Menu ==> Compute Engine ==> VM instances.
In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

Alternatively, you can open an SSH connection to an instance by clicking its name and SSH from the instance details page.
An SSH terminal window with the Ubuntu Linux instance created in the series’s second post will open.
You should now be able to run commands in Ubuntu Linux created on the Google Cloud server.

How to install PHP on Ubuntu Linux on Google Cloud Server
Installing PHP on Ubuntu Linux is no different, whether on Google Cloud or a local VM instance.
PHP packages are available in Ubuntu default repositories. One can use the apt-get commands to download and install PHP on Ubuntu Linux.
A detailed post with help installing PHP on Ubuntu Linux is below. Click on it to learn more about installing and managing PHP on Ubuntu Linux.
How to install PHP on Ubuntu Linux
With PHP installed, your domain name should now be able to bring up a default web server PHP test page when anyone browses your domain name, followed by /phpfinfo.php.
First, create a test PHP file called phpnfo.php in the web server’s default home directory.
sudo nano /var/www/html/phpinfo.php
Then copy and paste the line into the file and save it.
<?php phpinfo( ); ?>
Save the file and exit.
Restart your web server (Nginx or Apache).
Next, go and type your domain name in your browser, and you should see an example page similar to the one below:
http://example.com/phpinfo.php
If you installed the Nginx web server with PHP-FPM, then you should see a page similar to the one below:

If you installed the Apache web server with PHP, you should get a page similar to the one below instead.

As you can see, your server hosted on Google Cloud is now resolving your domain name and serving web content with PHP.
We’ll continue to add other servers and software so you can run a functional website online.
Conclusion:
This post demonstrated how to install PHP on a Google Cloud server running Ubuntu Linux. Here are the key points to remember:
- Connecting to your Google Cloud server can be easily accomplished using SSH from the Google Cloud Console.
- Installing PHP on Ubuntu is straightforward with the use of apt-get commands.
- A test page can be created to verify that PHP functions correctly on your web server.
- Both Nginx and Apache web servers can successfully serve PHP content.
- This process lays the foundation for building and running dynamic websites on your Google Cloud server.
As you progress through this series, you will gain more skills and knowledge about effectively setting up and managing your web presence.
Leave a Reply Cancel reply