有人能告诉我如何创建子域名而不将我链接到一些随机资源吗?我有一个 TLD 并在其上运行一个网站,但我想为其创建一个子域名并在子域名上安装 wordpress。有人能帮帮我吗? 更新 这是正确的吗?
设置数据库
1.
sudo mysql -u root -p
2.
CREATE DATABASE db_name;
3.
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';
4.
GRANT ALL ON db_name.* TO 'database_name'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
5.
FLUSH PRIVILEGES;
6.
EXIT;
7.
cd /tmp && wget https://wordpress.org/latest.tar.gz
8.
tar -zxvf latest.tar.gz
9.
sudo mv wordpress /var/www/html/subdomain
10.
sudo chown -R www-data:www-data /var/www/html/subdomain/
11.
sudo chmod -R 755 /var/www/html/subdomain/
12.
sudo nano /etc/apache2/sites-available/subdomain.conf
13.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/subdomain/
ServerName subdomain.domain.com
ServerAlias www.subdomain.domain.com
<Directory /var/www/html/subdomain/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
14.
sudo a2ensite subdomain.conf
15.
sudo a2enmod rewrite
16.
sudo systemctl restart apache2.service
17.
sudo mv /var/www/html/subdomain/wp-config-sample.php /var/www/html/subdomain/wp-config.php
18.
sudo nano /var/www/html/subdomain/wp-config.php
19.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'db_name');
/** MySQL database username */
define('DB_USER', 'db_username');
/** MySQL database password */
define('DB_PASSWORD', 'db_password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
20. 前往
subdomain.domain.com
它是否正确????
答案1
首先使用以下代码创建虚拟主机。
为您的域名创建虚拟主机配置文件。
vi /etc/apache2/sites-available/your_domain.conf
然后在 your_domain.conf 文件中添加主机配置
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
然后使用下面提到的命令为您的配置文件启用 a2ensite。
sudo a2ensite your_domain.conf
然后使用以下方法检查配置
sudo apache2ctl configtest
如果语法正确,则重新启动 apache,
sudo systemctl restart apache2