Linux运维新人自用笔记(用虚拟机Ubuntu部署lamp环境,搭建WordPress博客)

内容全为个人理解和自查资料梳理,欢迎各位大神指点!

每天学习较为零散。

day20

一、./configure 脚本命令

./configure 是 Unix/Linux 系统中用于配置软件源代码的脚本命令,通常用于为后续的 makemake install 准备编译环境。

选项 作用
--prefix=/path 指定安装根目录(默认 /usr/local
--bindir=/path 指定可执行文件目录
--libdir=/path 指定库文件目录
--includedir=/path 指定头文件目录
选项 作用
--enable-feature 启用特定功能
--disable-feature 禁用特定功能
--with-package=/path 指定依赖库路径
--without-package 禁用某个依赖
选项 作用
CC=gcc 指定 C 编译器
CFLAGS="-O2 -g" 设置编译标志
LDFLAGS="-L/path" 设置链接库路径

二、Ubuntu桌面版连接ssh服务

Ubuntu22.04桌面版

单击鼠标右键,选择open in terminal 打开终端

复制代码
#编辑资源配置
vi /etc/apt/sources.list

deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

#切换到root
sudo -i

#下载远程连接服务
sudo apt install openssh-server

#开启远程连接
sudo systemctl start ssh

在xshell上登陆连接

三、Ubuntu系统编译安装apache

apache官网

复制代码
https://downloads.apache.org/httpd/

https://downloads.apache.org/apr/

#下载tar包
wget https://downloads.apache.org/httpd/httpd-2.4.63.tar.gz
 tar -zxf httpd-2.4.63.tar.gz 


#运行配置脚本,缺少依赖
root@xun-virtual-machine:/a1/httpd-2.4.63# ./configure 
configure: error: APR not found.  Please read the documentation.

#下载APR依赖
root@xun-virtual-machine:/a1# wget https://downloads.apache.org/apr/apr-1.7.6.tar.gz

#系统缺少C编译器(如GCC),导致无法编译APR(Apache Portable Runtime)库
root@xun-virtual-machine:/a1/apr-1.7.6# ./configure 
configure: error: in '/a1/apr-1.7.6':
configure: error: no acceptable C compiler found in $PATH

#安装编译器
root@xun-virtual-machine:/a1/apr-1.7.6# sudo apt install build-essential

#运行配置脚本,缺少依赖
root@xun-virtual-machine:/a1/apr-1.7.6# ./configure
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

#安装依赖
root@xun-virtual-machine:/a1/apr-1.7.6# sudo apt install libtool autoconf automake

#APR相关依赖安装完毕
root@xun-virtual-machine:/a1/apr-1.7.6# ./configure


 
#继续下载apache服务,缺少APR-util
root@xun-virtual-machine:/a1# cd httpd-2.4.63/
root@xun-virtual-machine:/a1/httpd-2.4.63# ./configure 
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.

#下载tar包
wget https://downloads.apache.org/apr/apr-util-1.6.3.tar.gz
tar -zxf apr-util-1.6.3.tar.gz 


#确保APR已正确安装到系统目录(如/usr/local/apr)
ls /usr/local/apr/bin/apr-1-config

#在配置apr-util时,必须通过--with-apr参数指定APR的安装路径
#此命令明确告知apr-util从/usr/local/apr目录中查找APR的头文件和库
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr



#在apr-util目录下运行配置脚本,指定依赖库路径
./configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

#安装依赖
sudo apt install libpcre3-dev 

#在httpd-2.4.63目录下运行配置脚本,指定依赖库路径
root@xun-virtual-machine:/a1/httpd-2.4.63# 
 ./configure   --prefix=/usr/local/apache2   --with-apr=/usr/local/apr   --with-apr-util=/usr/local/apr-util   --with-pcre=/usr/bin/pcre-config  

#安装
 sudo make install

#启动服务
root@xun-virtual-machine:/a1/httpd-2.4.63# sudo /usr/local/apache2/bin/apachectl start


AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
httpd (pid 61419) already running



这个警告是因为缺少全局 ServerName 配置:

sudo vim /usr/local/apache2/conf/httpd.conf
找到或添加:

ServerName localhost:80

保存后重新加载配置:
root@xun-virtual-machine:/a1/httpd-2.4.63# sudo /usr/local/apache2/bin/apachectl graceful

#再次启动服务
root@xun-virtual-machine:/a1/httpd-2.4.63# sudo /usr/local/apache2/bin/apachectl start
httpd (pid 61419) already running

#创建Systemd服务
sudo vim /etc/systemd/system/httpd.service

[Unit]
Description=Apache HTTP Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl start
ExecStop=/usr/local/apache2/bin/apachectl stop
ExecReload=/usr/local/apache2/bin/apachectl graceful
PIDFile=/usr/local/apache2/logs/httpd.pid
PrivateTmp=true

[Install]
WantedBy=multi-user.target




root@xun-virtual-machine:/a1/httpd-2.4.63# sudo systemctl start httpd
root@xun-virtual-machine:/a1/httpd-2.4.63# sudo systemctl status  httpd
● httpd.service - Apache HTTP Server
     Loaded: loaded (/etc/systemd/system/httpd.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2025-06-17 23:20:15 CST; 1min 8s ago
    Process: 61799 ExecStart=/usr/local/apache2/bin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 61419 (httpd)
      Tasks: 0 (limit: 4545)
     Memory: 4.0K
        CPU: 11ms
     CGroup: /system.slice/httpd.service
             ‣ 61419 /usr/local/apache2/bin/httpd -k start

6月 17 23:20:15 xun-virtual-machine systemd[1]: Starting Apache HTTP Server...
6月 17 23:20:15 xun-virtual-machine apachectl[61802]: httpd (pid 61419) already running
6月 17 23:20:15 xun-virtual-machine systemd[1]: Started Apache HTTP Server.

#下载net工具
apt install net-tools

#查看端口
sudo netstat -tulnp | grep apache
tcp6       0      0 :::8088                 :::*                    LISTEN      2521/apache2          

#关闭防火墙
root@xun-virtual-machine:/a1# iptables -F


root@xun-virtual-machine:/a1# curl -I 127.0.0.1:8088
HTTP/1.1 200 OK
Date: Thu, 19 Jun 2025 05:10:34 GMT
Server: Apache/2.4.52 (Ubuntu)
Last-Modified: Wed, 18 Jun 2025 13:05:23 GMT
ETag: "29af-637d8482a80e5"
Accept-Ranges: bytes
Content-Length: 10671
Vary: Accept-Encoding
Content-Type: text/html

网页访问http://ip:8088


Apache2 Default Page
It works!
This is the default welcome page used to test the correct operation of the Apache2 server after installation on Ubuntu systems. It is based on the equivalent page on Debian, from which the Ubuntu Apache packaging is derived. If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server.

四、配置mysql仓库

下载mysql

复制代码
#交互界面选mysql8.0和ok即可
root@xun-virtual-machine:/a1/b1# wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb

#更新(注意服务器时间是否和网络时间一致)
apt update

#检查可安装的 MySQL 
root@xun-virtual-machine:/a1/b1# apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.42-0ubuntu0.22.04.1
  Version table:
     8.0.42-0ubuntu0.22.04.1 500
        500 https://mirrors.aliyun.com/ubuntu jammy-security/main amd64 Packages
        500 https://mirrors.aliyun.com/ubuntu jammy-security/main i386 Packages
        500 https://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages
        500 https://mirrors.aliyun.com/ubuntu jammy-updates/main i386 Packages
     8.0.35-1ubuntu23.04 500
        500 http://repo.mysql.com/apt/ubuntu lunar/mysql-8.0 amd64 Packages
     8.0.28-0ubuntu4 500
        500 https://mirrors.aliyun.com/ubuntu jammy/main amd64 Packages
        500 https://mirrors.aliyun.com/ubuntu jammy/main i386 Packages


#安装 MySQL 客户端和服务端​
apt install mysql-client
apt install mysql-server


#验证安装的 MySQL 包​
root@xun-virtual-machine:/a1/b1# dpkg -l |grep mysql
ii  mysql-apt-config                           0.8.34-1                                all          Auto configuration for MySQL APT Repo.
ii  mysql-client                               8.0.42-0ubuntu0.22.04.1                 all          MySQL database client (metapackage depending on the latest version)
ii  mysql-client-8.0                           8.0.42-0ubuntu0.22.04.1                 amd64        MySQL database client binaries
ii  mysql-client-core-8.0                      8.0.42-0ubuntu0.22.04.1                 amd64        MySQL database core client binaries
ii  mysql-common                               5.8+1.0.8                               all          MySQL database common files, e.g. /etc/mysql/my.cnf
rc  mysql-community-server                     8.0.0-dmr-1ubuntu14.04                  amd64        MySQL Server
ii  mysql-server                               8.0.42-0ubuntu0.22.04.1                 all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-8.0                           8.0.42-0ubuntu0.22.04.1                 amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-8.0                      8.0.42-0ubuntu0.22.04.1                 amd64


#启动mysql服务
systemctl start mysql

#安全配置
root@xun-virtual-machine:/a1/b1# sudo mysql_secure_installation
选择密码验证组件​​
Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: y

选择密码强度级别​​
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

后续配置​​
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] N
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

#登录 MySQL​
root@xun-virtual-machine:/a1/b1# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.42-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.01 sec)

mysql> CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'zxcvbn';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT;
Bye

五、下载php

复制代码
#下载解压
root@xun-virtual-machine:/a1/php# wget https://www.php.net/distributions/php-8.1.32.tar.gz
tar -zxf php-8.1.32.tar.gz 

apt-get install libcurl4-openssl-dev libonig-dev libzip-dev libgd-dev libfreetype6-dev libjpeg-dev libpng-dev libxml2-dev libssl-dev pkg-config

#检查安装配置环境
./configure \
    --prefix=/usr/local/php \
    --with-config-file-path=/usr/local/etc \
    --with-config-file-scan-dir=/usr/local/etc/php.d \
    --with-apxs2=/usr/local/apache2/bin/apxs \
    --enable-fpm \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-zlib \
    --with-curl \
    --with-zip \
    --with-gd \
    --with-freetype \
    --with-jpeg \
    --with-webp \
    --with-xpm \
    --enable-sockets \
    --enable-soap \
    --enable-opcache \
    --enable-mbstring \
    --enable-mbregex \
    --enable-pcntl \
    --enable-shmop \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-calendar \
    --enable-bcmath \
    --enable-maintainer-zts


+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.




root@xun-virtual-machine:/a1/php/php-8.1.32# cd /var/www/html/

#将apache的html文件改名
root@xun-virtual-machine:/var/www/html# ll
total 24
drwxr-xr-x 2 root root  4096  6月 19 13:56 ./
drwxr-xr-x 3 root root  4096  6月 18 21:05 ../
-rw-r--r-- 1 root root 10671  6月 19 13:30 index.html_s
-rw-r--r-- 1 root root    21  6月 19 13:30 index.php


root@xun-virtual-machine:/var/www/html# cat index.php 
<?php
 phpinfo();
?>


#访问网站
PHP Version 8.1.2-1ubuntu2.21
System	Linux xun-virtual-machine 6.8.0-60-generic #63~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 22 19:00:15 UTC 2 x86_64
Build Date	Mar 24 2025 19:04:23
Build System	Linux
Server API	Apache 2.0 Handler
Virtual Directory Support	disabled
Configuration File (php.ini) Path	/etc/php/8.1/apache2
Loaded Configuration File	(none)
Scan this dir for additional .ini files	/etc/php/8.1/apache2/conf.d

#将zip下载到:/var/www/html,解压
wget https://wordpress.org/latest.zip

#将wordpress/* 移动到 当前/var/www/html目录下
root@xun-virtual-machine:/var/www/html# mv wordpress/* .
root@xun-virtual-machine:/var/www/html# ll
total 28140
drwxr-xr-x  6 root root     4096  6月 19 14:45 ./
drwxr-xr-x  3 root root     4096  6月 18 21:05 ../
-rw-r--r--  1 root root    10671  6月 19 13:30 index.html_s
-rw-r--r--  1 root root      405  2月  6  2020 index.php
-rw-r--r--  1 root root 28551696  5月  1 00:48 latest.zip
-rw-r--r--  1 root root    19903  3月  6 14:24 license.txt
-rw-r--r--  1 root root     7425  3月  7 08:45 readme.html
drwxr-xr-x  2 root root     4096  6月 19 14:45 wordpress/
-rw-r--r--  1 root root     7387  2月 13  2024 wp-activate.php
drwxr-xr-x  9 root root     4096  4月 30 16:41 wp-admin/
-rw-r--r--  1 root root      351  2月  6  2020 wp-blog-header.php
-rw-r--r--  1 root root     2323  6月 14  2023 wp-comments-post.php
-rw-r--r--  1 root root     3336 10月 15  2024 wp-config-sample.php
drwxr-xr-x  4 root root     4096  4月 14 23:37 wp-content/
-rw-r--r--  1 root root     5617  8月  2  2024 wp-cron.php
drwxr-xr-x 30 root root    12288  4月 30 16:41 wp-includes/
-rw-r--r--  1 root root     2502 11月 26  2022 wp-links-opml.php
-rw-r--r--  1 root root     3937  3月 11  2024 wp-load.php
-rw-r--r--  1 root root    51414  2月  3 16:55 wp-login.php
-rw-r--r--  1 root root     8727  2月  8 16:00 wp-mail.php
-rw-r--r--  1 root root    30081  3月  4 13:06 wp-settings.php
-rw-r--r--  1 root root    34516  3月 10 18:16 wp-signup.php
-rw-r--r--  1 root root     5102 10月 18  2024 wp-trackback.php
-rw-r--r--  1 root root     3205 11月  8  2024 xmlrpc.php

六、搭建 WordPress论坛

复制代码
您的 PHP 安装似乎缺少 WordPress 所需的 MySQL 扩展。

请检查 PHP 扩展是否已安装并启用。mysqli

如果您不确定这些条款的含义,您应该联系您的房东。如果您仍需要帮助,可以随时访问 WordPress 支持论坛。

root@xun-virtual-machine:/var/www/html# apt install php-mysqli -y

#将文件移动到 Apache 根目录:
sudo mv wordpress /var/www/html/
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress


#配置 Apache 虚拟主机
#创建配置文件:
sudo vim /etc/apache2/sites-available/wordpress.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/wordpress
    ServerName 你的域名或IP

    <Directory /var/www/html/wordpress>
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>



#启用配置并重载 Apache:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2



完成 WordPress 安装
浏览器访问 http://你的域名或IP。

按提示选择语言,填写数据库信息:

数据库名: wordpress

用户名: wordpressuser

密码: 你设置的密码

主机: localhost

表前缀: 默认 wp_(可修改)

运行安装,设置站点标题、管理员账号和密码。
相关推荐
眠りたいです1 小时前
MySQL基础与常用数据类型浅析
linux·数据库·mysql
武子康1 小时前
Java-49 深入浅出 Tomcat 手写 Tomcat 实现【02】HttpServlet Request RequestProcessor
java·开发语言·后端·学习·spring cloud·tomcat
听风lighting2 小时前
1. C++ WebServer项目分享
linux·c语言·c++·设计模式·嵌入式·webserver
chengf2232 小时前
WSL 安装使用和常用命令
linux
MALLYUN2 小时前
ssh 服务和 rsync 数据同步
linux·服务器·ssh
we199898982 小时前
Ubuntu最新版本(Ubuntu22.04LTS)安装nfs服务器
linux·服务器·ubuntu
、我是男生。2 小时前
Linux、Ubuntu、虚拟机三者的关系和角色
linux·运维·ubuntu
우 유3 小时前
Linux从入门到入门
linux·运维·服务器
叶子爱分享3 小时前
如何高效的学习算法与数据结构
学习
Sally璐璐4 小时前
CentOS查日志
linux·运维·centos