# 如何使用LAMP发布网站或应用？

LAMP环境中部署网站主要分为5个步骤： **①**上传网站代码->**②**修改文件系统用户权限->**③**配置域名（非必要）->**④**增加网站对应的数据库（非必要）->**⑤**完成安装向导

LAMP环境中只部署一个网站还是多个网站、有无域名这两种情况对应的部署操作细节略有不一样，下面分别说明：

## 场景一：服务器只安装一个网站

1. 通过SFTP工具，将网站源文件上传到默认的根目录下：/data/wwwroot/default
2. 通过Putty工具修改用户权限，运行如下一条命令即可：

   ```
   chown -R apache.apache /data/wwwroot/default/
   ```
3. 如果没有可用域名，请直接通过[http://公网ip](http://xn--ip-xz4cq45o) 的方式来访问应用
4. 如果有可用的域名，通过域名控制台将域名解析到服务器公网IP，确保解析成功，然后通过[http://域名](http://xn--eqrt2g) 的方式来访问应用
5. 如果在安装向导过程中提示数据库无法自动创建，需要通过<http://ip/phpmyadmin> 创建数据库

## 场景二：服务器部署多个网站（无域名）

无域名情况下，以部署两个网站为例，具体操作如下：

1. 通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面，假设应用程序目录命为“mysite1”
2. 通过Putty工具修改用户权限，运行如下一条命令即可：

   ```
   chown -R apache.apache /data/wwwroot/default/
   ```
3. 通过<http://ip/mysite1> 的方式来访问应用，进入安装向导
4. 如果在安装向导过程中提示数据库无法自动创建，需要通过<http://ip/phpmyadmin> 创建数据库

安装第二个网站，操作步骤同样

## 场景三：服务器部署多个网站（共用一个域名）

以部署两个网站为例，具体操作如下：

1. 通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面，假设应用程序目录命为“mysite1”
2. 通过Putty工具修改用户权限，运行如下一条命令即可：

   ```
   chown -R apache.apache /data/wwwroot/default/
   ```
3. 通过域名控制台将域名解析到服务器公网IP，确保解析成功进入下一步
4. 通过[http://域名](http://xn--eqrt2g) */mysite1* 的方式来访问应用，进入安装向导
5. 如果在安装向导过程中提示数据库无法自动创建，需要通过<http://ip/phpmyadmin> 创建数据库

安装第二个网站，操作步骤同样

## 场景四：服务器部署多个网站（多个域名）

以部署其中一个网站为例，具体操作如下：

1. 通过SFTP将第一个网站目录上传到/data/wwwroot/default/目录下面，假设应用程序目录命为“mysite1”
2. 通过Putty工具修改用户权限，运行如下一条命令即可：

   ```
   chown -R apache.apache /data/wwwroot/default/
   ```
3. 通过域名控制台将域名解析到服务器公网IP，确保解析成功进入下一步
4. 通过SFTP进入 /ect/httpd/conf.d目录，新增一个conf文件，假设名称为mysite1.conf，将下面内容拷贝到这个配置文件中，将ServerName,ServerAlias,DocumentRoot,ErrorLog,CusomLog,Directory等的“**mydomain,mysite1**”等相关内容更换成你的实际域名、文件夹名称。

   ```
   <VirtualHost *:80>
   ServerName www.mydomain.com
   ServerAlias mydomain.com
   DocumentRoot "/data/wwwroot/default/mysite1"
   ErrorLog "/var/log/httpd/www.mydomain.com_error_apache.log"
   CustomLog "/var/log/httpd/www.mydomain.com_apache.log" common
   <Directory "/data/wwwroot/default/mysite1">
   Options Indexes FollowSymlinks
   AllowOverride All
   Require all granted
   </Directory>
   </VirtualHost>
   ```
5. 重启http服务或重启服务器

   ```
   #~ systemctl restart httpd
   ```
6. 通过[http://域名](http://xn--eqrt2g) 的方式来访问应用，进入安装向导
7. 如果在安装向导过程中提示数据库无法自动创建，需要通过<http://ip/phpmyadmin> 创建数据库

安装第二个网站，操作步骤同样


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://websoft9.gitbook.io/lamp-image-guide/shi-zhan-fang-an/ru-he-shi-yong-lamp-fa-bu-wang-zhan-huo-ying-yong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
