美文网首页
Ubuntu16.04下搭建LAMP环境

Ubuntu16.04下搭建LAMP环境

作者: Su_f819 | 来源:发表于2018-08-14 00:52 被阅读0次

1、Apache2 web 服务器的安装 :

可以先更新一下服务器

sudo apt-get update # 获取最新资源包

sudo apt-get upgrade # 本机软件全部更新

sudo apt-get dist-upgrade # 本机系统软件更新

安装Apache

sudoapt install apache2 -y

检查是否开启Apache,一般安装完会默认开启。

systemctl status apache2

开启、关闭和重启服务器

/etc/init.d/apache2 start

/etc/init.d/apache2 stop

/etc/init.d/apache2 restart

现在开始访问你的 web 服务器,打开浏览器并输入服务器的IP地址或者主机名(http://IP_Address_OR_Host_Name

2、数据库服务器的安装 (MySQL Server 5.7或者MariaDB,选择其中一种即可):

A、MySQL Server 5.7的安装:

sudo apt install mysql-servermysql-client

在安装过程中,它会要求你设置 mysql 服务器 root 帐户的密码。 

设置 mysql 服务器 root 帐户的密码

确认 root 帐户的密码 

确认安装成功

sudonetstat -tap | grep mysql

或者

sudonetstat -ano | grep3306

B、MariaDB的安装

sudo apt-getinstall mariadb-server-10.0mariadb-client-10.0

配置Mariadb的安全选项命令

sudomysql_secure_installation

设定新密码需要输入,其余回车即可

Enter current password for root (enter for none): 当前root的密码,直接回车,因为新数据库没有密码。

Set root password? [Y/n] 回车,默认为输入Y。

New password: 输入新密码

Re-enter new password 再次输入新密码

Remove anonymous users? [Y/n] 移除匿名用户

Disallow root login remotely? [Y/n] 禁止root远程登录

Remove test database and access to it? [Y/n] 移除测试数据库

Reload privilege tables now? [Y/n] 重新加载权限表

数据库测试

mysql-uroot-p

如果显示Welcome以及Mariadb的版本说明安装成功了。

3、PHP 脚本语言的安装:

在终端中执行如下的命令来安装 PHP 7:

sudo apt install php7.0-mysqlphp7.0-curlphp7.0-jsonphp7.0-cgiphp7.0libapache2-mod-php7.0

测试PHP,查看版本:

php--version

输出phpinfo

vim /var/www/html/phpinfo.php

写入如下内容

现在可以从 浏览器中访问这个页面, 输入 : “http://Server_IP/phpinfo.php ,Server_IP是你服务器的ip,可以看到如下页面。 

4、phpMyAdmin 的安装(可选,主要可以通过它的 web 界面来执行所有与数据库管理和其他数据库操作相关的任务):

安装命令:

sudo apt install php-mbstring php7.0-mbstring php-gettext

sudo systemctl restart apache2.service

sudo apt install phpmyadmin

选择 Apache2 并点击确定。 

点击确定来配置 phpMyAdmin 管理的数据库。 

指定 phpMyAdmin 向数据库服务器注册时所用的密码。 

指定 phpMyAdmin 向数据库服务器注册时所用的密码。

现在开始尝试访问 phpMyAdmin,打开浏览器并输入 : “http://Server_IP_OR_Host_Name/phpmyadmin” 

如无法访问:

那就是默认情况下phpMyAdmin的安装路径为/usr/share/phpmyadmin

输入:

cd var/www/html

sudo ln -s /usr/share/phpmyadmin phpmyadmin

OK,到这里Ubuntu16.04下搭建LAMP环境基本已经配置完成,本文参考自几篇博客作者亲测可用整理出来的。 

相关文章

网友评论

      本文标题:Ubuntu16.04下搭建LAMP环境

      本文链接:https://www.haomeiwen.com/subject/xyopbftx.html