How To Install LAMP Stack On Ubuntu 16.04

By M.el Khamlichi

Share on Facebook

Tweet on Twitter

  • tweet

LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters ofLinux,Apache HTTP Server,Mysql or MariaDB database,and PHP/Perl/Python. This tutorial describes how to install LAMP stack on Ubuntu 16.04,however the steps described below should work on prevIoUs Ubuntu versions such as Ubuntu 15.10/15.04/14.10/14.04/13.10 etc.

Install LAMP Stack On Ubuntu 16.04

1. Install Apache

Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI,SSL and virtual domains.


To install Apache,enter:

sudoapt-getinstallapache2
Enable and start your apache
root@ubuntu:~#systemctlenableapache2
root@ubuntu:~#systemctlstartapache2
root@ubuntu:~#systemctlstatusapache2

●apache2.service-LSB:Apache2webserver
Loaded:loaded(/etc/init.d/apache2;bad;vendorpreset:enabled)
Active:active(running)sinceWed2016-03-0209:23:37PST;1min2sago
Docs:man:systemd-sysv-generator(8)
CGroup:/system.slice/apache2.service
├─22328/usr/sbin/apache2-kstart
├─22331/usr/sbin/apache2-kstart
└─22332/usr/sbin/apache2-kstart

Mar0209:23:36ubuntusystemd[1]:StartingLSB:Apache2webserver...
Mar0209:23:36ubuntuapache2[22304]:*Startingwebserverapache2
Mar0209:23:36ubuntuapache2[22304]:AH00558:apache2:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.1.1.Setthe'S
Mar0209:23:37ubuntuapache2[22304]:*
Mar0209:23:37ubuntusystemd[1]:StartedLSB:Apache2webserver.
Mar0209:24:34ubuntusystemd[1]:StartedLSB:Apache2webserver.
Test Apache:

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.

Apache2 Ubuntu Default Page

2. Install MysqL

MysqL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases,though sqlite probably has more total embedded deployments

sudoapt-getinstallMysqL-serverMysqL-client

During installation,you’ll be asked to setup the MysqL “root” user password. Enter the password and click Ok.

sk@server: ~_001

Re-enter the password.

sk@server: ~_002

MysqL is installed Now.

You can verify the MysqL server status using command:

On Ubuntu 16.04/15.10/15.04:

sudosystemctlstatusMysqL

On Ubuntu 14.10 and prevIoUs versions:

sudoserviceMysqLstatus

Sample output:

●MysqL.service-MysqLCommunityServer
Loaded:loaded(/lib/systemd/system/MysqL.service;enabled;vendorpreset:enabled)
Active:active(running)sinceMon2015-10-2614:23:01IST;28sago
MainPID:3577(MysqLd_safe)
CGroup:/system.slice/MysqL.service
├─3577/bin/sh/usr/bin/MysqLd_safe
└─3924/usr/sbin/MysqLd--basedir=/usr--datadir=/var/lib/MysqL--...

Oct2614:23:00serversystemd[1]:StartingMysqLCommunityServer...
Oct2614:23:00serverMysqLd_safe[3577]:15102614:23:00MysqLd_safeCan't....
Oct2614:23:00serverMysqLd_safe[3577]:15102614:23:00MysqLd_safeLoggin....
Oct2614:23:01serverMysqLd_safe[3577]:15102614:23:01MysqLd_safeStarti...l
Oct2614:23:01serversystemd[1]:StartedMysqLCommunityServer.
Hint:Somelineswereellipsized,use-ltoshowinfull.

3. Install MariaDB

In case you want to use MariaDB instead of MysqL community edition,follow the steps given below.

MariaDB is a drop in replacement for MysqL. It is a robust,scalable and reliable sql server that comes rich set of enhancements.

First you have to remove existing MysqL packages if any. To completely uninstall MysqL along with its configuration files,enter the following commands one by one:

sudosystemctlstopMysqL
sudoapt-getremove--purgeMysqL-serverMysqL-clientMysqL-common
sudoapt-getautoremove
sudoapt-getautoclean
sudorm-rf/var/lib/MysqL/
sudorm-rf/etc/MysqL/

After removing MysqL,run the following command to install MariaDB.

sudoapt-getinstallmariadb-server

