By Levi Clancy for לוי on
This is to set up a LAMP server on Google Cloud, applicable to any Linux Ubuntu 8 (jessie) operating system.
Enter your domain name to get the commands you will need to run.
Enter your domain name, e.g. mysite.com without any leading www or anything else
Linux Ubuntu operating system (version jessie)
And: Configure common options, like redirecting from www.mysite.com to mysite.com
Also: SSL support
Plus: Some helpful modifications for PHP
First set up the Google Cloud project. You will be required to set up a billing account for the project. New users may receive free credit to begin exploring.
By default, there is already a VPC network. Update it to 'global' dynamic routing mode. You will see the notification icon in the upper corner spinning while this saves.
When it finishes, then open Google Cloud shell and enter these commands,
<i>in google cloud shell:</i> gcloud init
Choose  then choose the project you are working on — usually  — then [n] to move along quickly. You can run 'clear' as a command to clean out the window contents, which can prevent distraction.
Now, go to Compute Engine and create an instance.
Change your boot disk to 'Debian GNU/Linux 8 (jessie)' and configure the system's memory and disk space to your needs and budget. Check 'Allow HTTP traffic' and 'Allow HTTPS traffic' for your instance to be accessible as a website.
Open the 'Management, Disks, Networking...' options and choose 'Networking.' Choose your network you just created, and make sure to reserve an external static IP address. Otherwise, the IP address will always change and you cannot point a web domain to it.
Now, enter the following in the google cloud shell at the bottom of the window,
in google cloud shell:
gcloud compute config-ssh
If prompted then choose [Y], then press 'enter' twice to skip setting a passphrase for the key pair.
Set up the system
In the list of instances, press 'SSH' to connect to your instance. The command line will look like this,
Now enter these commands,
<i>in command line:</i> sudo -s apt-get update apt-get install apache2 apt-get install mysql-server
You may be asked along the way to type 'Y' to confirm the installations. If prompted for a mySQL password then leave it empty and hit 'return' because we will set it up in the next step.
<i>in command line:</i> sudo mysql_secure_installation
You will be asked to set up a mySQL password. The default is no root password, which is very insecure. Choose [Y] for all the subsequent options.
in command line:
apt-get install php5 libapache2-mod-php5
apt-get install php5-mysql
apt-get install php5-gd
apt-get install zip
apt-get install unzip
service apache2 restart
I suggest allowing short PHP tags as a helpful way to make coding a little easier.
in command line:
Use CTRL+W and type 'short_open_tag' press enter. Then press CTRL+W and enter again. Change "Off" to "On". Then CTRL+O and enter and CTRL+X to save it and close it. Then restart Apache,
<i>in command line:</i> service apache2 restart
Access your server
At this point you can access your server on the world wide web. The external IP listed by the instance will be the address. It hosts files from the /var/www/html directory by default.
Make the directory where you will store your website files,
mkdir -p /var/www/mysite.com chown -R $USER:$USER /var/www/mysite.com chmod -R 755 /var/www/mysite.com
Create an index.php file,
Populate the file with a simple PHP script,
in the index.php file:
Now we will set up the Apache configuration file so your site can be hosted,
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.com.conf
This step copied the default configuration file and made a configuration file especially for you. Next we will edit it,
You'll want to set up the parameters like this. With the conf file open for editing, swap out any of the placeholders already there and make sure these are in place,
<i>in the conf file:</i> ServerName mysite.com ServerAlias www.mysite.com DocumentRoot /var/www/mysite.com
Note how the document root is the directory with the index.php file that you set up earlier? Now activate the conf file,
a2ensite mysite.com.conf service apache2 reload
When you finish setting up the conf files for all domains names you want, then it is time to add SSL,
mkdir -p /etc/apt/sources.list.d nano /etc/apt/sources.list.d/sources.list
Add this line to the sources.list file,
deb http://ftp.debian.org/debian jessie-backports main
Then save and go forward,
apt-get -t stretch-backports install "package" apt-get install python-certbot-apache -t jessie-backports certbot --authenticator webroot --installer apache
Sometimes something with Apache or somewhere else gets screwy. Definitely do not be afraid to reinstall,
sudo -s apt-get autoremove --purge apache2 apt-get autoremove --purge letsencrypt apt-get autoremove --purge certbot apt-get autoremove --purge python-certbot-apache apt-get install python-certbot-apache -t jessie-backports
Then you can install from there as normal.