Ubuntu 16.04 LAMP Server Tutorial With Apache 2
Ubuntu 16.04 LAMP Server Tutorial With Apache 2
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
English|
Tutorials
Tags
Forums
Contribute
Subscribe
ISPConfig
Deutsch
LoginorSignup
News
Tutorialsearch
Tutorials
Ubuntu16.04LAMPservertutorialwithApache2.4,PH
Ubuntu16.04LAMPservertutorialwithApache2.4,
PHP7andMariaDB(insteadofMySQL)
LAMPisshortforLinux,
Apache,MySQL,PHP.This
tutorialshowshowyoucan
installanApache2web
serveronanUbuntu16.04
(XenialXerus)serverwith
PHP7(mod_php)and
MySQLsupport.
Additionally,Iwillinstall
PHPMyAdmintomake
MySQLadministration
easier.ALAMPsetupisthe
perfectbasisforCMS
systemslikeJoomla,
WordpressorDrupal.
PreliminaryNote
ThistutorialexistsfortheseOSversions
Ubuntu15.10(WilyWerewolf)
Ubuntu15.04(VividVervet)
Ubuntu14.10(UtopicUnicorn)
Ubuntu14.04LTS(TrustyTahr)
Ubuntu13.10(SaucySalamander)
Onthispage
PreliminaryNote
InstallingMariaDBasMySQLreplacement
InstallApache2.4
InstallPHP7
TestPHPandgetdetailsaboutyourPHPinstallation
GetMySQL/MariaDBsupportinPHP
InstalltheAPCuPHPcachetospeedupPHP
EnabletheSSLwebsiteinapache
InstallphpMyAdmin
Links
Inthistutorial,Iwillusethehostnameserver1.example.comwiththeIPaddress
192.168.1.100.Thesesettingsmightdifferforyou,soyouhavetoreplacethemwhere
appropriate.
IrecommendtouseaminimalUbuntuserversetupasbasisforthetutorial,thatcanbeavirtual
orrootserverimagewithanUbuntu16.04minimalinstallfromawebhostingcompanyoryouuse
ourminimalservertutorialtoinstallaserverfromscratch.
I'mrunningallthestepsinthistutorialwithrootprivileges,somakesureyou'reloggedinasroot:
sudosu
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
1/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
InstallingMariaDBas
MySQLreplacement
WewillinstallMariaDBinsteadofMySQL.
MariaDBisaMySQLforkmaintainedbythe
originalMySQLdeveloperMontyWidenius.
MariaDBiscompatiblewithMySQLand
providesinterestingnewfeaturesandspeed
improvementswhencomparedtoMySQL.
Runthefollowingcommandtoinstall
MariaDBserverandclient:
aptgetyinstallmariadbservermariadbclient
NowwesetarootpasswordforMariaDB.
mysql_secure_installation
Youwillbeaskedthesequestions:
Entercurrentpasswordforroot(enterfornone):<pressenter
Setrootpassword?[Y/n]<y
Newpassword:<EnterthenewMariaDBrootpasswordhere
Reenternewpassword:<Repeatthepassword
Removeanonymoususers?[Y/n]<y
Disallowrootloginremotely?[Y/n]<y
Reloadprivilegetablesnow?[Y/n]<y
TestthelogintoMariaDBwiththe"mysqlcommand"
mysqlurootp
andentertheMariaDBrootpasswordthatyou'vesetabove.Theresultshouldbesimilartothe
screenshotbelow:
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
2/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
ToleavetheMariaDBshell,enterthecommand"quit"andpressenter.
InstallApache2.4
Apache2isavailableasanUbuntupackage,thereforewecaninstallitlikethis:
aptgetyinstallapache2
Nowdirectyourbrowsertohttp://192.168.1.100,andyoushouldseetheApache2default
page(Itworks!):
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
3/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Thedocumentrootoftheapachedefaultvhostis/var/www/htmlonUbuntuandthemain
configurationfileis/etc/apache2/apache2.conf.Theconfigurationsystemisfully
documentedin/usr/share/doc/apache2/README.Debian.gz.
InstallPHP7
WecaninstallPHP7andtheApachePHPmoduleasfollows:
aptgetyinstallphp7.0libapache2modphp7.0
ThenrestartApache:
systemctlrestartapache2
TestPHPandgetdetailsaboutyourPHPinstallation
Thedocumentrootofthedefaultwebsiteis/var/www/html.WewillnowcreateasmallPHPfile
(info.php)inthatdirectoryandcallitinabrowser.Thefilewilldisplaylotsofusefuldetailsabout
ourPHPinstallation,suchastheinstalledPHPversion.
nano/var/www/html/info.php
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
4/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
<?php
phpinfo()
?>
Thenchangetheowneroftheinfo.phpfiletothewwwdatauserandgroup.
chownwwwdata:wwwdata/var/www/html/info.php
Nowwecallthatfileinabrowser(e.g.http://192.168.1.100/info.php):
Asyousee,PHP7.0isworking,andit'sworkingthroughtheApache2.0Handler,asshownin
theServerAPIline.Ifyouscrollfurtherdown,youwillseeallmodulesthatarealreadyenabled
inPHP5.MySQLisnotlistedtherewhichmeanswedon'thaveMySQL/MariaDBsupportinPHP
yet.
GetMySQL/MariaDBsupportinPHP
TogetMySQLsupportinPHP,wecaninstallthephp7.0mysqlpackage.It'sagoodideato
installsomeotherPHPmodulesaswellasyoumightneedthemforyourapplications.Youcan
searchforavailablePHPmoduleslikethis:
aptcachesearchphp7.0
Picktheonesyouneedandinstallthemlikethis:
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
5/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
aptgetyinstallphp7.0mysqlphp7.0curlphp7.0gdphp7.0intlphppearphp
imagickphp7.0imapphp7.0mcryptphpmemcachephp7.0pspellphp7.0recodephp7.0
sqlite3php7.0tidyphp7.0xmlrpcphp7.0xslphp7.0mbstringphpgettext
NowrestartApache2:
systemctlrestartapache2
PHP7hasnowMySQL/MariaDBsupportasshowninphpinfo()above.
InstalltheAPCuPHPcachetospeedupPHP
APCuisafreePHPopcodecacherforcachingandoptimizingPHPintermediatecode.Itis
stronglyrecommendedtohaveanOpcacheinstalledtospeedupyourPHPpage.
APCucanbeinstalledasfollows:
aptgetyinstallphpapcu
NowrestartApache:
systemctlrestartapache2
Nowreloadhttp://192.168.1.100/info.phpinyourbrowserandscrolldowntothe
modulessectionagain.Youshouldnowfindlotsofnewmodulesthere:
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
6/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Pleasedon'tforgettodeletetheinfo.phpfilewhenyoudon'tneeditanymoreasitprovides
sensitivedetailsofyourserver.Runthefollowingcommandtodeletethefile.
rmf/var/www/html/info.php
EnabletheSSLwebsitein
apache
SSL/TLSisasecuritylayertoencryptthe
connectionbetweenthewebbrowserand
yourserver.Executethefollowing
commandsonyourservertoenablehttps://
support.Run:
a2enmodssl
a2ensitedefaultssl
whichenablesthesslmoduleandaddsasymlinkinthe/etc/apache2/sitesenabledfoldertothe
file/etc/apache2/sitesavailable/defaultssl.conftoincludeitintotheactiveapacheconfiguration.
Thenrestartapachetoenablethenewconfiguration:
systemctlrestartapache2
NowtesttheSSLconnectionbyopeninghttps://192.168.1.100inawebbrowser.
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
7/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
YouwillreceiveanSSLwarningastheSSLcertificateoftheserverisa"selfsigned"SSL
certificate,thismeansthatthebrowserdoesnottrustthiscertificatebydefaultandyouhaveto
acceptthesecuritywarningfirst.Afteracceptingthewarning,youwillseetheapachedefaultpage.
Theclosed"GreenLock"infrontoftheURLinthebrowsershowsthattheconnectionis
encrypted.TogetridoftheSSLwarning,replacetheselfsignedSSLcertificate/etc/ssl/certs/ssl
certsnakeoil.pemwithanofficiallysignedSSLcertificatefromanSSLAuthority.
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
8/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
InstallphpMyAdmin
phpMyAdminisawebinterfacethroughwhichyoucanmanageyourMySQLdatabases.It'sa
goodideatoinstallit:
aptgetyinstallphpmyadmin
Youwillseethefollowingquestions:
Webservertoconfigureautomatically:<Selecttheoption:apache2
Configuredatabaseforphpmyadminwithdbconfigcommon?<Yes
MySQLapplicationpasswordforphpmyadmin:<Pressenter,aptwillcreatearandom
passwordautomatically.
MariaDBenablesaplugincalled"unix_socket"fortherootuserbydefault,thispluginpreventsthat
therootusercanlogintoPHPMyAdminandthatTCPconnectionstoMySQLareworkingforthe
rootuser.Therefore,I'lldeactivatethatpluginwiththefollowingcommand:
echo"updateusersetplugin=''whereUser='root'flushprivileges"|mysqluroot
pmysql
EntertheMariaDBrootpassword,whenrequestedbythemysqlcommand.
Afterward,youcanaccessphpMyAdminunderhttp://192.168.1.100/phpmyadmin/:
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
9/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Links
Apache:http://httpd.apache.org/
PHP:http://www.php.net/
MySQL:http://www.mysql.com/
MariaDB:https://mariadb.com/
Ubuntu:http://www.ubuntu.com/
phpMyAdmin:http://www.phpmyadmin.net/
viewaspdf|
Sharethispage:
Tweet
Follow@howtoforgecom
17.6Kfollowers
Recommend
69
31
25Comment(s)
Addcomment
Name*
Email*
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
10/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Submitcomment
Comments
From:GainSat:2016050302:32:15
Reply
Thankyousomuch.Worksperfectly.
From:Jat:2016050316:40:35
Reply
Nicework,completeandworkedperfectlyfirsttime.
From:JeffBeamat:2016050413:25:12
Reply
excellentworkthanks
From:Allenat:2016050606:38:32
Reply
WWWonderfuull!!!!:)
From:christnoelat:2016050622:09:40
Reply
hellothanksforyourtutoitsworkswithoutproblemsthanksforthetimespentbywrittingititshelp
someonelikeme
From:TuanAnhHaat:2016050810:57:55
Reply
Thankyouverymuch!VielenDankfrIhreHilfe!
From:J.L.Barbryat:2016050909:51:18
Reply
Thankyoutoyouforthistutorialwhichisveryeasytouse.Unfortunately,Igetanerrorinthelast
step,aftertheinstallationofphpMyAdmin:TherequestedURL/phpmyadmin/wasnotfoundonthis
server.
Thesameerrorwith127.0.1/phpmyadminorlocalhost/phpmyadmin.
Itried3timestouninstallandreinstallwithoutsuccess.PitythatUbuntudoesnotofferaLAMP
package!
Bestregards
From:tillat:2016051508:33:22
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
Reply
11/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Trytorun:
dpkgreconfigurephpmyadmin
andensurethatyouselectapache2asconfigoption.Ifnowebserverconfigoptionisselected
duringphpmyadmininstallation,thenthealiastoaccessphpmyadmindoesnotgetaddedtothe
apacheconfig.
From:Garethat:2016052115:39:23
Reply
Hi
Youprobablymissedthefactthatyouneedtoputamarkintheselectionofapache2inthe
config.Itdefinitelylookslikeit'sselecteditwhentheredboxisintheselectionthing,butunless
youpressspaceitwon'tmarkitasselectedanditwon'tconfigureititforapache.Hopethat
makessense?!
Cheers
Gareth
From:BobWat:2016051315:06:13
Reply
Followedtheinstructionswith16_04andeverythingworkedgreatuptophpMyAdmin.
Igetthemessage:
ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(using?password:NO)
Uninstalledandtriedagain.
Stillataloss????
OtherUbuntuforumpostswereforpassword:YES.
WhatshouldIchecktosolvethis?
From:DSmidgeat:2016051421:05:12
Reply
InstallingAPCuisnotnecessary.
Asitstatesonhttp://php.net/manual/en/intro.apcu.php:"APCuisAPCstrippedofopcodecaching."
From:tillat:2016051508:16:41
Reply
Andthat'sexactlywhyweinstallAPCu.ForOpcodecaching,wehavealready"Opcache"
installed.ButmanysoftwarereliesontheAPCspecificcachingfunctionse.g.asapagecache
andthat'swhyweinstallAPCuontopofOpcache,itaddstheAPCfunctionstoPHPwhen
Opcacheisinstalled.
From:FranzSat:2016051515:07:40
Reply
ThankyoufortheTutorial!Itisveryawesome.
OnUnbuntu16.04igetafailuremessagein/var/syslogifitakeacloserlook.
Itseemsthatsettingasecurepasswordforrootuserwilldocreateproblemswithmysqlcheck
becausethepasswordistnotupdatedin/etc/mysql/debian.cnf
Fordetailssee:
http://askubuntu.com/questions/772785/1604mariadberrorinsyslogmysqlcheck
From:Clarkat:2016051612:52:44
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
Reply
12/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Thanksalotspenthourstryingtogetmylamprunning.Iusedmysqlthough:)
From:tomat:2016051614:53:40
Reply
Thanks,thishelpedgettingmynewdevserverupandrunning:)
From:steveat:2016051701:16:47
Reply
Iwonderifyoucanhelp.Ihavefollowedallyoututorialwhichiswellpresented.butIcannotaccess
phpmyadmin.Ialsodidnotknowwheretoaddthelastlineinyoututorialaboutunix_socket.
ihavereinstalledthephpmyadminandensureapache2istheservertouse.ihavecheckedand
includedthefollowinglinetoapache2.conf
Include/etc/phpmyadmin/apache.conf
butstillnoaccess.anyhelpwouldbegreatthankyou
From:DanteCamachoat:2016051818:48:18
Reply
Thankyousomuchforthispiceofcake!
From:Stephanieat:2016052001:22:31
Reply
Hi
ImanagedtoinstalleverythingfinebutwhenItriedtoruninfo.phpIgotthefollowingmessage:
Forbidden
Youdon'thavepermissiontoaccess/onthisserver.
Apache/2.4.18(Ubuntu)ServeratlocalhostPort80Herearethedocumentrootfile
permissions:root@SatelliteC660:/var/www/html#lsltotal16rwrr1rootroot11321May20
00:56index.htmlrwrr1wwwdatawwwdata35May2001:55info.phproot@Satellite
C660:/var/www/html#
From:Andriyat:2016052322:44:53
Reply
Amazing!Thankyouforthisgreattutorial.
From:stefanogiacominiat:2016052610:00:08
Reply
excellentworkthanks!
From:Bibotat:2016060606:41:51
Reply
Itsays"ERROR1046(3D000)atline1:Nodatabaseselected"
From:otisat:2016060707:47:50
Reply
NotFound
TherequestedURL/phpmyadminwasnotfoundonthisserver.
Apache/2.4.18(Ubuntu)ServeratlocalhostPort80ihaveaproblemtoaccessonphpmyadmini
don'tknowwhy,i'vefollowedperfectlythistuto,pleasecouldyouhelpme?
From:tillat:2016060708:05:04
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
Reply
13/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
Youmissedtoenablephpmyadminforapache(asdescribedinthetutorail).Youcanredothe
stepbyrunning:
dpkgreconfigurephpmyadmin
thenensurethatapache2isselected,theremustshowacrossfortheapacheoptionwhichgets
enabledwiththewhitespacekeyofyourkeyboard.Ifnocrossisshownthere,thenapacheisnot
activeforphpmyadminandyouwontbeabletoreachitthen!
From:Edat:2016060716:58:52
Reply
Hi,
Thanks,butApache2.4isvaluablewiththeeventmoduleenabled,andISPConfigwon'tworkwithit
itinsistsonusingmorkerright?Can'tyouchangethissowecanusethemuchbetterevent,
please?Thanks
From:tillat:2016060807:45:27
Reply
ISPConfigdoesnotdependonaspecificapachemode,youjustwillnotbeabletousethe
mod_phpmodeinispconfiginworkermode.
Tutorials
Ubuntu16.04LAMPservertutorialwithApache2.4,PH
Signupnow!
TutorialInfo
Author:
TillBrehm
Lastupdated:
May20,2016
Tags: apache,linux,mysql,php,ubuntu,webserver
VMwareimagedownload
Ubuntu16.04LAMPservertutorialwithApache
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
14/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
2.4,PHP7andMariaDB
(insteadofMySQL)as
readytousevirtual
machineimagedownload
inova/ovfformat,
compatiblewithVMWare
andVirtualbox.
Download:
Ubuntu_16_04_lamp_server.ova
Guide:
OtherDownloads:
VMWareImageImportGuide.
ListofallVMWareImages
ShareThisPage
Tweet
Follow
Recommend
17.6Kfollowers
69
31
33%
off
SANDISKSSDPLUSSOLID
STATEDRIVESDSSDH
MRP: Rs.4,600.00
Rs.3,079.00
(details+delivery)
SEAGATEDESKTOP1TB
SOLIDSTATEHYBRID
Rs.5,490.00
(details+delivery)
NEW14IN1REPAIR
OPENINGTOOLKIT
Rs.299.00
(details+delivery)
XenforoskinbyXenfocus
HowtoforgeprojektfarmGmbH.
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
Contact
Help
Imprint
Terms
15/16
6/18/2016
Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)
https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/
16/16