Professional Documents
Culture Documents
Introduction
A "LAMP" stack is a group of open source software that is tpicall installed together to
enable a server to host dnamic websites and web apps. This term is actuall an
acronm which represents the Linux operating sstem, with the Apache web server.
The site data is stored in a MQL database, and dnamic content is processed b
PHP.
In this guide, we'll get a LAMP stack installed on an Ubuntu 16.04 Droplet. Ubuntu will
Prerequisites
Before ou begin with this guide, ou should have a separate, non-root user account
with sudo privileges set up on our server. You can learn how to do this b completing
steps 1-4 in the initial server setup for Ubuntu 16.04.
We can install Apache easil using Ubuntu's package manager, apt . A package
manager allows us to install most software pain-free from a repositor maintained b
Ubuntu. You can learn more about how to use apt here.
ince we are using a sudo command, these operations get executed with root
privileges. It will ask ou for our regular user's password to verif our intentions.
Once ou've entered our password, apt will tell ou which packages it plans to
install and how much extra disk space the'll take up. Press Y and hit Enter to continue,
Signinstallation
and the up for ourwill
newsletter.
proceed. ×
Get the latest tutorials on SysAdmin and open source topics.
et Global erverName to uppress ntax Warnings
ign Up
Next, we will add a single line to the /etc/apache2/apache2.conf file to suppress a
warning message. While harmless, if ou do not set ServerName globall, ou will
S C R O L L TO TO P
receive the following warning when checking our Apache configuration for sntax
errors:
Output
AH00558: apache2: Could not reliably determine the server's fully qualified doma
Syntax OK
Inside, at the bottom of the file, add a ServerName directive, pointing to our primar
domain name. If ou do not have a domain name associated with our server, ou can
use our server's public IP address:
Note
If ou don't know our server's IP address, skip down to the section on how to find our
server's public IP address to find it.
/etc/apache2/apache2.conf
. . .
ServerName server_domain_or_IP
aveSign
and up forthe
close ourfile
newsletter.
when ou are finished. ×
Get the latest tutorials on SysAdmin and open source topics.
Next, check for sntax errors b tping:
ign Up
S C R O L L TO TO P
ince we added the global ServerName directive, all ou should see is:
Output
Syntax OK
Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
If ouSign
lookup
at for
theour
Apache
×
Full profile, it should show that it enables traffic to ports 80
newsletter.
and 443:
Get the latest tutorials on SysAdmin and open source topics.
ign Up
$ sudo ufw app info "Apache Full"
S C R O L L TO TO P
Output
Ports:
80,443/tcp
You can do a spot check right awa to verif that everthing went as planned b
visiting our server's public IP address in our web browser (see the note under the
next heading to find out what our public IP address is if ou do not have this
information alread):
http://your_server_IP_address
You will see the default Ubuntu 16.04 Apache web page, which is there for
informational and testing purposes. It should look something like this:
ign Up
S C R O L L TO TO P
If ou see this page, then our web server is now correctl installed and accessible
through our firewall.
ign Up
$ ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
S C R O L L TO TO P
This will give ou two or three lines back. The are all correct addresses, but our
computer ma onl be able to use one of them, so feel free to tr each one.
An alternative method is to use the curl utilit to contact an outside part to tell ou
how it sees our server. You can do this b asking a specific server what our IP
address is:
Regardless of the method ou use to get our IP address, ou can tpe it into our web
browser's address bar to get to our server.
Again, we can use apt to acquire and install our software. This time, we'll also install
some other "helper" packages that will assist us in getting our components to
communicate with each other:
Note: In this case, ou do not have to run sudo apt-get update prior to the
command. This is because we recentl ran it in the commands above to install Apache.
The package index on our computer should alread be up-to-date.
Sign up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
Again, ou will be shown a list of the packages that will be installed, along with the
amount of disk space the'll take up. Enter Y to continue. ign Up
During the installation, our server will ask ou to select and confirm a password for the
MQL "root" user. This is an administrative account in MQL that hasS Cincreased
R O L L TO TO P
privileges. Think of it as being similar to the root account for the server itself (the one
ou are configuring now is a MQL-specific account, however). Make sure this is a
strong, unique password, and do not leave it blank.
When the installation is complete, we want to run a simple securit script that will
remove some dangerous defaults and lock down access to our database sstem a little
bit. tart the interactive script b running:
$ sudo mysql_secure_installation
You will be asked to enter the password ou set for the MQL root account. Next, ou
will be asked if ou want to configure the VALIDATE PASSWORD PLUGIN .
If ou enabled password validation, ou'll be shown a password strength for the
existing root password, and asked ou if ou want to change that password. If ou are
happ with our current password, enter n for "no" at the prompt:
For the rest of the questions, ou should press Y and hit the Enter ke at each prompt.
This will remove some anonmous users and the test database, disable remote root
logins, and load these new rules so that MQL immediatel respects the changes we
have made.
At this point, our database sstem is now set up and we can move on.
S C R O L L TO TO P
$ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
This should install PHP without an problems. We'll test this in a moment.
In most cases, we'll want to modif the wa that Apache serves files when a director is
requested. Currentl, if a user requests a director from the server, Apache will first
look for a file called index.html . We want to tell our web server to prefer PHP files,
so we'll make Apache look for an index.php file first.
To do this, tpe this command to open the dir.conf file in a text editor with root
privileges:
/etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
We want to move the PHP index file highlighted above to the first position after the
DirectoryIndex specification, like this:
/etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
Sign up for
</IfModule> our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
When ou are finished, save and close the file b pressing Ctrl-X.ign
You'll
Uphave to confirm
the save b tping Y and then hit Enter to confirm the file save location.
After this, we need to restart the Apache web server in order for our changes
S C R O L Lto
TObeTO P
We can also check on the status of the apache2 service using systemctl :
Sample Output
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Wed 2016-04-13 14:28:43 EDT; 45s ago
Docs: man:systemd-sysv-generator(8)
Process: 13581 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCES
Process: 13605 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCC
Tasks: 6 (limit: 512)
CGroup: /system.slice/apache2.service
├─13623 /usr/sbin/apache2 -k start
├─13626 /usr/sbin/apache2 -k start
├─13627 /usr/sbin/apache2 -k start
├─13628 /usr/sbin/apache2 -k start
├─13629 /usr/sbin/apache2 -k start
└─13630 /usr/sbin/apache2 -k start
ign Up
Install PHP Modules
To enhance the functionalit of PHP, we can optionall install some additional modules.
S C R O L L TO TO P
To see the available options for PHP modules and libraries, ou can pipe the results of
apt-cache search into less , a pager which lets ou scroll through the output of
other commands:
The results are all optional components that ou can install. It will give ou a short
description for each:
To get more information about what each module does, ou can either search the
internet, or ou can look at the long description of the package b tping:
ign Up
For example, to find out what the php-cli module does, we could tpe this:
Along with a large amount of other information, ou'll find something that looks like
this:
Output
…
Description-en: command-line interpreter for the PHP scripting language (default
This package provides the /usr/bin/php command interpreter, useful for
testing PHP scripts from a shell or performing general shell scripting tasks.
.
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used
open source general-purpose scripting language that is especially suited
for web development and can be embedded into HTML.
.
This package is a dependency package, which depends on Debian's default
PHP version (currently 7.0).
…
If, after researching, ou decide ou would like to install a package, ou can do so b
using the apt-get install command like we have been doing for our other
software.
If ou want to install more than one module, ou can do that b listing each one,
separated b a space, following the apt-get install command, like this:
In order to test that our sstem is configured properl for PHP, we can create a ver
basic PHP script.
We will call this script info.php . In order for Apache to find the file and serve it
correctl, it must be saved to a ver specific director, which is called the "web root".
In Ubuntu 16.04, this director is located at /var/www/html/ . We can create the file at
that location b tping:
This will open a blank file. We want to put the following text, which is valid PHP code,
inside the file:
info.php
<?php
phpinfo();
?>
Now we can test whether our web server can correctl displa content generated b a
PHP script. To tr this out, we just have to visit this page in our web browser. You'll
need our server's public IP address again.
The page that ou come to should look something like this: ign Up
S C R O L L TO TO P
This page basicall gives ou information about our server from the perspective of
PHP. It is useful for debugging and to ensure that our settings are being applied
correctl.
You probabl want to remove this file after this test because it could actuall give
information about our server to unauthorized users. To do this, ou can tpe this:
$ sudo rm /var/www/html/info.php
ign Up
Conclusion
Now that ou have a LAMP stack installed, ou have man choices for what to do next.
S C R O L L TO TO P
Basicall, ou've installed a platform that will allow ou to install most kinds of websites
As an immediate next step, ou should ensure that connections to our web server are
secured, b serving them via HTTP. The easiest option here is to use Let's Encrpt to
secure our site with a free TL/L certificate.
Install Wordpress the most popular content management sstem on the internet.
et Up PHPMAdmin to help manage our MQL databases from web browser.
Learn how to use FTP to transfer files to and from our server.
Note: We will be updating the links above to our 16.04 documentation as it is written.
ign Up
Related Tutorials
S C R O L L TO TO P
How To Install Moodle on Ubuntu 16.04
73 Comments
Log In to Comment
0
Sign
Nice!
up for our newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
How can I restore a Full Backup done with Cpanel, in m new VP after install
wordpress? ign Up
0 Hi,
The cPanel full backup is a compressed file that normall is named like backup-
[date]_[time]_[cPanel user name].tar.gz . This file can be be uncompressed
on a Mac b double clicking on it. For Windows, most unzip utilities should also be able
to uncompress the file.
After uncompressing the file ou'll have a folder with man other folders and files in it. All
of our website files should be in homedir/public_html and ou'll see the database
backups under the mysql folder. Those two items will make up our WordPress site.
You can then follow a process ver similar to the outlined here to migrate the WordPress
site to our new server.
0 Thank ou!
1 In theor es, but ou ma be better off using the phpMAdmin one-click.
ou can upload all the files in the homedir/public_html folder of the
backup to /var/www/html/ of the One-click based Droplet. Then ou
would create the database in phpMAdmin and import our database
backup also through the phpMAdmin panel. You would need to update the
database connection details in the /var/www/html/wp-config.php
Sign up forfile,
ourbut after that the WordPress site should load.
newsletter. ×
Get the latest tutorials on SysAdmin and open source topics.
Enter password:
ERROR at line 1: Unknown command '\
'.
What ou think? It's better start configuration a Ubuntu 16.04 manuall?
0 Yo!
It's ok now. Backup restored and imported db... how I can configure m
domain from bluehost here on m VP? The Domain will still there.
0 Awesome tutorial!
S C R O L L TO TO P
Considering conflict php5 for php7.0:
However, php5 is not installed. sudo a2dismod php5 returns another error saing it
doesn't exist.
0 I successfull installed apache2 but there is not in ufw list. Wh and how can I
configured it?
0 Thank ou, thank ou, thank ou! i cannot thank ou enough. i could fall at our feet
and kiss them. this tut saved m life!
0 Unable to render php code after upgrading the ubuntu 16.04. B following to install the
php with above process.
0 Hi,
SignI had
up for
theour newsletter.
same ×
issue. I followed the install guide above, but installed php5.6 instead
Get of
thephp7
latest(which comes
tutorials with ubuntu
on SysAdmin and16.04).
open source topics.
output of: apachectl configtest
ign Up
"Apache is running a threaded MPM, but our PHP Module is not compiled to be
threadsafe. You need to recompile PHP"
a2enmod mpmprefork
0 hould this work on 32 bit computers as well? Or do ou need php7 in combination
with 64 bit computer?
I tr to install lamp on ubuntu 16.04 for 2 weeks alread and guess that 32 bit will be the
reason of m failures?
0 Had the same problem, for future references if someone else gets that error, I onl
had to add a 5 (the current version of php) after php to make it work:
Signsudo
up for our newsletter.
apt-get install php5 libapache2-mod-php5 php5-mcrpt php5-msql ×
Get the latest tutorials on SysAdmin and open source topics.
ign Up
packetsniffer August 20, 2016
0 thank ou ver much for this. I had the same problem as JasonRawlings above.
Your trick worked.
S C R O L L TO TO P
0 Nice Tutorial... Question though, I was able to install apache2, php, msql but Web
browser is displaing PHP codes instead of executing it.. M guess is apache issue? an
input? Thanks
0 For those who struggle with seeing the code in the browser instead of the phpinfo()
page...
<? phpinfo();
PHP is
Sign upinstalled
php.ini.
for ourb default with short tags off. Either change our code or change
newsletter. ×
Get
Thisthe
sedlatest tutorials
command willondoSysAdmin
the trick ifand
ouopen source
opt to topics.tags on.
turn short
ign Up
sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php/7.0/apache2/p
S C R O L L TO TO P
0 Hello everone :D
I have a problem.
I can access the application, phpmadmin, etc. But onl inside the server.
1 Sign up for
For ver lazour newsletter.
ssadmins like me: ×
Get
sudothetasksel
latest tutorials on SysAdmin and open source topics.
then choose LAMP-erver.
Drink a coffee and enjo ign Up
S C R O L L TO TO P
slowdive Decemer 7, 2016
this is great, this should be indicated at the ver beginning of this tutorial as an
alternative option!
0
0 One of the best tutorials I have ever seen regarding servers. ALL steps worked (!)
without an issue. This is highl professional. Well done.
Copright © 2017 DigitalOcean™ Inc.
Distros & One-Click Apps Terms, Privac, & Copright ecurit Report a Bug Get Paid to Write
Sign up for our newsletter.
hop
×
Get the latest tutorials on SysAdmin and open source topics.
ign Up
S C R O L L TO TO P