Setting up LAMP and phpMyAdmin on Google Cloud




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:

http://[YOUR_EXTERNAL_IP_ADDRESS]

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:

http://[YOUR_EXTERNAL_IP_ADDRESS]/phpinfo.php

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.

MySQL configuration:

sudo mysql_secure_installation

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.

Install 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):

http://[YOUR_EXTERNAL_IP_ADDRESS]/phpmyadmin

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:

http://[YOUR_EXTERNAL_IP_ADDRESS]/phpmyadmin

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.



Posted in Google Cloud, LAMP, phpmyadmin, tutorial | Tagged , , , | Comments Off on Setting up LAMP and phpMyAdmin on Google Cloud

Headless Setup of the Raspberry Pi Zero W





The new Rapberry Pi Zero W released last month is a major step forward for so-called “headless” or standalone controllers. However, order to get a Zero W up and running is not quite as simple as it could be. This is because in order to activate the Wi-Fi connection, the simplest way is to use a keyboard, mouse and screen which potentially defeats the object of the Zero W!

This brief tutorial describes a completely headless setup that does not require the extra hardware and can be performed over the local Wi-Fi network.

The setup comprises 5 simple steps:

  1. Download the latest Raspian Image
  2. Flash the modified Raspian image to SDHC
  3. Modify the boot code (don’t worry – its not complicated!)
  4. Boot the Pi Zero W
  5. Connect to the Zero W using ssh over the local WiFi network

You will need a micro SDHC card with at least 8GByte capacity, we suggest a fast 16Gbyte card rated at Class 10 minimum.

Raspian Image Download

The instructions found in the MagPi magazine suggested downloading the full Raspian PIXEL image. This is not necessary as it assumes that you will use the graphical interface to perform setup. We suggest that for headless applications the latest Raspian JESSIE LITE zip image is sufficient, download it from HERE.

Expand the zip file into a separate folder, we suggest using 7zip but your favourite application should suffice.

Flash the image files to SDHC

The expanded image file should now be flashed into the micro-SDHC. for this we recommend Etcher which makes the job very easy and clear. Etcher can be downloaded HERE. Start Etcher and select the image file, in our case it was “2017-02-16-raspbian-jessie.img”. Select the SDHC card which Etcher should have identified for you – CAUTION: make sure that you select the correct card as it willbe completely over-written. Check all is correct then click “FLASH”. This process can take several minutes so go get a cup of tea. Etcher will flash and verify the file, reporting any errors encountered. Remove the SDHC card. Etcher should have unmounted (ejected) the SDHC, if it has not, make sure that you remove it safely.

Modify the Boot Code

In order to make the Pi start up and use ssh and WiFi, 2 additional files are necessary on the SDHC, “ssh” and “wpa_supplicant.conf”. The file “ssh” need be nothing more than a name, the conf file needs some additional information, though. The ssh file is a switch that tells the pi to setup to use ss at first boot, once set up the file is deleted and ssh is permanently enabled. These files should be written to the “/boot” partition on the SDHC in the following manner. Remount the SDHC card using file explorer, navigate to the root of the SDHC, you should see just one partition/folder (on a Windows PC) labelled “/boot” containing¬† several files and folders. right click on the folder list and select “new”, then “Text Document”. Simply change the name of the file to “ssh” (with no suffix) and leave it at that.

The “wpa-supplicant.conf” file needs to be copied from a working Raspberry Pi unit using WiFi. Typically its contents will look like:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="your-wifi-ssid-goes-here"
psk="your-wifi-password-goes-here"
key_mgmt=WPA-PSK
}

Replace the ssid, psk and country fields with the data appropriate to your Wifi network. You can attempt to generate this file yourself using a plain text editor if you wish but no guarantees that it will work. The best way is to copy a known working copy from /etc/wpa/wpa_supplicant/wpa_supplicant.conf on a known working Pi SDHC card. Again, save the file to the “/boot” folder on the SDHC card being prepared. Unmount the SDHC card and remove it to the target Raspberry Pi Zero W.

Boot your Pi Zero!

Once you have fitted your newly prepared SDHC card to your Pi, plug in a suitable USB power supply (5 Volts at minimum 1 Amp) and switch on! After about 30 – 45 seconds, your Raspberry Pi Zero W should be connected to the network and visible. IMPORTANT: make sure tha there are no other hosts on your network with the hostname “raspberrypi” as this will confuse the DHCP system. The pi should have acquired an IP address on the network using DHCP. In order to communicate with the Pi, we need to ascertain what this address is. In our case, our (Netgear) router has the facility to look at the DHCP allocation table. Yours should have a similar facility. Log into the router and find the allocation table, sometimes called “connected devices”. Your Pi should be listed with the hostname “raspberrypi”. Make a note of the IP address allocated, usually something like “192.168.0.XX”. If you cannot see it at first, wait a while and perform a refresh.

You should now be able to communicate with your Pi using an ssh client such as “PUTTY” for Windows or by using the ssh command from the command line in a Linux terminal. Log in using the username pi and the password raspberry.

Connect and Setup your Pi Zero!

Once you are connected, it is wise to change the password for user pi, particularly if it is to be visible on the internet. Choose a strong password and use the “passwd” command to effect this.

You may also want to perform other setup options using the raspi-config command. We usually change the hostname as well as we have several pi’s in our network oven at once.



Posted in raspberry pi, tutorial | Tagged , , | 1 Comment