本次带大家了解Ubuntu上的LAMP环境的部署教程,教程理论Debian系通用。

环境部署前最好先给Linux机器进行换源,将官方源替换成国内源以提高下载速度。换源教程可参考:https://www.isisy.com/835.html

Apache安装

1、安装命令

apt-get install apache2

2、检查确认是否安装成功:

apache2 -v

查看Apache版本.png
成功后在Ubuntu的浏览器中输入http://127.0.0.1,出现如下页面表示Apache已正常工作
打开页面.png
其中:
默认Web目录: /var/www/html/
配置目录: /etc/apache2/
全局配置文件: /etc/apache2/apache2.conf
端口配置文件: /etc/apache2/ports.conf
虚拟主机配置文件: /etc/apache2/sites-enabled/000-default.conf

MySQL

1、安装命令

apt-get install mysql-server mysql-client

检查确认是否安装成功:

mysql --version

2、登录测试:

mysql -u root -p

测试登录mysql.png
该安装方式测试无密码,直接回车即可登入数据库。


若需要设置密码等操作,下方给出相关系列设置,按需设置(临时使用或测试等无设置必要可直接跳过下面步骤,其主要受影响的是数据库将无需密码登录,不可远程登录等)。

3.1、初始化配置mysql服务
查找mysql_secure_installation文件位置

whereis mysql_secure_installation

找到位置后执行脚本(脚本为位置后面的第一个文件,正常的话位置基本不变,可直接执行下方命令执行)

/usr/bin/mysql_secure_installation

mysql设置.png
这个脚本会问你几个问题,回答“Y”或“N”根据你的需求来选择。

第一个问题将要求您安装验证密码插件。通常会回答“N”,因为我们知道我的密码是安全的。 如果您愿意,可以回答“Y”。
VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N

接下来,该脚本将要求您为根MySQL用户设置新密码(自行设置即可)。

New password:
Re-enter new password:

该脚本现在将要求您删除匿名用户。 回答:Y
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

询问您是否要远程禁止root登录。 此处按需回答:N
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely?

(Press y|Y for Yes, any other key for No) : N

要求您删除测试数据库并访问它。 回答:Y
By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

要求您重新加载权限表。 回答:Y
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

最后,脚本完成。


3.2、若您上述选择了允许root远程登录,则需再次登录数据库进行相关权限设置

mysql -u root -p

输入您刚刚设置的密码登录数据库。

3.3、切换数据库

use mysql;

3.4、查看用户权限表

select user,host from user;

添加用于root账户远程登录的权限(操作提示报错不用管,忽略)

update user set host = '%' where user = 'root';

3.5、刷新权限

flush privileges;

PHP

1、安装software-properties-common

apt-get install software-properties-common

2、添加ppa源,输入命令后按ENTER继续

add-apt-repository ppa:ondrej/php

3、更新软件索引

apt-get update

4、安装php(此处安装的是PHP 7.3,若安装其他版本请修改)

apt-get install -y php7.3

5、检查PHP的版本

php -v

查看php版本.png
此处php已成功安装,若无其他需求可直接使用;若需要其他模块拓展下方将给出模块安装教程

6.1、查找拓展包(请根据安装的php版本来查找)

apt-cache search php7.3

6.2、按需安装拓展包

apt-get install php7.3-cgi php7.3-curl php7.3-fpm php7.3-json php7.3-mysql php7.3-xmlrpc php7.3-xsl php7.3-yaml

至此,LAMP环境已经部署完毕

End

本文标题:Ubuntu系统部署LAMP环境

本文链接:https://www.isisy.com/886.html

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

声明:转载请注明文章来源。

如果觉得我的文章对你有用,请随意赞赏