內容全為個人理解和自查資料梳理,歡迎各位大神指點!
每天學習較為零散。
day20
一、./configure
?腳本命令
./configure
?是 Unix/Linux 系統中用于配置軟件源代碼的腳本命令,通常用于為后續的?make
?和?make 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.listdeb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiversedeb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiversedeb 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 multiversedeb 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.gztar -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 startAH00558: 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.targetroot@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 ServerLoaded: loaded (/etc/systemd/system/httpd.service; disabled; vendor preset: enabled)Active: active (running) since Tue 2025-06-17 23:20:15 CST; 1min 8s agoProcess: 61799 ExecStart=/usr/local/apache2/bin/apachectl start (code=exited, status=0/SUCCESS)Main PID: 61419 (httpd)Tasks: 0 (limit: 4545)Memory: 4.0KCPU: 11msCGroup: /system.slice/httpd.service? 61419 /usr/local/apache2/bin/httpd -k start6月 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 -Froot@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:8088Apache2 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.1Version table:8.0.42-0ubuntu0.22.04.1 500500 https://mirrors.aliyun.com/ubuntu jammy-security/main amd64 Packages500 https://mirrors.aliyun.com/ubuntu jammy-security/main i386 Packages500 https://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 Packages500 https://mirrors.aliyun.com/ubuntu jammy-updates/main i386 Packages8.0.35-1ubuntu23.04 500500 http://repo.mysql.com/apt/ubuntu lunar/mysql-8.0 amd64 Packages8.0.28-0ubuntu4 500500 https://mirrors.aliyun.com/ubuntu jammy/main amd64 Packages500 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.phproot@xun-virtual-machine:/var/www/html# cat index.php
<?phpphpinfo();
?>#訪問網站
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 admin@example.comDocumentRoot /var/www/html/wordpressServerName 你的域名或IP<Directory /var/www/html/wordpress>AllowOverride All</Directory>ErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${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_(可修改)運行安裝,設置站點標題、管理員賬號和密碼。