Ubuntu上搭建LAMP

一,搭建LAMP环境

1,Apache2 web服务器的安装

apt install apache2  安装Apache

systemctl status apache2 检查是否开启apache,一般安装完毕后会默认开启

systemctl start apache2  开启apache服务器

systemctl stop apache2   关闭apache服务器

systemctl restart apache2  重启apache服务器

使用浏览器访问IP地址,出现如下页面说明apache服务器安装成功

2,MySql数据库的安装

apt install -y mysql-server 安装MySQL数据库

netstat -tap | grep mysql 检查MySQL是否安装成功

为了让数据库更安全和正常运转,进行初始化操作

root@VM-0-6-ubuntu:/# mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

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 #需要安装密码插件吗?
Please set the password for root here.

New password:   输入新的root用户密码

Re-enter new password: 再次输入
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 是否删除匿名账户
Success.


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) :  是否禁止远程登陆

 ... skipping.
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 删除test数据并取消对它的访问权限
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

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
Success.  刷新授权表,让初始化后的设定立即生效。

All done! 
root@VM-0-6-ubuntu:/#

sysytemctl status mysql 检查MySQL服务是否正常运行

3,安装PHP

apt  -y install php 安装PHP 

诉Apache首先提供PHP页面。

打开/etc/apache2/mods-enabled/dir.conf文件并将其更改为首先列出index.php。

<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

 vim /etc/apache2/mods-enabled//dir.conf 

systemctl restart apache2 重启apache web 服务器

测试PHP

在/var/www/html中新建一个phpinfo.php文件  vim phpinfo

在里面写入<?php phpinfo();?>

然后再浏览器当中输入http://{ip}/phpinfo.php进行访问,出现如下页面,表示PHP正常

为了安全,在测试完PHP正常之后删除该文件

rm /var/www/html/phpinfo.php

安装PHP模块

最有可能的是,当您安装基于PHP的应用程序时,它将具有PHP模块依赖性。

一个常见的PHP模块是php-curl模块。

我们可以用apt来安装这些。 只需在您需要安装的模块前面添加“php-”。

apt install php-curl

如果您在查找所需的模块时遇到问题,只需输入“apt install php”(模块的第一个字母),然后点击TAB键。

Ubuntu将为您列出所有匹配的包。

# apt install php-c
php-cache-integration-tests  php-cgi                      php-common                  php-console-table
php-cache-lite              php-cli                      php-composer-ca-bundle      php-constant-time
php-cache-tag-interop        php-cli-prompt              php-composer-semver          php-curl
php-cas                      php-codecoverage            php-composer-spdx-licenses   
php-cassandra                php-codesniffer              php-console-commandline

综上,LAMP现在已经搭建好了,接下来就可以搭建网站了。

二,搭建网站

发布了41 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_32393893/article/details/103732366