Alternatively,you can install it using MariaDB repository if you want to try most recent version of MariaDB. Run the following commands to add PPA. As of writing this,MariaDB PPA is not yet updated to Ubuntu 16.04. However,we can use the repository of Ubuntu 15.10 instead.

sudoapt-getinstallsoftware-properties-common
sudoapt-keyadv--recv-keys--keyserverhkp://keyserver.ubuntu.com:800xcbcb082a1bb943db
sudoadd-apt-repository'debhttp://download.nus.edu.sg/mirror/mariadb/repo/10.1/ubuntuvividmain'

Update the software sources list and install MariaDB using following commands:

sudoapt-getupdate
sudoapt-getinstallmariadb-server

During installation you will be asked to set MysqL ‘root’ user password. Enter the password twice,and complete the installation.

Important Note: In Ubuntu 16.04/15.10/15.04,MariaDB won’t ask you to set root user password during installation.

Also,you can’t set password manually using the following command too:

MysqL_secure_installation

It will throw the following error.

NOTE:RUNNINgalLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMariaDB
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!

InordertologintoMariaDBtosecureit,we'llneedthecurrent
passwordfortherootuser.Ifyou'vejustinstalledMariaDB,and
youhaven'tsettherootpasswordyet,thepasswordwillbeblank,soyoushouldjustpressenterhere.

Entercurrentpasswordforroot(enterfornone):
ERROR1698(28000):Accessdeniedforuser'root'@'localhost'Entercurrentpasswordforroot(enterfornone):

To fix this error,log in to MysqL prompt without password as root user:

sudoMysqL-uroot

Then,run the following commands one by one in the MysqL prompt:

useMysqL;
updateusersetplugin=''whereUser='root';
flushprivileges;
\q

That’s it. Now,set database administrative “root” user password using command. Press Enter and go with the default settings.

MysqL_secure_installation

Sample output:

NOTE:RUNNINgalLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMariaDB
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!

InordertologintoMariaDBtosecureit,soyoushouldjustpressenterhere.

Entercurrentpasswordforroot(enterfornone):
OK,successfullyusedpassword,movingon...

SettingtherootpasswordensuresthatnobodycanlogintotheMariaDB
rootuserwithouttheproperauthorisation.

Setrootpassword?[Y/n]y
Newpassword:
Re-enternewpassword:
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
...Success!

Bydefault,aMariaDBinstallationhasananonymoususer,allowinganyone
tologintoMariaDBwithouthavingtohaveauseraccountcreatedfor
them.Thisisintendedonlyfortesting,andtomaketheinstallation
goabitsmoother.Youshouldremovethembeforemovingintoa
productionenvironment.

Removeanonymoususers?[Y/n]
...Success!

normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This
ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.

disallowrootloginremotely?[Y/n]
...Success!

Bydefault,MariaDBcomeswithadatabasenamed'test'thatanyonecan
access.Thisisalsointendedonlyfortesting,andshouldberemoved
beforemovingintoaproductionenvironment.

Removetestdatabaseandaccesstoit?[Y/n]
-Droppingtestdatabase...
ERROR1008(HY000)atline1:Can'tdropdatabase'test';databasedoesn'texist
...Failed!Notcritical,keepmoving...
-Removingprivilegesontestdatabase...
...Success!

Reloadingtheprivilegetableswillensurethatallchangesmadesofar
willtakeeffectimmediately.

ReloadprivilegetablesNow?[Y/n]
...Success!

Cleaningup...

Alldone!Ifyou'vecompletedalloftheabovesteps,yourMariaDB
installationshouldNowbesecure.

ThanksforusingMariaDB!

Check if mariadb is running or not,using the following command:

sudoserviceMysqLstatus

Sample output:

●MysqL.service-LSB:StartandstoptheMysqLdatabaseserverdaemonLoaded:loaded(/etc/init.d/MysqL)Active:active(running)sinceMon2015-10-2614:26:36IST;2min5sago
Docs:man:systemd-sysv-generator(8)
CGroup:/system.slice/MysqL.service
├─6387/bin/bash/usr/bin/MysqLd_safe
├─6388logger-pdaemonerr-t/etc/init.d/MysqL-i
└─6544/usr/sbin/MysqLd--basedir=/usr--datadir=/var/lib/MysqL--...

