Update from Sync Service

This commit is contained in:
FNS Service
2026-04-21 20:33:24 +08:00
parent 10cf64e83b
commit 909857f835
4 changed files with 530 additions and 95 deletions

View File

@@ -1,2 +1,165 @@
**阿里云下Ubuntu16下LAMP+wordpress建站记录**
> 来自 <[http://blog.csdn.net/code12hour/article/details/63691403](http://blog.csdn.net/code12hour/article/details/63691403)>
# 阿里云搭建 WordPress
> Ubuntu 16.04 + LAMP 搭建 WordPress 博客
---
## 准备工作
```bash
# 更新系统
sudo apt-get update && sudo apt-get upgrade -y
```
---
## 安装 LAMP
### 1. 安装 Apache
```bash
sudo apt-get install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
```
测试:`http://服务器IP` 应看到 Apache 页面。
### 2. 安装 MySQL
```bash
sudo apt-get install mysql-server -y
# 安全配置
sudo mysql_secure_installation
```
### 3. 安装 PHP
```bash
sudo apt-get install php7.0 php7.0-mysql libapache2-mod-php7.0 -y
```
### 4. 安装 PHP 组件
```bash
sudo apt-get install php7.0-gd php7.0-mbstring php7.0-xml php7.0-curl -y
```
---
## 配置 WordPress
### 1. 下载 WordPress
```bash
cd /tmp
wget https://cn.wordpress.org/wordpress-6.0-zh_CN.tar.gz
tar -xzf wordpress-6.0-zh_CN.tar.gz
sudo mv wordpress /var/www/html/
```
### 2. 设置权限
```bash
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
```
### 3. 创建数据库
```bash
sudo mysql -u root -p
# 在 MySQL 中执行:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY '你的密码';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```
### 4. 配置 WordPress
```bash
cd /var/www/html/wordpress
sudo cp wp-config-sample.php wp-config.php
sudo vim wp-config.php
```
修改数据库连接信息:
```php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', '你的密码');
```
---
## 配置 Apache
### 虚拟主机
```bash
sudo vim /etc/apache2/sites-available/wordpress.conf
```
写入:
```apache
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/wordpress
<Directory /var/www/html/wordpress>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
```
### 启用站点
```bash
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
```
---
## 完成安装
浏览器访问:`http://服务器IP/wordpress`
按提示填写:
- 网站标题
- 用户名
- 密码
- 邮箱
---
## 常用命令
```bash
# 重启 Apache
sudo systemctl restart apache2
# 查看 WordPress 目录
ls -la /var/www/html/wordpress/
# 更新 WordPress通过 Web 界面)
```
---
## 安全建议
1. 修改 WordPress 数据库前缀(默认 `wp_`
2. 安装 SSL 证书启用 HTTPS
3. 定期备份数据库和文件
4. 设置强密码
---
> 参考:[CSDN - LAMP+WordPress 建站](http://blog.csdn.net/code12hour/article/details/63691403)

View File

@@ -1,18 +1,98 @@
安装php7我这里装了好多我也不知道哪些是非必需的
[plain] view plain copy
apt-get install php7.0 php7.0-curl php7.0-gd php7.0-json php7.0-opcache php7.0-xml mcrypt php7.0-curl php7.0-cgi php7.0-xmlrpc php7.0-gd php-pear
# 阿里云管理 PHP
重启apache2和mysql
[plain] view plain copy
systemctl restart apache2
systemctl restart mysql
> PHP 7.0 安装和配置
测试php和apache2
[plain] view plain copy
vim /var/www/html/info.php
输入
[php] view plain copy
## 安装 PHP 组件
```bash
sudo apt-get install php7.0 \
php7.0-curl \
php7.0-gd \
php7.0-json \
php7.0-opcache \
php7.0-xml \
php7.0-mbstring \
php7.0-mcrypt \
php7.0-cgi \
php7.0-xmlrpc \
php-pear
```
---
## 重启服务
```bash
sudo systemctl restart apache2
sudo systemctl restart mysql
```
---
## 测试 PHP
### 创建测试文件
```bash
sudo vim /var/www/html/info.php
```
写入:
```php
<?php
phpinfo();
?>
保存后访问你的域名或者公网ipyour_server_ip/info.php看看有没有对应的信息有就说明成功了。
```
### 访问
浏览器打开:`http://服务器IP/info.php`
能看到 PHP 版本信息页面说明安装成功。
---
## 常用 PHP 配置
### php.ini 位置
```bash
# Apache 模块方式
/etc/php/7.0/apache2/php.ini
# CLI 方式
/etc/php/7.0/cli/php.ini
```
### 常用配置项
```ini
display_errors = On # 显示错误
error_reporting = E_ALL # 错误级别
upload_max_filesize = 20M # 上传文件大小限制
post_max_size = 25M # POST 大小限制
max_execution_time = 300 # 最大执行时间
memory_limit = 256M # 内存限制
```
---
## PHP-FPM可选
如果使用 Nginx
```bash
sudo apt-get install php7.0-fpm
sudo systemctl start php7.0-fpm
```
---
## 常用命令
| 命令 | 说明 |
|------|------|
| `php -v` | 查看 PHP 版本 |
| `php -m` | 查看已加载模块 |
| `php -i` | 详细 PHP 信息 |
| `systemctl restart apache2` | 重启 Apache |

View File

@@ -1,82 +1,142 @@
WordPress的安装与配置
下载wordpress
[plain] view plain copy
# 阿里云管理 WordPress
> WordPress 安装与配置
---
## 下载并安装
```bash
# 下载 WordPress
wget https://wordpress.org/latest.zip
安装unzip:
[plain] view plain copy
# 安装解压工具
apt-get install unzip
解压和后续操作
[plain] view plain copy
# 解压到网站目录
unzip -q latest.zip -d /var/www/html/
cd /var/www/html/wordpress
# 移动文件到根目录
cp -a * ..
rm -r wordpress/
rm -rf wordpress/
# 设置权限
chown www-data:www-data -R /var/www/html/
创建上传目录:
[plain] view plain copy
```
---
## 创建上传目录
```bash
mkdir -p /var/www/html/wp-content/uploads
chown www-data:www-data -R /var/www/html/wp-content/uploads
mysql相关操作
创建mysql账户
[plain] view plain copy
mysql -u root -p
[sql] view plain copy
```sql
CREATE DATABASE wordpress character set utf8 collate utf8_bin;
```
GRANT ALL PRIVILEGES on wordpress.* to 'wpuser'@'localhost' identified by 'your_password';
FLUSH PRIVILEGES;
exit
编辑配置文件
[plain] view plain copy
---
## 创建数据库
```bash
mysql -u root -p
```
```sql
CREATE DATABASE wordpress CHARACTER SET utf8 COLLATE utf8_bin;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost' IDENTIFIED BY '你的密码';
FLUSH PRIVILEGES;
EXIT;
```
---
## 配置 WordPress
```bash
cd /var/www/html
mv wp-config-sample.php wp-config.php
vim wp-config.php
[plain] view plain copy
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress'); /** MySQL database username */
define('DB_USER', 'wpuser'); /** MySQL database password */
define('DB_PASSWORD', 'your_password'); /** MySQL hostname */
define('DB_HOST', 'localhost');
```
设置固定链接:
如果是设置了虚拟主机的话这部分可能和下面的操作不一样我也不太清楚可以去google搜一下
[plain] view plain copy
vim /etc/apache2/sites-available/000-default.conf
[plain] view plain copy
[...]
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName server1.example.com
修改数据库连接:
```php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', '你的密码');
define('DB_HOST', 'localhost');
```
---
## 配置固定链接
### 1. 修改 Apache 配置
```bash
sudo vim /etc/apache2/sites-available/000-default.conf
```
添加:
```apache
<Directory /var/www/html/>
AllowOverride All
AllowOverride All
</Directory>
[...]
就是在里面添加上ServerName到</Directory>这一段
允许URL的重写以及Apache2的重启
[plain] view plain copy
a2enmod rewrite
service apache2 restart
创建.htaccess文件
[plain] view plain copy
```
### 2. 启用 rewrite 模块并重启
```bash
sudo a2enmod rewrite
sudo systemctl restart apache2
```
### 3. 创建 .htaccess
```bash
touch /var/www/html/.htaccess
chown :www-data /var/www/html/.htaccess
chmod 664 /var/www/html/.htaccess
```
添加wordpress安全保护其实我也不太懂具体作用
访问 https://api.wordpress.org/secret-key/1.1/salt/
然后打开wp-config.php
[plain] view plain copy
vim /var/www/html/wp-config.php
[plain] view plain copy
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
---
## 安全密钥
访问https://api.wordpress.org/secret-key/1.1/salt/
复制生成的密钥,添加到 `wp-config.php`
```php
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
将其对应填入。
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
```
---
## 常用命令
```bash
# 重启 Apache
sudo systemctl restart apache2
# 查看 WordPress 文件
ls -la /var/www/html/
# 更新权限
sudo chown -R www-data:www-data /var/www/html/
```
---
## 访问 WordPress
浏览器打开:`http://服务器IP`
按提示完成安装即可。

View File

@@ -1,21 +1,153 @@
1. 首先安装Apache2安装命令sudo apt-get install apache2
[![UbuntuApache2](Exported%20image%2020260407231508-0.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=1)3.  安装完成后,进入到/etc/apache2中根据自己的实际安装目录这边我配置文件在/etc/apache2中。 我们看到没有想象中的httpd.conf配置文件这里要说明的是apache2的配置文件是apache2.conf,而不是http.conf。 打开apache2.conf。写入两条语句ServerName localhostDirectoryIndex index.html index.htm index.php这里的ServerName localhost是为了防止最后开启apache2服务的时候会提示DNS出错。DirectoryIndex index.html index.htm index.php是默认目录的写法。保存退出。可以在apache2.conf中加入  AddDefaultCharset GB2312    设置默认字符集,定义服务器返回给客户机默认字符集(由于西欧UTF-8是Apache默认字符集因此当访问有中文的网页时会出现乱码这时只要将字符集改成GB2312再重启Apache服务即可)Listen 192.168.1.1:80       设置监听ip是192.168.1.1的地址和端口为80Listen 192.168.1.2:8080     设置监听ip是192.168.1.2的地址和端口为8080Alias /down    "/sofТWare /download"   创建虚拟目录创建名为down的虚拟目录它对应的物理路径是/sofТWare /downloadAlias /ftp     "/var/ftp"                创建虚拟目录创建名为ftp的虚拟目录它对应的物理路径是/var/ftp<Directory "/var/www/html">       设置目录权限(<Directory "目录路径">此次写设置目录权限的语句</Directory>      Options FollowSymLinks        page:116      AllowOverride None</Directory>
[![UbuntuApache2](Exported%20image%2020260407231510-1.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=2)
[![UbuntuApache2](Exported%20image%2020260407231513-2.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=3)7.  需要说明的是在apache2中根设置默认主目录在 /etc/apache2/sites-АVailable/default中我们打开default进行配置。如图这里我们的默认主目录设置的路径是/var/www,文档最上方的VirtualHost后方的*代表通配符即表示所有本机ip地址监听端口为80ServerName填写你注册的域名没有可以不填。保存退出。
[![UbuntuApache2](Exported%20image%2020260407231515-3.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=4)
[![UbuntuApache2](Exported%20image%2020260407231517-4.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=5)11.   至此基本配置已经全部完成查看本机ip地址。输入启用apache2的命令:/etc/init.d/apache2 restart.并在浏览器中输入本机ip地址。成功
[![UbuntuApache2](Exported%20image%2020260407231522-5.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=6)
[![UbuntuApache2](Exported%20image%2020260407231525-6.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=7)
[![UbuntuApache2](Exported%20image%2020260407231527-7.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=8)
# 阿里云配置 Apache
## END
注意事项
> Ubuntu Apache2 配置指南
18. 配置文件从httpd.conf变成了apache2.con > 来自 <[https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)>
[![UbuntuApache2](Exported%20image%2020260407231553-8.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=1)[![UbuntuApache2](Exported%20image%2020260407231559-9.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=2)
[![UbuntuApache2](Exported%20image%2020260407231602-10.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=3)[![UbuntuApache2](Exported%20image%2020260407231605-11.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=4)
[![UbuntuApache2](Exported%20image%2020260407231610-12.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=5)[![UbuntuApache2](Exported%20image%2020260407231612-13.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=6)
[![UbuntuApache2](Exported%20image%2020260407231616-14.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=7)
[![UbuntuApache2](Exported%20image%2020260407231620-15.jpeg)](http://jingyan.baidu.com/album/9158e0006581d1a2541228b5.html?picindex=8)
> 来自 <[https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)>
![plain aptget install apache2 aptget install libapa...](Exported%20image%2020260407231623-16.png)
---
## 安装 Apache
```bash
sudo apt-get update
sudo apt-get install apache2 -y
```
---
## 配置文件
### 重要文件位置
| 文件 | 说明 |
|------|------|
| `/etc/apache2/apache2.conf` | 主配置文件 |
| `/etc/apache2/sites-available/` | 站点配置目录 |
| `/etc/apache2/sites-enabled/` | 已启用站点 |
| `/etc/apache2/ports.conf` | 端口配置 |
> ⚠️ **注意**Apache2 用 `apache2.conf`,不是传统的 `httpd.conf`
---
## 基本配置
### 1. 配置 apache2.conf
```bash
sudo vim /etc/apache2/apache2.conf
```
添加:
```apache
ServerName localhost
DirectoryIndex index.html index.htm index.php
```
### 2. 设置默认字符集
```apache
AddDefaultCharset UTF-8
```
### 3. 设置监听端口
```apache
Listen 80 # 监听 80 端口
Listen 8080 # 监听 8080 端口
```
### 4. 创建虚拟目录
```apache
Alias /down "/software/download"
Alias /ftp "/var/ftp"
```
### 5. 设置目录权限
```apache
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
```
---
## 配置站点
### 1. 编辑默认站点
```bash
sudo vim /etc/apache2/sites-available/000-default.conf
```
```apache
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```
### 2. 启用站点
```bash
sudo a2ensite 000-default.conf
sudo a2enmod rewrite
```
---
## 常用命令
```bash
# 启动/停止/重启
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
# 或
sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 restart
# 查看状态
sudo systemctl status apache2
# 启用/禁用站点
sudo a2ensite site-name
sudo a2dissite site-name
```
---
## 测试配置
```bash
# 测试配置文件语法
sudo apache2ctl configtest
# 查看已启用模块
apache2ctl -M
```
---
## 安全建议
1. 禁用不必要的模块
2. 隐藏 Apache 版本信息
3. 启用 HTTPS (Let's Encrypt)
4. 配置防火墙只开放 80/443
---
> 参考:[百度经验 - Ubuntu Apache2 配置](https://jingyan.baidu.com/article/9158e0006581d1a2541228b5.html)