A corrected tutorial
The Google cloud tutorial at https://cloud.google.com/community/tutorials/setting-up-lamp is quite out of date and does not work if followed to the letter. In the revised brief tutorial that follows, I attempt to correct some of the more obvious pitfalls and also clarify what is actually happening.
The exercise that follows uses a micro VM (Virtual machine) instance which is currenly within the free tier usage limit of Google Cloud and so is ideal for teaching and demonstration purposes. This VM has 1 shared cpu, 0.6GB of memory and by default will have 10GB of storage, quite enough for most small tasks.
First, you must create and sign in to your Google Cloud Platform account. I will not go into any detail of this here. From the home menu, select “VM instances” and then “Create”. Give your VM a memorable name – we will use “tester-vm” for the purpose of this tutorial. By default, the Debian GNU/Linux image will be installed and that is what we need. The original Google tutorial suggests Debian 7 as an option but it is no longer available. The only other settings that need attention are to allow the firewall to pass HTTP (and if need be HTTPS) traffic by checking the respective boxes. Click on the “Create” button and withing a few seconds the VM instance “tester-vm” should appear.
Make a note of the external IP which will be needed during testing.
To make sure that everything is workong correctly, connect to the VM by using your browser by clicking on the SSH dropdown to the right of the VM listing and selecting “Open in browser window”. It may take some time to connect but be patient. A separate browser window should open giving what is effectively command line access to the VM. You should be able to navigate and explore the VM using Bash commands such as “cd” and ls. Now to install the Apache server and php.
Install Apache and PHP on your VM Instance
First update the repositories:
sudo apt-get update
Then install Apache and php:
sudo apt-get install apache2 php libapache2-mod-php
So far, so good, the Google instructions work. PHP7 will be installed by default, php5 does not seem to be available as an option in Google cloud any more. Check that all is well by opening a page in your browser:
you should see the default Debian/Apache2 web page. You should also check that php is running properly by creating a file in the apache2 document root:
sudo sh -c 'echo "<?php phpinfo() ?>" > /var/www/html/phpinfo.php'
Check that it works in the browser:
You should see the php information page displayed. It is not a good idea to leave this page as it is, I renamed the page to something-else-memorable.php (choose you own name).
The next step is to install mysql:
sudo apt-get install mysql-server php-mysql php-pear
Note the missing “5” when compared with the Google tutorial – we have php7 installed. We must now configure mysql to be secure.
You should set the root password, remove anonymous access, remove the test database (unless you have a reason to keep it) and restrict root access to localhost only. From here on is where the installation process diverges more from that in the Google tutorial. You should now test mySQL as follows:
sudo mysql -u root -p
If you attempt to connect without the “sudo”, you will get an error. You should get the Mariadb welcome “Welcome to the MariaDB monitor…..etc”. to get back to the command line, just type the “exit” or “\q” command. Assuming all is well, we are now ready for phpMyAdmin.
sudo apt-get install phpmyadmin
note that it is all lower case, if you use “phpMyAdmin” you will get the message that the install cannot be found. During the installation, select “Apache2” as the server and say yes to using “dbconfig-common” for the configuration. You should also set a password for phpMyAdmin to access mySQL when asked.
At this point, the Google tutorial suggest that you browse to the phpMyAdmin page to check for success. This will fail (for now):
The reason is that the install has not been completed and Apache2 does not “know” that phpMyAdmin exists. To get it running, we need to add the phpMyAdmin configuration to the conf-enabled list in the Apache2 config file. This is perfomed by creating a symbolic link to the phpmyadmin.conf file in the apache2 conf-enabled folder and then enabling the link by using the built in apache2 “a2enconf” command as follows:
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf sudo a2enconf phpmyadmin.conf sudo service apache2 restart
Note that after the a2enconf command, it suggests using systemctl to restart apache2, this does not work, you must use the service restart command shown above. If you now check for a sucessful install, you should see the phpmyadmin login page:
You will, however, not be able to log in as root or anyone else as securing the mySQL has stopped all external attempts. In order to overcome this, we need to create a user with full privileges as follows:
sudo mysql -u root -p [enter the password set up earlier for mySQL root] CREATE USER 'your-chosen-username'@'localhost' IDENTIFIED BY 'your-chosen-password'; GRANT ALL PRIVILEGES ON * . * TO 'your-chosen-username'@'localhost'; FLUSH PRIVILEGES; \q
Now navigate agin to phpMyAdmin in your browser and log in as “your-chosen-usename” using “your-chosen-password”. You should now see the phpMyAdmin page listing available databases. check things out by creating a database and then deleting (dropping) it. Note that the last step could have been accomplished by using: “sudo dpkg-reconfigure phpmyadmin” but this method is self-explanatory and it works!
That is all for now and good luck with your project.