Featured Articles
1. Introduction
Setting up and managing our own servers can take a considerable amount of time especially if we are not a day to day linux user. That is why we see things like serverless and containers catching on. There’s another option out there though too and it’s called unikernels.
What are unikernels though? Unikernels are simple single application operating systems. Instead of deploying our software on top of linux unikernels create an operating system out of our application and run only that app – nothing else. There’s no concept of usernames/passwords or sshin’g into the application as it is only running one application. Traditionally unikernels have been hard to work with as they used to require expert level of systems knowledge. Now there are newer tools like OPS that fix that.
2. Setup
In the next few minutes we are going to build, run, then deploy a php unikernel. First things first let’s download OPS from https://ops.city:
- curl https://ops.city/get.sh -sSfL | sh
We can also download and build it from github. can always go to https://github.com/nanovms/ops and build it from source – it’s written in Go.
3. Build and Run our First PHP Unikernel
Now that we have that let’s create a temporary working directory:
- mkdir p && cd p
For this simple example we’ll just use the built-in php webserver just to keep things simple. Put this into a config.json file:
- {
- "Args":["-S", "0.0.0.0:3030"],
- "Files": ["index.php"]
- }
What this does is tell the built in php webserver to listen on port 3030 and place the index.php file onto the otherwise barren filesystem. We’ll put this into a index.php:
- <?php
- echo 'hello from php!';
- ?>
Now let’s run it via:
- ops load php_7.2.13 -c config.json -p 3030
Here we tell OPS that we wish to use PHP7. When we are running this it will first download a php package then it looks at the config file and finally opens up a local port on 3030.
We should see this:
- [php -S 0.0.0.0:3030]
- booting /Users/eyberg/.ops/images/php.img ...
- assigned: 10.0.2.15
Assuming that boots we should now be able to hit it with curl:
- ➜ ~ curl -XGET http://127.0.0.1:3030/
- hello from php!%
- ➜ ~ curl -XGET http://127.0.0.1:3030/
- hello from php!%
4. Deploy to Google Cloud
Great! We just ran our first php unikernel! Now let’s deploy it. Assume have a google cloud account we’ll need a project id, a service worker key, and a cloud storage bucket to place our built images in. We definitely don’t have to use google but we are using it for this example.
We are going to slightly modify our config.json file and put this inside:
- {
- "Args":["-S", "0.0.0.0:80"],
- "Files": ["index.php"],
- "CloudConfig" :{
- "ProjectID" :"my-project-id",
- "BucketName":"my-bucket"
- },
- "RunConfig" : {"Memory": "2G"}
- }
What this does is tell OPS to place our built image in the bucket ‘my-bucket’ and use ‘my-project-id’. We also changed the port to 80 which is the default HTTP port.
If we got a service worker key we can put that somewhere to source like so:
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud.json
Then let’s build the image. What this does is create a virtual machine on Google Cloud that contains only our application with the php interpreter. It’s important to note that there is no underlying linux system here. When the virtual machine boots it boots straight into our application just like it did locally. This make it run much faster and safer than linux.
- ➜ p ops image create -c config.json -p php_7.2.13
- [php -S 0.0.0.0:80]
- bucket found: nanos-deploy
- Image creation started. Monitoring operation operation-1556904873950-587ff29f5fcc5-76e6bf08-ff926925.
- ..............
- Operation operation-1556904873950-587ff29f5fcc5-76e6bf08-ff926925 completed successfullly.
- Image creation succeeded nanos-php-image.
- gcp image 'nanos-php-image' created...
We should see something like this when it’s done building:
- ➜ p ops image list
- +--------------------+--------+-------------------------------+
- | NAME | STATUS | CREATED |
- +--------------------+--------+-------------------------------+
- | nanos-main-image | READY | 2019-03-21T15:06:17.567-07:00 |
- +--------------------+--------+-------------------------------+
- | nanos-node-image | READY | 2019-04-16T23:16:03.145-07:00 |
- +--------------------+--------+-------------------------------+
- | nanos-php-image | READY | 2019-05-03T10:34:34.966-07:00 |
- +--------------------+--------+-------------------------------+
Now let’s create an instance. Keep in mind an instance is the server. The image is the actual disk image of the server.
- ➜ p ops instance create -p prod-1033 -z us-west2-a -i nanos-php-image
- Instance creation started using image projects/prod-1033/global/images/nanos-php-image. Monitoring operation operation-1556905041207-587ff33ee1f25-fc8382ab-ec299733.
- .....
- Operation operation-1556905041207-587ff33ee1f25-fc8382ab-ec299733 completed successfullly.
- Instance creation succeeded nanos-php-image-1556905040.
If we look at the instance list we can see it running:
- ➜ p ops instance list -z us-west2-a -p prod-1033
- +----------------------------+---------+-------------------------------+-------------+--------------+
- | NAME | STATUS | CREATED | PRIVATE IPS | PUBLIC IPS |
- +----------------------------+---------+-------------------------------+-------------+--------------+
- | nanos-php-image-1556905040 | RUNNING | 2019-05-03T10:37:22.465-07:00 | 10.240.0.48 | 35.236.11.13 |
- +----------------------------+---------+-------------------------------+-------------+--------------+
Now if we hit that ip up with curl we can see our php unikernel running in Google Cloud!
- ➜ ~ curl -XGET http://35.236.11.13
- hello from php!%
- ➜ ~ curl -XGET http://35.236.11.13
- hello from php!%
We can also see the logs from the unikernel:
- ➜ p ops instance logs nanos-php-image-1556905040 -p prod-1033 -z us-west2-a
- SeaBIOS (version 1.8.2-20190322_093631-google)
- Total RAM Size = 0x0000000080000000 = 2048 MiB
- CPUs found: 1 Max CPUs supported: 1
- found virtio-scsi at 0:3
- virtio-scsi vendor='Google' product='PersistentDisk' rev='1' type=0 removable=0
- virtio-scsi blksize=512 sectors=2097152 = 1024 MiB
- drive 0x000f2a30: PCHS=0/0/0 translation=lba LCHS=1024/32/63 s=2097152
- Booting from Hard Disk 0...
- assigned: 10.240.0.48
- [Fri May 3 17:39:36 2019] 1.2.3.4:57595 [200]: /
- [Fri May 3 17:39:37 2019] 1.2.3.4:57596 [200]: /
- [Fri May 3 17:39:59 2019] 92.112.48.216:35338 [200]: /
5. Conclusion
Congratulations! We’ve built, ran and deployed our first php unikernel on google cloud – now we can go show our friends that we don’t need servers to deploy our applications anymore! Unikernels give us the convenience of containers and serverless with the protection and speed of traditional virtual machines.
Article source: https://article-realm.com/article/Computers/Software/2508-Running-PHP-Unikernels-on-Google-Cloud.html
Comments
Reviews
Most Recent Articles
- Jul 23, 2026 How to Build a Powerful Logistics App Development Project in 10 Simple Steps by iQlance Solutions
- Jul 17, 2026 Polymarket Clone Script for Launching Advanced Prediction Market Software by gurubalan v
- Jul 14, 2026 Dating App Development for Creating Feature-Rich Online Matchmaking Platforms by gurubalan v
- Jul 11, 2026 Can the Best Software Development Company for Wheat ERP Reduce Daily Operational Chaos? by Arobit Tech
- Jul 9, 2026 What Businesses Should Know Before Hiring Ecommerce Developers? by Steve Jonas
Most Viewed Articles
- 3899 hits What Is The Process Of Updating Garmin GPS Maps Free Of Cost? by Henry Ford
- 3208 hits Mit lokaler SEO Suchmaschinenoptimierung auf Platz eins! by BRIGHT DIGITAL
- 2358 hits Google Lighthouse- Auditing & Enhancing Shopify Theme Performance by Anuj Sharma
- 2307 hits How to Find Best Deals on www.amazon.com/code? by Patrika Jones
- 2177 hits How to change your Outlook password by larry felice
Popular Articles
In today’s competitive world, one must be knowledgeable about the latest online business that works effectively through seo services....
80979 Views
Walmart is being sued by a customer alleging racial discrimination. The customer who has filed a lawsuit against the retailer claims that it...
49411 Views
Are you caught in between seo companies introduced by a friend, researched by you, or advertised by a particular site? If that is...
37026 Views
Facebook, the best and most used social app in the world, has all the social features you need. However, one feature is missing. You cannot chat...
23342 Views
If you have an idea for a new product, you can start by performing a patent search. This will help you decide whether your idea could become the...
14562 Views
Moving becomes easy when you have the right moving accessories. These moving accessories help secure and protect your item by ensuring that no harm...
12516 Views
A lot of us look forward to the result of moving and not the process itself. It is pretty typical behavior, though. As modern people, many things...
11717 Views
Building a custom home is an exciting adventure. It’s your chance to bring your vision to life and create an area that sincerely displays...
11519 Views
Moving from one state, city, or even to a whole different county, is something that is either dictated by choice or circumstance. This is because,...
11331 Views
Statistics
| Members | |
|---|---|
| Members: | 16750 |
| Publishing | |
|---|---|
| Articles: | 78,447 |
| Categories: | 202 |
| Online | |
|---|---|
| Active Users: | 2210 |
| Members: | 1 |
| Guests: | 2209 |
| Bots: | 5101 |
| Visits last 24h (live): | 8343 |
| Visits last 24h (bots): | 38287 |