在centos7上使用shell脚本编译安装lamp
时间: 2023-08-14 15:28:45 浏览: 63
好的,在 CentOS 7 上使用 shell 脚本编译安装 LAMP 的步骤如下:
1. 安装必要的软件包:
```bash
sudo yum install -y httpd mariadb-server mariadb php php-mysql php-cli php-curl php-gd php-mbstring php-xml
```
2. 启动 Apache 和 MariaDB:
```bash
sudo systemctl start httpd
sudo systemctl start mariadb
```
3. 配置 MariaDB 数据库:
```bash
sudo mysql_secure_installation
```
4. 创建一个新的 MySQL 数据库:
```bash
sudo mysql -u root -p
CREATE DATABASE database_name;
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
```
5. 修改 Apache 配置文件 /etc/httpd/conf/httpd.conf:
```bash
sudo nano /etc/httpd/conf/httpd.conf
```
找到以下两行:
```
DirectoryIndex index.html
```
将其修改为:
```
DirectoryIndex index.php index.html
```
保存并退出。
6. 重启 Apache:
```bash
sudo systemctl restart httpd
```
7. 创建一个 PHP 文件来测试 LAMP 是否正常工作:
```bash
sudo nano /var/www/html/info.php
```
添加以下代码:
```php
<?php
phpinfo();
?>
```
保存并退出。
8. 在浏览器中输入服务器的 IP 地址或域名,加上 /info.php,访问该文件,如果一切正常,应该能看到 PHP 信息页面。
至此,LAMP 已经安装完成了。