Local webserver(LAMP)

It’s time for a disclaimer regarding this blog.  The intent is to show you some things you can do with an Ubuntu installation when you have local root access.  That’s all!  Specifically excluded is any attempt to harden your installation, i.e., protect it from the bad guys.  This page in the blog is all about setting your box up as a local webserver to play and experiment.  As this requires internet access to load packages and google for questions/answers, i.e., troubleshooting, there is a quandary.  How secure is your local environment?  Are you playing on your own machine at home behind a wireless router that probably has a firewall built-in?  Before continuing on this page consider the ramifications of enabling a local webserver on your Ubuntu server in regards to the bad-guys!

What’s the point of having the power of a Linux server at your fingertips if you aren’t going to do something fun with it?  Everybody has browsed a website, heck you had to hit Canonical’s Ubuntu site to download the bits your trusty hardware is running now.  Now that the new install is road-tested, so to speak, let’s start to have some fun.

By the way, if you haven’t figured it out yet, from my perspective you need to be as comfortable with the command-line shell as the mouse and the point-and-click GUI.

https://help.ubuntu.com/lts/serverguide/lamp-overview.html

The link provides a shell command to run, but you almost certainly have to install a package before you can run this command, try these commands:

sudo apt-get install tasksel

sudo tasksel install lamp-server

Similar to the dash re-configure we did earlier, the second command eventually presents a dialog asking you to provide a root password for the mysql database installation.  I highly recommend you set a password here and write it down somewhere.  After doing the lamp-server install, reboot your machine.  This ensures that whatever you test next you know works from a clean reboot.  Sometimes you can install a package and the install scripts aren’t quite right and it kinda-sorta works immediately after installing but mysteriously stops working when you reboot.  Let’s avoid the kinda-sorta works step and make sure that it works after a clean reboot.  After rebooting and logging in, fire up your browser and type this into the URL address:  localhost

You should see something like this.

The first extra package you might want to install is phpmyadmin.

tmike@tmike-HP-ENVY-m7-Notebook:~$ sudo apt-get install phpmyadmin
[sudo] password for tmike:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4 php-gd php-mbstring php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mbstring php7.0-mcrypt
Suggested packages:
libmcrypt-dev mcrypt php-libsodium php-gmp php-imagick
The following NEW packages will be installed:
dbconfig-mysql javascript-common libjs-jquery libjs-sphinxdoc libjs-underscore libmcrypt4 php-gd php-mbstring php-mcrypt php-phpseclib php-tcpdf php7.0-gd php7.0-mbstring php7.0-mcrypt
phpmyadmin
0 upgraded, 15 newly installed, 0 to remove and 24 not upgraded.
Need to get 12.8 MB of archives.
After this operation, 49.4 MB of additional disk space will be used.
Do you want to continue? [Y/n]

As these packages get installed you will see three dialogs appear, in this order…

The phpmyadmin package must have a database installed and configured before it can be used…

If you are reading this blog you most certainly want to answer Yes to this question. If you answered yes to first dialog you will see this screen appear:

Please provide a password for phpmyadmin to register with the database server…

As before, write down or record this password.

The third dialog allows you to choose a web server to use and since the lamp-server installs apache2, this is the recommended selection.

Please choose the web server that should be automatically configured to run phpMyAdmin.

We don’t want to reboot the system after each iteration, but we do need to restart the apache service when new packages are installed that interact with the server:

sudo service apache2 restart

Type this into URL address box of your browser:  localhost://phpmyadmin

For me, I get a very disappointing empty screen in the browser, time to troubleshoot…

First thing to do is check the official Ubuntu help pages.

The Ubuntu page on phpmyadmin didn’t shed any light for me, the configuration looked correct.  Time to turn to Dr. Google, as one of my favorite authors, Stephen Hunter refers to google in some of his novels.

sudo apt-get install php libapache2-mod-php

This resulted in php7 getting installed for me.  Still no joy, so we keep reviewing what’s in the google post and come across a reference to the apache log file and how to view it…

cat /var/log/apache2/error.log

I note these very telling lines at the end of my log file:

[Thu Jul 07 20:19:30.619102 2016] [core:notice] [pid 1260] AH00094: Command line: ‘/usr/sbin/apache2’
[Thu Jul 07 20:27:43.460626 2016] [:error] [pid 1264] [client 127.0.0.1:36250] PHP Fatal error: require_once(): Failed opening required ‘/usr/share/php/php-gettext/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477
[Thu Jul 07 20:30:45.968024 2016] [:error] [pid 1266] [client 127.0.0.1:36258] PHP Fatal error: require_once(): Failed opening required ‘/usr/share/php/php-gettext/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477
[Thu Jul 07 20:43:13.206659 2016] [:error] [pid 1267] [client 127.0.0.1:36446] PHP Fatal error: require_once(): Failed opening required ‘/usr/share/php/php-gettext/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477

Use this as a google search:

PHP Fatal error: require_once(): Failed opening required ‘/usr/share/php/php-gettext/gettext.inc’ (include_path=’.:/usr/share/php’) in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 477

The first hit provides the final step:

tmike@tmike-HP-ENVY-m7-Notebook:/etc/apache2/mods-enabled$ sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Reading package lists… Done
Building dependency tree
Reading state information… Done
php-mbstring is already the newest version (1:7.0+35ubuntu6).
php-mbstring set to manually installed.
php7.0-mbstring is already the newest version (7.0.4-7ubuntu2.1).
php7.0-mbstring set to manually installed.
The following additional packages will be installed:
php-pear php-xml php7.0-xml
The following NEW packages will be installed:
php-gettext php-pear php-xml php7.0-xml
0 upgraded, 4 newly installed, 0 to remove and 18 not upgraded.
Need to get 414 kB of archives.
After this operation, 2,671 kB of additional disk space will be used.
Do you want to continue? [Y/n]

We were missing some php packages that were required to run phpmyadmin.  My guess is that Ubuntu 16.04 is still in its infancy and this type of issue will be resolved by updating package depenencies.

Using your browser retry the URL address:  http://localhost/phpmyadmin

If you login as root with the password you used during package installation and configuration you will see a page like this.

Now that phpmyadmin appears to be functional, reboot your box and confirm it still works.