Oct2614:26:39server/etc/MysqL/debian-start[6595]:MysqL.time_zone_transit...
Oct2614:26:39server/etc/MysqL/debian-start[6595]:MysqL.time_zone_transit...
Oct2614:26:39server/etc/MysqL/debian-start[6595]:MysqL.user...
Oct2614:26:39server/etc/MysqL/debian-start[6595]:Phase2/6:Fixingviews
Oct2614:26:39server/etc/MysqL/debian-start[6595]:Processingdatabases
Oct2614:26:39server/etc/MysqL/debian-start[6595]:information_schema
Oct2614:26:39server/etc/MysqL/debian-start[6595]:MysqL
Oct2614:26:39server/etc/MysqL/debian-start[6595]:performance_schema
Oct2614:26:39server/etc/MysqL/debian-start[6653]:Checkingforinsecurer...
Oct2614:26:39server/etc/MysqL/debian-start[6657]:Triggeringmyisam-recov...
Hint:Somelineswereellipsized,use-ltoshowinfull.

4. Install PHP (PHP7)

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.

Install PHP with following command:

sudoapt-getupdate
sudoapt-getinstallPHP7.0-MysqLPHP7.0-curlPHP7.0-jsonPHP7.0-cgiPHP7.0libapache2-mod-PHP7

Test your PHP version

root@ubuntu:~#PHP-v
PHP7.0.3-3(cli)(NTS)
copyright(c)1997-2016ThePHPGroup
ZendEnginev3.0.0,copyright(c)1998-2016ZendTechnologies
withZendOPcachev7.0.6-dev,copyright(c)1999-2016,byZendTechnologies
root@ubuntu:~#

To test PHP,create a sample “testPHP.PHP” file in Apache document root folder.

sudovi/var/www/html/testPHP.PHP

Add the following lines:

<?PHP
PHPinfo();
?>

Restart apache2 service.

On Ubuntu 15.10/15.04:

sudosystemctlrestartapache2

On Ubuntu 14.10 and lower versions:

sudoserviceapache2restart

Navigate to http://server-ip-address/testPHP.PHP. It will display all the details about PHP such as version,build date and commands etc.

<a href=PHP7.03" height="851" width="1200" src="http://www.unixmen.com/wp-content/uploads/2016/03/PHP7.03.png">

If you want to install all PHP modules at once,enter the command sudo apt-get install PHP* and restart the apache2 service. To verify the modules,open web browser and navigate to http://server-ip-address/testPHP.PHP. You will able to see all installed PHP modules.

5. Manage MysqL Databases (Optional)

Install PHPMyAdmin

PHPMyAdmin is a free open-source web interface tool used to manage your MysqL databases. It is available in the Official Debian repositories. So install it with command:

sudoapt-getinstallPHPmyadmin

Select the Web server that should be automatically configured to run PHPMyAdmin. In my case,it is apache2.

sk@server: ~_004

The PHPMyAdmin must have a database installed and configured before it can be used. This can be optionally handled by dbconfig-common.

Select ‘Yes’ to configure database for PHPmyadmin wjth dbconfig-common.

sk@server: ~_005

Enter password of the database’s administrative user.

sk@server: ~_008

Enter MysqL application password for PHPmyadmin:

sk@server: ~_006

Re-enter password:

sk@server: ~_009

Success! PHPMyAdmin installation is installed.

Additional Note: if you followed all steps carefully,PHPMyAdmin should work just fine. In case PHPMyAdmin is not working,please do the following steps.

Open terminal,and type:

sudonano/etc/apache2/apache2.conf

Add the following line at the end.

Include/etc/PHPmyadmin/apache.conf

Save and Exit. Restart apache service:

On Ubuntu 16.04/15.10/15.04:

sudosystemctlrestartapache2

On Ubuntu 14.10 and lower versions:

sudo/etc/init.d/apache2restart

6. Access PHPMyAdmin Web Console

Now,you can access the PHPmyadmin console by navigating to http://server-ip-address/PHPmyadmin/ from your browser.

Enter your MysqL username and password which you have given in prevIoUs steps. In my case its “root” and “ubuntu”.

phpMyAdmin - Google Chrome_009

You will be redirected to PHPMyAdmin main web interface.

192.168.1.103 - localhost | phpMyAdmin 4.4.13.1deb1 - Google Chrome_010

From here,you can manage your MysqL databases from PHPMyAdmin web interface.

That’s it. Your LAMP stack is ready to use.

