在云服务器下搭建网站博客wordpress +LAMP+HTTPS
我现在以虚拟机ubuntu20.04版本的服务器为例
此软件是findshell
点击下方文字↓即可下载:
#显示本机的IP地址
ip add
公网ip地址是大家都可以访问的到,而我现在的虚拟机服务器地址为内网地址,现在只能我这台电脑能访问的到
假设我现在的虚拟网卡的IP地址为公网ip地址
1. 安装Apache2、MariaDB、PHP、cURL:
apt install apache2 mariadb-server curl php php-mysql libapache2-mod-php php-gd php-curl php-xml php-mbstring php-imagick php-zip
apt 是命令 install 是安装参数 后面的为软件包,每个空格隔开的就是一个软件包
建议一个一个装,如果哪个报错就说明你的apt源里面没有他或其他问题
没有某个安装包的话就去网上搜你服务器版本的apt源或yum源配置教程
例:我现在的是ubuntu20.04 就搜ubuntu20.04 apt源配置教程
配置好才能安装这些软件包,如果没有这些软件包则下面的操作也操作不了
如果是以上界面则安装完成,其他界面错误请重新配置apt源或yum源
2. 为WordPress创建MariaDmariadbB数据库和用户
如果是root用户直接输入以下命令即可,否则最前面都要加sudo
(1) 进入数据库
mariadb
(2) 创建WordPress的数据库,这里的数据库名为“wordpress”:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
(3) 为数据库wordpress创建单独的本地用户名和密码:
# wordpressuser 为用户,最后面123456为密码
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY '123456';
(4) 不重启MySQL服务”的情况下,上面的配置直接生效,然后再退出数据库交互界面:
FLUSH PRIVILEGES;
EXIT;
如果都是ok即命令成功执行,最后一条命令是退出数据库
3. 调整Apache的配置以允许.htaccess覆盖和重写
a2enmod rewrite
4. 配置WordPress:
(1) 下载:
wget https://cn.wordpress.org/wordpress-6.6.2-zh_CN.tar.gz
(2) 解压并移动:
将解压出来的WordPress文件夹“wordpress/”复制或者移动到指定目录,下面的示例命令移动到“/var/www/”文件夹下:
tar -zxvf wordpress-6.6.2-zh_CN.tar.gz -C /var/www/
(3) 创建“.htaccess”文件和“upgrade/”文件夹,将wp-config-sample.php复制更名为wp-config-sample.php
cd /var/www/wordpress/
touch .htaccess
mkdir ./wp-content/upgrade
cp wp-config-sample.php wp-config.php
(4) 将所有文件加入Apache Web服务器运行的用户和组,设置WordPress目录和文件的权限,保证安全性:
chown -R www-data:www-data /var/www/wordpress
find /var/www/wordpress/ -type d -exec chmod 750 {} \;
find /var/www/wordpress/ -type f -exec chmod 640 {} \;
(5) 从WordPress密钥生成器中获取安全值:
curl -s https://api.wordpress.org/secret-key/1.1/salt/
(6) 将第5点的终端输出的内容复制到“wp-config.php”中,并注释掉下面的值,
在下面的位置中根据提示写入用户名和密码等内容:
vim wp-config.php
wordpress 为刚才上面创建的数据库,wordpressuser为用户,123456为密码
(7) 有些情况下会出现首页加载不全等网页加载异常现象,一般是链接不一致引起的,有两种解决方法:
修改的是wp_options表中的siteurl和home两个字段,修改siteurl和home两条数据的值为对应你的数据库IP或者对应域名。也可以登录WordPress仪表盘里面找对应设置进行更改。
打开“wp-config.php”,在“if ( ! defined( 'ABSPATH' ) ) {”的上面任何位置插入如下代码:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
如果是https就写成这样:
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
5. 配置Apache2:
(1) 新建“/etc/apache2/sites-available/wordpress.conf”,“wordpress.conf”也可以换成其他名字:
cd /etc/apache2/
touch ./sites-available/wordpress.conf
(2) 删除“/etc/apache2/sites-enable/000-default.conf”,千万不要把“sites-available”下的“000-default.conf”删掉。将“wordpress.conf”向“/etc/apache2/sites-enabled/”下添加软链接:
cd sites-enabled/
rm 000-default.conf
ln -s ../sites-available/wordpress.conf wordpress.conf #一定要在/etc/apache2/sites-enabled目录下执行这条命令
ls -alt
以下内容需要购买域名才能继续下去,有域名即可
(3) 编辑“wordpress.conf”,拒接直接通过访问IPv4地址访问WordPress,下面以本网站为例:
vim wordpress.conf
<VirtualHost *:80>
ServerName www.maybe.xyz
#Redirect permanent / https://www.maybe.xyz/
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName 192.168.146.130
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
ServerName 后面是域名
下面的这个ServerName是禁止直接用IP访问本网站
(4) 测试配置:如果输出“Syntax OK”,说明“wordpress.conf”配置语法没问题,重启Apache2服务:
apache2ctl configtest
systemctl restart apache2
6. 安装Certbot和申请配置SSL证书:
(1) 安装Certbot:
apt install python3-certbot-apache
(2) 获取并自动配置证书,下面以本网站为例:
certbot --apache -d www.maybe.xyz
下面的代码为上面这句代码输入后需要的操作
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): hubinqiang@126.com #这里为你的邮箱,下面照着就行,下面最后一个选项选2
-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for hubinqiang.com
dns-01 challenge for hubinqiang.com
-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
(3)经过上面的配置,文件夹下会生成新的文件:“/etc/apache2/sites-available/wordpress-le-ssl.conf”,适当自行修改配置文件,下面给出一个示例:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.maybe.xyz
#ServerAlias localhost 127.0.0.1
DocumentRoot /var/www/wordpress
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/haar.xyz-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/haar.xyz-0001/privkey.pem
<Directory /var/www/wordpress>
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
<VirtualHost *:443>
ServerName 192.168.146.130
<Location />
Order Allow,Deny
Deny from all
</Location>
</VirtualHost>
vim /etc/apache2/sites-available/wordpress-le-ssl.conf
把wordpress-le-ssl.conf 文件里面的ServerName 后面改为你的域名
下面的那个改为你的服务器ip,DocumentRoot /var/www/wordpress 加进去,完成后就可以用浏览器访问你自己的域名,完成wordpress的安装
填写这些信息就可以登录了
版权声明:
作者:maybe
链接:https://www.maybe3212.xyz/archives/26
来源:渗透测试-网络安全-maybe博客
文章版权归作者所有,未经允许请勿转载。
ben
写的太好了,继续加油

