搭建LAMP环境需要安装以下软件:
Apache HTTP Server: Web服务器
MySQL/MariaDB: 数据库服务器
PHP: 脚本语言
下面是在CentOS 7上搭建LAMP环境的步骤:
1.更新系统软件包
sudo yum update
2.安装Apache HTTP Server
sudo yum install httpd
启动Apache:
sudo systemctl start httpd.service
设置开机自启动:
sudo systemctl enable httpd.service
3.安装MySQL/MariaDB
CentOS 7默认使用MariaDB作为数据库服务器,所以可以使用以下命令安装:
sudo yum install mariadb mariadb-server
启动MariaDB:
sudo systemctl start mariadb.service
设置开机自启动:
sudo systemctl enable mariadb.service
配置MariaDB:
sudo mysql_secure_installation
安装过程中需要设置root用户密码,以及是否删除测试数据库和禁止远程root登录等。
4.安装PHP
sudo yum install php php-mysql
测试LAMP环境
在Apache的默认网站目录/var/www/html/下创建一个php文件,例如:
sudo nano /var/www/html/test.php
输入以下内容:
<?php
phpinfo();
?>
保存并退出,然后在浏览器中访问http://服务器IP地址/test.php,如果能看到PHP信息页面,则表示LAMP环境已经搭建完成。