3/30/2017 - 4:11 AM

Lamp notes

Lamp notes

Initial server setup with ubuntu 16.04

Create non-root user

adduser josh
#password at prompt
#enter for all other questions

add user to sudo group, so can use sudo to access root privileges

usermod -aG sudo josh

switch to new user

su - josh

test superuser privileges

sudo ll /root

setup ssh key pair

How to install lamp stack on ubuntu 16.x


Fetch updated package index

sudo apt-get update

Install Apache

Install apache package

sudo apt-get install apache2

Verify apache by browsing to http://, where ip is the server ip address, ie:

hostname -I

Install Mysql

Install package (and set root password at prompt)

sudo apt-get install mysql-server


if mysql version > 5.7.6 (would be for Ubuntu 16.04) then data directory has been created for you automatically during installation, so can skip this step. Should you accidentally lose the database files (usually located in /var/lib/mysql) then you can start again without completely reinstalling the server package. This is done with the command mysqld --initialize. If you run this command while a database is already in place, it will report an error ("File exists") and it won't attempt to overwrite the database. However, if you're unsure if the installation procedure has completed correctly, it's OK to delete the directory /var/lib/mysql and re-initialize the database. (from

sudo mysql_install_db (depricated) mysqld --initialize

Run mysql setup script

sudo /usr/bin/mysql_secure_installation

Prompt will ask for root password and series of question. Easiest to answer y for all everything.

Install PHP 5.6 (along side php7 that comes with 16.04)

Could remove php7 but dependancy problem hinted at here, so maybe better to leave php7 alone.

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php 5.6

Then switch to php5.6

# For php in web apps
sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart
# For php-cli in the command line
sudo ln -sfn /usr/bin/php5.6 /etc/alternatives/php

Alternatively, completely remove php7 and instll php5.6

sudo apt-get remove -y --purge php7.0*
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6

unmet dependencies: percona-server-server-5.6 percona-xtradb-cluster-server-5.6 php-apcu php-yac

Test PHP server by creating info.php file in webroot with following contents:


that is:

cd /var/www/html
touch info.php
vim info.php

Then visit http:///info.php to verify and get php config details.

Install mysql module for php5.6

check installed php pkgs

sudo apt list --install | grep php

install mysql for php

sudo apt-get install php5.6-mysql

Install helper packages as well

What are these???

sudo apt-get install libapache2-mod-php5.6 php5.6-mcrypt

Check out some other optional packages.

apt-cache search php- | less apt-cache show <package_name>

Restart apache and browse to

sudo service apache2 restart

Enable Apache mod_rewrite for Drupal

Enable mod_rewrite for Apache and restart

sudo a2enmod rewrite
service apache2 restart

Verify module loaded

sudo apache2ctl -M | grep rewrite_module

Now edit the 000-default.conf located at /etc/apache2/sites-available/

sudo nano /etc/apache2/sites-available/000-default.conf

Add the below mentioned lines just under DocumentRoot /var/www/html

DocumentRoot /var/www/html
<Directory /var/www/html>
    AllowOverride All
    Order Allow,Deny
    Allow from all

This will add AllowOverride within the default website configuration


Troubleshoot apache config issues

The above did not work so changed "AllowOverride None" to "AllowOverride All" in three places in /etc/apache2/apache2.conf

That didn't work, so Added Rewrite Rules Directly to Virtual Host or apache2.conf:

#Added the following from
<Directory /var/www/your_drupal_site>
         RewriteEngine On
         RewriteBase /
         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]