Ubuntu上搭建LAMP

一,搭建LAMP环境

1,Apache2 web服务器的安装

apt install apache2  安装Apache

Ubuntu上搭建LAMP_第1张图片

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

Ubuntu上搭建LAMP_第2张图片

systemctl start apache2  开启apache服务器

systemctl stop apache2   关闭apache服务器

systemctl restart apache2  重启apache服务器

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

Ubuntu上搭建LAMP_第3张图片

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:/#

Ubuntu上搭建LAMP_第4张图片

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

Ubuntu上搭建LAMP_第5张图片

3,安装PHP

apt  -y install php 安装PHP 

Ubuntu上搭建LAMP_第6张图片

诉Apache首先提供PHP页面。

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


        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

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

Ubuntu上搭建LAMP_第7张图片

systemctl restart apache2 重启apache web 服务器

测试PHP

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

在里面写入

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

Ubuntu上搭建LAMP_第8张图片

为了安全,在测试完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现在已经搭建好了,接下来就可以搭建网站了。

二,搭建网站

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Ubuntu上搭建LAMP)