ubuntu 16.04 LAMP 安装的更多相关文章

  1. iOS – 友好的NSDate格式

    我需要在我的应用程序中显示帖子的日期给用户,现在我用这种格式:“5月25日星期五”.如何格式化NSDate以阅读“2小时前”的内容?使其更加用户友好.解决方法NSDateFormatter不能做这样的事情;你将需要建立自己的规则.我想像:所以这是打印’x分钟前’或’x小时前’从日期起24小时,通常是一天.

  2. 从iOS应用程序发送帖子到PHP脚本不工作…简单的解决方案就像

    我之前已经做了好几次了但是由于某些原因我无法通过这个帖子…我尝试了设置为_POST且没有的变量的PHP脚本……当它们未设置为发布时它工作精细.这是我的iOS代码:这里是PHP的一大块,POST变量不在正确的位置?我想这对于更有经验的开发人员来说是一个相当简单的答案,感谢您的帮助!解决方法$_POST是一个数组,而不是一个函数.您需要使用方括号来访问数组索引:

  3. 记一次云计算测试实验-openstack-icehouse-安装swift

    -----------------------controller:---------------------------------sourceadmin-openrc.shkeystoneuser-create--name=swift--pass=000000--email=swift@localhostkeystoneuser-role-add--user=swift--tenant=ser

  4. Project Perfect让Swift在服务器端跑起来-在Linux上创建你的Perfect项目(三)

    前两篇,分别讲述了入门和在Linux下部署,现在得说说如何在Linux下开发了。在Linux下开发,相对比在Mac下开发更灵活。我们先来看看构建基于Perfect的网站服务的编译方式如图通过引用基础库PerfectLib和数据链接,中间件模块创建你的网页文件,并用makefile打包生成你的网站动态库。所以如果你只是在Linux下构建项目,你只需要先创建好你的Handlers.swift即可。根据上面的方式我们开始在Linux下创建我们的Perfect项目。这里我在Perfect文件夹创建了一个Demo文

  5. 使用 Swift 语言编写 Android 应用入门

    Swift标准库可以编译安卓armv7的内核,这使得可以在安卓移动设备上执行Swift语句代码。做梦,虽然Swift编译器可以胜任在安卓设备上编译Swift代码并运行。这需要的不仅仅是用Swift标准库编写一个APP,更多的是你需要一些框架来搭建你的应用用户界面,以上这些Swift标准库不能提供。简单来说,构建在安卓设备上使用的Swiftstdlib需要libiconv和libicu。通过命令行执行以下命令:gitclonegit@github.com:SwiftAndroid/libiconv-libi

  6. Project Perfect让Swift在服务器端跑起来-Hi Linux(二)

    开篇写了一个简单的入门,今天想说说怎么让Perfect项目在Linux上运行。Swift开源后,苹果让Swift不仅在OSX/iOS上跑,更让Swift在Linux/Windows上跑。作为服务端的Perfect框架+RemObjectSilver,让Swift成为了一个全栈语言。Perfect由于是服务端的,让Perfect在Linux上跑是必然的事情。从第一篇文章中我们可以了解到Perfect由PerfectLib和PerfectServer组成。

  7. Project Perfect让Swift在服务器端跑起来-在Linux上创建你的Perfect项

    前两篇,分别讲述了入门和在Linux下部署,现在得说说如何在Linux下开发了。在Linux下开发,相对比在Mac下开发更灵活。我们先来看看构建基于Perfect的网站服务的编译方式如图通过引用基础库PerfectLib和数据链接,中间件模块创建你的网页文件,并用makefile打包生成你的网站动态库。所以如果你只是在Linux下构建项目,你只需要先创建好你的Handlers.Swift即可。根据上面的方式我们开始在Linux下创建我们的Perfect项目。

  8. Swift for OS X编译Linux?

    我对其他平台上Swift的构建过程感到困惑.Swift是否允许我在OSX上构建Linux项目,或者我是否需要在Linux上专门使用Swift来构建我计划在那里使用的任何东西?我查看了documentation,但这个主题并不是很清楚……

  9. Swift 2和Linux / OS X的区别

    我正在尝试将一些基本的应用程序从OSX移植到Linux,但似乎Linux平台上缺少基本的东西.有些文件缺少什么?

  10. 将Trickle移植到android

    >如何告诉编译器链接我之前为android交叉编译的共享库,以便为android生成最终的可执行命令行应用程序.而且这甚至可以在Android上移植涓流?

