Install LAMP Stack on Ubuntu 14.04

DigitalOcean install reference
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04

assuming you have ubuntu already installed via virtualbox or direct install on pc:

first, always do this on new ubuntu installs:

$ sudo apt-get update
$ sudo apt-get upgrade

1. Install apache server

$ sudo apt-get install apache2

If installing on DigitalOcean, go to the ip address of the machine and check that you see the Apache2 Ubuntu Default page.

2. Install MySQL

if necessary, also see:
How to Upgrade MySQL from 5.5 to 5.7

$ sudo apt-get update

$ sudo wget http://dev.mysql.com/get/mysql-apt-config_0.6.0-1_all.deb

$ sudo wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb

$ sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb

You'll see a prompt that asks you which MySQL product you want to configure. The MySQL Server option, which is highlighted, should say mysql-5.7. If it doesn't, press ENTER, then scroll down to mysql-5.7 using the arrow keys, and press ENTER again.

Once the option says mysql-5.7, scroll down on the main menu to Apply and press ENTER again. Now, update your package index.

NOTE: I have had problems where the prompts would not let me proceed with the installation when I selected mysql 5.7. One solution is that when you select ‘OK' on the first screen to exit and you return to the command line, just continue with the code below. This will install 5.7.

Then:

$ sudo apt-get update
$ sudo apt-get install mysql-server php5-mysql

You'll be prompted to create a root password during the installation. Choose a secure one and make sure you remember it, because you'll need it later.

To check the mysql version:

$ mysql --version

Then:

$ sudo mysql_secure_installation

You will be prompted to enter to password for the user root that you just created. Then follow the prompts.

Prerequisites: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14

Testing MySQL:

$ sudo service mysql status

You'll see the following output:

* MySQL Community Server 5.7.16 is running

If MySQL isn't running, you can start it with:

$ sudo service mysql start

For an additional check, you can try connecting to the database using the mysqladmin tool, which is a client that lets you run administrative commands. For example, this command says to connect to MySQL as root (-u root), prompt for a password (-p), and return the version.

mysqladmin -p -u root version

You should see output similar to this:

mysqladmin  Ver 8.42 Distrib 5.7.16, for Linux on x86_64
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version          5.7.16
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 13 min 34 sec

Threads: 1  Questions: 15  Slow queries: 0  Opens: 123  Flush tables: 1  Open tables: 42  Queries per second avg: 0.018

Additional options to tune MySQL or just skip to Step 3.

MySQL Tuner is a Perl script that connects to a running instance of MySQL and provides configuration recommendations based on workload. Ideally, the MySQL instance should have been operating for at least 24 hours before running the tuner. The longer the instance has been running, the better advice MySQL Tuner will give.

Install MySQL Tuner from Ubuntu’s repositories:

$ sudo apt-get install mysqltuner

To run it:

$ sudo mysqltuner

You will be asked for the MySQL root user’s name and password. The output will show two areas of interest: General recommendations and Variables to adjust.

MySQL Tuner is an excellent starting point to optimize a MySQL server, but it would be prudent to perform additional research for configurations tailored to the application(s) utilizing MySQL on your Linode.

Securely Administer MySQL with an SSH Tunnel
https://www.linode.com/docs/databases/mysql/securely-administer-mysql-with-an-ssh-tunnel

also see:
MySQL vs MariaDB

3. Install PHP

$ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

UPDATE: To install Latest PHP

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install php7.2-cli

To make the web server to prefer PHP files over .html files:

sudo nano /etc/apache2/mods-enabled/dir.conf

add the PHP index file to the first position:

<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml inde$
</IfModule>

Ctrl+x to save, ‘Y' to exit.

restart the Apache web server:

sudo service apache2 restart

to install optional PHP components, see this:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04

to test PHP install:

sudo nano /var/www/html/info.php

enter the lines below:

<?php
phpinfo();
?>

Ctrl+x to save, ‘Y' to exit.

4. Install phpMyAdmin:

sudo apt-get install phpmyadmin

IMPORTANT: When the first prompt appearch, apache2 is highlighted, but not selected. Hit “SPACE”, “TAB”, and then “ENTER” to select Apache.

Select ‘YES' on next prompt to configure database for phpmyadmin with dbconfig-common

Enter a password for the database's adminstrative user.

Then provide a password for phpmyadmin to register with the database server, and confirm.

Next, enable php5-mcrypt extention:

sudo php5enmod mcrypt

then restart the server:

sudo service apache2 restart

you can now access phpMyAdmin at
http://domain_name_or_IP/phpmyadmin

5. Installing an SSH server

sudo apt-get install openssh-server

This service will start running as soon as it is installed. To verify this, you can do:

ssh localhost

Also, to access web server and ssh on virtualbox, you must go into ‘Settings' > ‘Network' > click on ‘Advanced' arrow > click ‘Port Forwarding' . click the green ‘+' icon on the right hand side > then:

make sure to put in Host IP (example: 192.168.1.x) and Host Port (example: 80 or something else…) and Guest IP (example 10.0.2.15 or you can find it using ifconfig at terminal) and Guest Port (example: 80 or something else). For SSH, do the same except Host Port and Guest Port are both 22.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.