 My name is Ken, so hello to everyone. Because I think it's a new faces, so I just introduced a bit of what I do with the developers community here. I'm a co-organiser for Koopi.js, which is this icon here, which is happening this Saturday at 11am. So if you are free for brunch, join us. I also co-organise Mydol Dinosaur, which basically is a JavaScript studying group. It's not related to PHP, but this is what I do for the... Sorry? No, it's everywhere. Mydol Dinosaur, it happens quite a few times at SPH because I work at SPH. That's the reason why. But other than that, sometimes we go to different places. There was one time we did it at Block 71. We have one of our regular members who runs a startup over there, so that's why we just went over there. But nowadays, there's the junior def, which keeps everyone busy every two weeks. So today what I'm going to share about is my experience creating a simple PHP application on Google App Engine. Okay, the motivation for this is because... So just now, as I was sharing, I started PHP programming since 2011. So the usual things I go through is PHP, MAM, because I will use a Mac. Then last year, when I was at... No, this year, this year. This year, there was the first year birthday party bash for the Google Cloud Datacenter. So I went over there and then I saw a lot of new products. Because all this while, we know there's AWS. So most of our stuff is as in we have played on AWS before. But Google Cloud, not so much. So I decided, okay, maybe I should try doing some simple stuff on Google Cloud and see if it's any different. Because AWS is just an EC2, which means it's just like a regular LAM stack kind of thing. Google Cloud, I'm not sure. So that's why I decided to give it a try. Okay lah, so give it a try usually is you start google.com, get started, PHP, Google Cloud. And then, so I saw this page. Okay, still okay, like getting started. Then you'll see here how to run Hello World. It looks very simple. Then start to scroll down. So as I start to scroll down, I see the index of PHP. I started to get a bit worried because, hey, what's Silax? Actually, I never play with Silax before. So I was like, hmm, okay. Then this looks very okay, okay. I think it's getting too complicated. I just need an echo Hello World and the regular things that I can do with my LAM stack. So, and then I search some more. Then I start to see symphony coming out. Then I'm okay. I think it's time I need to do on my own. Because I think I researched for about 1 hour trying to find a simple one but I couldn't find. So I decided to do it on my own. Okay, so this is the part where I'm mind blown. Too many things, symphony and Silax. Okay, so at the end of the day, this is my result. Okay, the code, hopefully you all can see. So it's a very simple one with MySQL i, trying to connect, echo and then a form. And this form basically takes in a file and then uploads to the cloud storage which is like the S3 for AWS and then return something like. So basically able to connect to a database and able to receive file upload. Ya, that's the basic My Hello World app. So how do I get to that was actually a journey. It's not that some parts were simple. The echoing part was simple but like uploading of files and connecting to MySQL was a difficult one. So these are three things, the App Engine, the Cloud SQL and Cloud Storage. So I think it's quite, the actual PHP runs on the App Engine. This is your regular MySQL stuff and this is your storage space. Okay, so I'll do the demo since it's a small crowd here so I can do the demo. Okay, so very simply okay, since we are all adults here so we all have credit card. I assume everyone has credit card so you need a credit card to start with Google Cloud Platform. I think that's quite standard already. So to begin with, after you are in this page here you have already seen. So just now in afternoon I already tried. So I have a few test projects already. So I'm just going to walk through how to create one, the simple one. So over here, actually here, over here select a project. You just click on new project. Okay, then I'm going to give it some name PHPGE2 okay, then create. Okay, so once you create you'll take a while, you'll see this twirly thing okay, it probably takes sometimes 30 seconds to a minute so just be patient. The one thing I learn or the one thing I come to learn about working with this interface is that you need to be patient. Not everything comes out immediately, you know. So now you see try PHPGE2 okay, let's go in. So you will be greeted with this interface. Because for me I already enable billing for all my projects. So you will see that everything is here but usually if you really start out real fresh you have to go to the billing site and then to actually enable billing for the application. So in this case you can go to overview. So the thing is once you have credit card they won't deduct money you have 300 credits to run for what year. So that's where you can play with whatever you want. Okay, then you need to add in your projects here. So like for this is really added here GE2. Okay, so the thing is you have your project ready. So remember the slide I had 3 components. The App Engine, the Storage and the SQL. Now you just click on this place scroll down a bit, App Engine okay. And then yeah, welcome to App Engine. Very simple. One button, create application. Choose where you want to go usually I choose Asia because that's where I am. And then PHP. Okay, this is the part. So the tutorial that I went that I chanced upon is all flexible. So but they're standard and flexible for you to choose from. There's also online documentation to tell you when you should use standard when you should use flexible. Quite detail actually. They even tell you that so the thing is about what are the language and version supported by the flexible and standard. So you see a standard actually supports only 5.5 which is outdated already. And 7.2 is in beta. Whereas for the flexible one you have more recent versions of PHP it's not stated here but you get more recent versions of PHP. So this is one thing to consider as well as other things like how fast you can spin up the instance so this is for you to play with it and to figure out okay so I choose flexible in this case just next. So successfully created you need to then download the cloud SDK. This is your command line tool for you to actually upload your code from your localhost to the cloud. Okay so is it done? I'll do this later. Okay done. Actually this fast. Okay so my app engine is now ready so if you go to the dashboard here it will fail to load. Oh no. Shenanigans. Aha. Okay. So done. You have your app engine ready for this project. Next thing. So once you the thing about GCP once you create an app engine it will also create a cloud storage for you automatically so you just need to go in and check. Ya. Then there you go. You have your try PHP GA2 this is your cloud storage. Then here you can tweak the settings of your cloud storage just like S3. If you want to make it public you go here and then you go to permissions and then wait for it to load. Okay then over here add members in ALL then you see all users and then to make it to make your files viewable to the public you just go storage object viewer and then after that you just add. Okay. And then just go to here then you see this cloud storage public accessible. So you have 2 things nailed down already you have your app engine you have your cloud storage. The final thing which in my whole learning journey which was the most complicated is the SQL. Any questions so far okay I go for the SQL So over here okay same thing create instance so when I was playing with this I think one month back the interface didn't look like that now it looks like that which I think is nicer you can choose between MySQL and Postgres I'm familiar with MySQL so just like that then you will tell you okay last time one month ago it didn't have such a new such a fancy full interface but now at least this one you will tell you which one you should be using and what you will not have and what you will have so I mean since this is a learning thingy so you just need to choose development because you don't really need HA high availability and you probably don't need to increase storage but if you are doing some more some advanced learning stuff then maybe you will need it so okay configure MySQL okay then as usual test SQL2 password just root don't use root ever but this for demonstration so it's okay location should be fine Asia south east any okay so here you also notice for this SQL instance that you have that you are going to create right how many CPUs how much memory and storage you have for just for your knowledge you know if you are more of a back end DevOps guy this this information maybe something that you will need as well okay so I'll just create okay so creating this SQL it's we'll take 1-2 minit I timed it this afternoon just because I was worried how much time you'll take to run this whole demo so I just okay so while this is going on I'll show you my code first so now you can see the code in higher definition this is most of it comes from the hello world code that I got from the Google cloud documentation you can't run away with vendor or the load because you need some things from Google which is in your composer Jason you need your Google slash cloud tools and you need your cloud and cloud storage in order for the file upload to work so composer.json this is the bare minimum that you need for this project at the moment it's also needed this is to this is so that when you when you deploy this project into Google cloud it knows what runtime you need to have what's the environment which you have configured but this one is for the deployment to know them and then your where's your document route for me I put dot but if depending on application if you have a public folder then you change this to public but in this case because it's a super simple no framework PHP application so it's just dot okay storage bucket so this storage bucket is where you see it just now in your still so patience the thing about Google cloud is patience the clock storage is just now where you are here if you remember this is the name this is the string that you put over here okay user password not going to show you because this you decide user and password is the one that you will is once later you will see I'll show you where to put in this MySQL user password then also MySQL DSN is a compulsory item as well basically telling okay MySQL DB name unique soket tinggi and you also need this Cloud SQL Instance tinggi here so all these are compulsory these are the bare minimum compulsory fields that you need to have in your app as well so after you create that strong range sorry means auto-generator I no it's not auto-generated like this is like I have to create from write it out on my own of course if you download from Google Cloud the documentation they have a sample hello world app they also have this so you can but they also have other things which I taken out after that so this is my index.php so you have your vendor autoload like my env.php which basically stores MySQL username password then this storage client you need to use it in order to make cloud to allow file uploading okay this function upload a file is from the documentation so it's a I just copy and paste I didn't even change because I just need to make sure it works first and then all this file thing is the other one and that's that's about it for my index.php which is my php application okay let's see if the SQL is done if it's not done never mind okay it's still it's still so so the thing is patience are patience but never mind as all cooking shows is already prepared set of food ready to show your okay so that was where I was so this is my actually finished food okay so you have you see the green tick sign when your SQL is ready okay click into it okay because this is just your SQL instance you still need to create stuff over there which is your database okay loading database from my SQL so I have a testdb here I think hope you all can see over here okay because you just created SQL instance but you still need to put in your database and then your users which is here okay then you give it a password you know like create user account and give it a password kind of thing then this is the one thing that trip me up also which I'll show you later basically after all this right you will still need to do this thing called Google Cloud SQL Admin thing let me see unknown it's under API and services because what you have created you have created the tools that you have but you still need to enable an API which is called the cloud SQL admin API and cloud SQL admin because this trip me up for a bit because what I did was after I created all this then I started to deploy that PHP application then I basically I got to this page but it let me try again it got me to this page but it keeps giving me error with connecting to a database then I was like why why is it not connecting then after Googling for a long time then I realised that oh you need to actually enable enable this admin API so that's the one thing that took up about at least 2 hours of my time ya so what does it do it's so that you enable the API so that your application can actually talk to cloud SQL it's like a lot of Google applications the API when you have an application or have an IDE or whatever or also tell it what APIs I have access to in the whole cloud ya so this one this one is which they didn't mention in the tutorial la so that's why it wasn't very clear to me how I also found out is also by because one thing is when you deploy the app then you can actually look at the log files in this part gcloud app logs tail dash s that was actually where I also it actually did tell me la okay your admin API is not enabled so okay fine ya so after enable this right okay so done actually didap means yes then you can Google Cloud app deploy so this is what I did okay so okay so you see the into your project folder initially you need to run this thing called gcloud init la Google Cloud init basically initialize you ask you what is your project because once you Google Cloud init you ask you for your Gmail first then with your Gmail they will be able to detect what projects you have on hand and then you link it basically to establish the profile then after that init finish right then you just gcloud app deploy okay and I will show you okay then okay then I will show you like where is it going to deploy to you know is this correct okay yes then you start to deploy and deploy and so based on this afternoon's experience they talk about let me see I timed it also I started at 4.25 completes the deployment at 4.36 which 11 minutes later so please have patience I think it's also because I'm using the flexible the app engine the flexible environment if I haven't tried the standard one based on what I read in that documentation just now perhaps the standard one may be faster so I will give it a try anyway still the same still the same so but probably can give it a try but if you manage to get it faster than I do then please let us know I would just my assumption ya la the gcloud so it's you create like top gcloud folder in their project because I assume the settings are specific for each project I don't see any gcloud init files in my project folder don't have it's more like or it could be in my slash user that means in my slash user folder it could be there ya because so now now it's anything la so as in because it does remember so whenever I type gcloud init you'll say your your previous config is like that are you going to switch to another one so it probably is in my slash user folder okay so here is the part la it will take it really pre-empt you la it will take 7 minutes la but it's ya la about 11 minutes like that so if you all have if you all interested to try make it fast as in if you all get faster with us do let us know okay so at the end of it so if let's say everything deploy nicely okay at the end of the day this is what you get la you know this your project name followed by dot appspot.com then slash index of PHP if I remove index of PHP it will also work yes okay so choose your file probably text to send ya so it works and then how do you verify that it's been uploaded go to your bucket refresh and then you will see your text to.txt over here ya so that's the simplest application ever la receiving input I mean text entry not the issue it's more like file upload that's usually one thing how you handle it and then communicating with SQL for the AWS RDS the SQL administrator account they restrict the options available to you so they don't allow you to set all the SQL options how about the Google Cloud SQL options la I think I think also have so that means like what user can do what la yes you know that sometimes my SQL default they don't allow to set a good line or I think it's a fine point set set point set of like some default this is some SQL mode SQL mode la user it's pretty much changing the concrete file ya quite the concrete file so the AWS actually restricts block some la even from your SQL administrator ok ok I'm not sure man like underwear right side oh ok it's flex flex but it's not the my SQL not the mysql.in is it ya so it's like hmm ya la lock files this lock files or the mysql.in hmm where lock files query logs slow query logs and stuff is there is there is there a SQL query emisi ya da da da da da oh so a hmm hmm so you have my SQL you have this ya whoa ok ok this is basically Stack driver la that means everything SQL Even deployment you also can see stuff Okay, so going back to my slide So actually I've already illustrated The challenges faced Primarily in this simple Hello world everywhere it was The cloud SQL it was quite an issue First thing because the documentation was using PDO as database connector Yes, I'm trying to use MySQL And even if I use MySQL There was issue like In this Google group forum Let's go there There's a lot of people saying that they Couldn't connect to MySQL Like All this whole bunch of PHP, MNG Cannot connect to cloud SQL So many since 2016 until here You know Things like that Then because the thing is Let me show you They're using PDO And then in the Yeah, this is where you get Just now I'm showing you the MySQL DSN And the port number they put here is 3306 Which is the usual one Even in our localhost we use 3306 But But I've come to realise that For In the Google App Engine For this one The DB port I should put now Even if I put 3306 It won't work Is it because of the unit socket Normally you don't have the unit socket In the database connection stream That Hose equals something Then de-renege is something But the database connection stream You have the word unit socket Where's the part of the database connection stream? They haven't found this one You have your unique socket here Which I'm not sure Even over here You also have the Unique socket The socket You're also in the app demo So I thought this would be The compulsory fuel I have no idea So I really I really tried 3306 I tried empty That means in my As long as you read the ESN You should be fine You're in your index file Which is Here No, I'm not Oh, because Because the MySQL i Doesn't take in the ESN If you format it in one string Then you just pass into Which I would really like to be using I think in PDO's case That connection string ESN is like Connection string As long as you have connection string You know how to pass it internally And get pieces So if you're using the SQL i It probably requires you to pass So in some applications That we get before We actually have a parser That will look at a few connection strings Because connection string is generated By some other library Or some other service That connects to a service Environment variable And so we actually have To write a parser It will pass that environment variable Because it comes as a long string Into these component parts And break it down into these things So you could have done that What you could have done is read that component That ESN environment variable And broke it down To pass it into these component parts Is one possibility Or you could In your app demo Just broken it down into the small chunks That you have That you need Over here you can just broken it down Without the MySQL DS And just break it down into MySQL Of a server Just fine Just curious Pot Has to be a number Yeah I thought it can be there So where I found This DB pot now This thing Is in a Two year old Two year old YouTube video I was seriously Seriously MySQL higher Yeah I was half doubting Ready Should I trust this two year old video So I Go to The eighth minute So This is from Nope It's from VT Games The engineers done here In our video Okay Where's the Okay, let me just increase the I think you set the pot Now you just default using The Just default using The socket So this is where I saw it Pot is now Host is now as well Then I was like, okay In what Yeah It needs to have something in the fifth argument Yeah But even then host now I'm like, okay Like I can't Okay I tried different permutations It I think that's your idea Initializer It needs to have You don't use the socket To set the host and pot You don't use the socket So that's where I was Because It might be Google setting Since you're I think it knows Yeah Hopefully with this discussion And with this tutorial But perhaps It It can help future developers Who are using MySQL The question I have is When you are deploying a new version That's the old version Is the site still up Or you are deploying it? Yes, the site should be still up Okay, so it's probably going to go really far Because there is Whenever I go into Actually when you are at the home page Right You see that every time I Deploy, there will be actually a version Of it Yeah I see Could it be slowness Due to the Faking now Split Split top prime Go bit more top Top Right That So you can do A-B test A-B test You can split traffic You can So you can see the first one is 100% you can actually If you want it, you can split it amount Or you can have multiple instances running And then split the traffic Okay, it's kind of cool You can do A-B testing here Although it will kill So This is for the same At So you have different versions So for this, we want the reasons Why it's so slow to deploy Because it needs to suppose Save the previous version Save him Sir, sir Because when they are doing the deployment They are creating a docker image Publishing the docker image Bringing up a server Publishing that docker image Putting that docker image Exploiting port So it's all cool So it's all cool Okay, let's see Because we're using flex That's running on another server If you go to GCE We'll see your server Let's see Bm Instances Nope So i guess Because Google Cloud Will be handling that CE for me And it's not my CE I'm using flex Can you directly Assessage or SFTP to the Accord Actually according to You could if you do some Assessage Assessage debugging Yes for flexible Assessage running container Ya So that's what After this I'll just go back and try With a standard environment Maybe the flexible environment As Actually It's built into container Whereas standard Maybe it has a few standard containers It just map the right volumes Okay, so this basically Is my learning experience Hope it help To give you some inspiration To try other things So ya la, please go and try Ya, thank you