随机推荐

  1. crontab发送一个月份的电子邮件

    ubuntu14.04邮件服务器:Postfixroot收到来自crontab的十几封电子邮件.这些邮件包含PHP警告.>我已经解决了这些警告的原因.>我已修复每个cronjobs不发送电子邮件(输出发送到>/dev/null2>&1)>我删除了之前的所有电子邮件/var/mail/root/var/spool/mail/root但我仍然每小时收到十几封电子邮件.这些电子邮件来自cronjobs,

  2. 模拟两个ubuntu服务器计算机之间的慢速连接

    我想模拟以下场景:假设我有4台ubuntu服务器机器A,B,C和D.我想在机器A和机器C之间减少20%的网络带宽,在A和B之间减少10%.使用网络模拟/限制工具来做到这一点?

  3. ubuntu-12.04 – 如何在ubuntu 12.04中卸载从源安装的redis?

    我从源代码在Ubuntu12.04上安装了redis-server.但在某些时候它无法完全安装,最后一次makeinstallcmd失败.然后我刚刚通过apt包安装.现在我很困惑哪个安装正在运行哪个conf文件?实际上我想卸载/删除通过源安装的所有内容,只是想安装一个包.转到源代码树并尝试以下命令:如果这不起作用,您可以列出软件自行安装所需的步骤:

  4. ubuntu – “apt-get source”无法找到包但“apt-get install”和“apt-get cache”可以找到它

    我正在尝试下载软件包的源代码,但是当我运行时它无法找到.但是当我运行apt-cache搜索squid3时,它会找到它.它也适用于apt-getinstallsquid3.我使用的是Ubuntu11.04服务器,这是我的/etc/apt/sources.list我已经多次更新了.我尝试了很多不同的debs,并没有发现任何其他地方的错误.这里的问题是你的二进制包(deb)与你的源包(deb-src)不

  5. ubuntu – 有没有办法检测nginx何时完成正常关闭?

    &&touchrestarted),因为即使Nginx没有完成其关闭,touch命令也会立即执行.有没有好办法呢?这样的事情怎么样?因此,pgrep将查找任何Nginx进程,而while循环将让它坐在那里直到它们全部消失.你可以改变一些有用的东西,比如睡1;/etc/init.d/Nginx停止,以便它会休眠一秒钟,然后尝试使用init.d脚本停止Nginx.你也可以在某处放置一个计数器,这样你就可以在需要太长时间时发出轰击信号.

  6. ubuntu – 如何将所有外发电子邮件从postfix重定向到单个地址进行测试

    我正在为基于Web的应用程序设置测试服务器,该应用程序发送一些电子邮件通知.有时候测试是使用真实的客户数据进行的,因此我需要保证服务器在我们测试时无法向真实客户发送电子邮件.我想要的是配置postfix,以便它接收任何外发电子邮件并将其重定向到一个电子邮件地址,而不是传递到真正的目的地.我正在运行ubuntu服务器9.10.先感谢您设置本地用户以接收所有被困邮件:你需要在main.cf中添加:然后

  7. ubuntu – vagrant无法连接到虚拟框

    当我使用基本的Vagrantfile,只配置了两条线:我看到我的虚拟框打开,但是我的流氓日志多次显示此行直到超时:然后,超时后的一段时间,虚拟框框终于要求我登录,但是太久了!所以我用流氓/流氓记录.然后在我的物理机器上,如果我“流氓ssh”.没有事情发生,直到:怎么了?

  8. ubuntu – Nginx – 转发HTTP AUTH – 用户?

    我和Nginx和Jenkins有些麻烦.我尝试使用Nginx作为Jenkins实例的反向代理,使用HTTP基本身份验证.它到目前为止工作,但我不知道如何传递带有AUTH用户名的标头?}尝试将此指令添加到您的位置块

  9. Debian / Ubuntu – 删除后如何恢复/ var / cache / apt结构?

    我在ubuntu服务器上的空间不足,所以我做了这个命令以节省空间但是现在在尝试使用apt时,我会收到以下错误:等等显然我删除了一些目录结构.有没有办法做apt-getrebuild-var-tree或类似的?

  10. 检查ubuntu上安装的rubygems版本?

    如何查看我的ubuntu盒子上安装的rubygems版本?只是一个想法,列出已安装的软件包和grep为ruby或宝石或其他:)dpkg–get-selections

返回
顶部