How to install LAMP on Ubuntu

How to install LAMP on Ubuntu

About LAMP

LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the virtual private server is already running Ubuntu, the linux part is taken care of. Here is how to install the rest.

First things first: update

LAMP Stack (Apache, Mysql, PHP)

This will install the LAMP stack in one command




Want a more recent version of PHP 5 for Ubuntu? Then use the PPA for PHP5 offered by Ondřej Surý. PHP 5.4+

PHP 5.5+ note: there are significant differences between PHP 5.4. and PHP 5.5!

PHP 7.0 (prior to Ubuntu 16.04)


NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server.

NGINX doesn’t start on its own, so:

Learn about configuring NGINX as a front-end proxy with Apache


phpMyAdmin allows you to manage your MySQL Database via web browser.

Choose Apache and then YES for dbconfig-common. If you ever need to edit phpMyAdmin config:


Webmin is an open-source server management tool much like cPanel.

Scroll to the bottom and paste the following lines then save:

Import the key

Update the sources list

Run the install

Start Webmin

When it’s finished, open Firefox or Chrome and type:

If you’ve installed a fresh copy of Ubuntu (or if you don’t know your password) you can set a new one:

You’ll be prompted to enter your new password twice. Now, you can login to Webmin.


ProFTPd is a high-performance FTP server.

(I always select “standalone”) Turn on Passive FTP via Webmin: Servers –> ProFTPD server –> Virtual Servers –> Default Server –> Networking Options


PostFix Mail

Select “Internet Site” and then enter the domain name you want the Reverse DNS entry to be. BTW: To avoid your server being blacklisted, get a reverse DNS entry!

Alternative PHP Cache (APC)

APC is a PHP opcode cacher and works by caching PHP objects, functions, and database queries into your server’s RAM. If you run a WordPress website – then it takes full advantage of APC out-of-the-box. See my post on The Perfect APC Configuration Note, APC is no longer available in PHP 5.5+ as it’s now called OPCACHE.

By default, Ubuntu will install this from a repository which has an outdated version. To install the latest version of APC:

Uninstall APC


Memcached is a high-performance, distributed memory object caching system. However, it can work together with multiple servers (unlike APC).

Check to see if Memcached is running


Fail2Ban scans log files (e.g. /var/log/apache/error_log) and automatically bans IPs that show malicious signs for exploits.


RSYNC is a open source utility that provides fast incremental file transfer.

Server-to-server transfers with RSYNC


ImageMagick is a software suite to create, edit, compose, or convert bitmap images.


Icecast is a streaming audio server. If you ever wanted to have your own web radio station (like Shoutcast) this is the software.

Configure Icecast2. Mainly, setting up your passwords and default port.

Enable init.d script. Scroll to the bottom and change enable=true

Start icecast2

If you left the default port as 8000 then you can view your Icecast2 Server


Munin is a networked resource monitoring tool that can help analyze resource trends and “what just happened to kill our performance?” problems.

Now, this is a single server setup, so let’s install munin and munin-node

Configure Munin:

The first thing you should see is the operating directories. We need to change one of them:


Now let’s edit apache.conf

Delete everything inside apache.conf  and just add:

Move the web files to /var/www/munin

Set permissions

Restart Munin

Finally, restart Apache


Cacti graphical server monitor provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box.

Choose YES for dbconfig-common and Apache2. When finished you need to configure:

Default user & pass: admin / admin Remove cacti


bmon is a bandwidth monitor capable of retrieving statistics from various input modules.

When it’s finished installing:

Zip and Unzip

In my experience ZIP is great for creating archives for sharing via email or ftp. It’s a universal format that almost everyone can open. I would NOT use ZIP for file backups. For large backups, see 7ZIP or TAR below.

Zip up a folder:

Unzip (extract) an archive:


7ZIP is a very popular archiving program with excellent compression. Plus, it’s open source and supports multiple operating systems.

Create an archive

Extract an archive

TAR (Tape Archive)

TAR –  is the prefered way to handle file backups. I’ve read, the maximum allowed file size only depends on your hard drive. A disk formatted with FAT32 for example, only allows 2GB. You can also compress TAR using GZIP or BZ2.

GZIP – good compression, is very fast. Note: .tar.gz and .tgz are the same:

BZ2 – excellent compression, but slower. I find BZ2 works best if you’re archiving a smaller directory. Note: .tar.bz2 and .tbz are the same:

Untar (extract) an archive and if tarball already contains a directory name, strip it:

If you want to tarball the directory you’re currently in, with say, gzip:

Other handy commands:

View all running services

Restart PHP 7.0

Move files from one directory to another

Copy files from one directory to another

Set the server timezone

Add a user to the list of sudoers (you have to be logged in as root, or now the sudo password)

Download files

Server-to-server transfers with SCP

Server-to-server transfer with SCP into the current directory (Read more about SCP)

List size of directories

Set a password

Edit PHP.ini

Restart Apache

Set Recursive Permissions for your websites directory

Block IP address using IPTABLES

Single IP

IP Range

You can also manage IPTABLES (e.g., the linux firewall) via Webmin under Networking -> Linux Firewall

Manage packages

Remove LAMP

Happy Coding 🙂

Leave a Reply

Notify of
Close Menu