環境準備: 內網IP:192.168.0.36 軟體包版本/下載地址: mysql軟體包: wget https://dev.mysql.com/get/Downloads/mysql-5.6.24.tar.gzapache軟體包: wget https://mirrors.aliyun.com/a ...
環境準備:
內網IP:192.168.0.36
軟體包版本/下載地址:
mysql軟體包:
wget https://dev.mysql.com/get/Downloads/mysql-5.6.24.tar.gz
apache軟體包:
wget https://mirrors.aliyun.com/apache/httpd/httpd-2.4.38.tar.gz wget https://mirrors.aliyun.com/apache/apr/apr-1.6.5.tar.gz wget https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz
php軟體包: wget http://cn2.php.net/get/php-7.0.32.tar.bz2/from/this/mirror
一、搭建apache
1、下載httpd、apr、apr-utils 軟體包:
2、解壓軟體包並編譯安裝Apache服務
① 解壓軟體包,把apr和apr-utils移動到httpd目錄下的srclib文件夾下,一起進行編譯
tar xf apr-util-1.6.1.tar.gz tar xf apr-1.6.5.tar.gz tar xf httpd-2.4.38.tar.gz
mv apr-1.6.5 httpd-2.4.38/srclib/apr
mv apr-util-1.6.1 httpd-2.4.38/srclib/apr-util
② 安裝相關的依賴包、庫文件等
yum groupinstall -y "Development Tools" && yum install libtool expat-devel pcre pcre-devel openssl-devel -y
③ 檢查編譯環境、並安裝
./configure --prefix=/usr/local/apache24 \ --enable-ssl \ --enable-so \ --with-mpm=event \ --with-included-apr \ --enable-cgi \ --enable-rewrite \ --enable-mods-shared=most \ --enable-mpms-shared=all && make -j6 && make install
3、添加httpd的環境變數
echo "export PATH=$PATH:/usr/local/apache24/bin" > /etc/profile.d/httpd.sh source /etc/profile.d/httpd.sh
4、添加Apache的啟動配置文件
vim /usr/lib/systemd/system/httpd.service
[Unit] Description=The Apache HTTP Server After=network.target [Service] Type=forking ExecStart=/usr/local/apache24/bin/apachectl -k start ExecReload=/usr/local/apache24/bin/apachectl -k graceful ExecStop=/usr/local/apache24/bin/apachectl -k graceful-stop PIDFile=/usr/local/apache24/logs/httpd.pid PrivateTmp=false [Install] WantedBy=multi-user.target
因為添加或修改了啟動文件所以需要先載入一下,再進行啟動
systemctl daemon-reload && systemctl start httpd
# 查看一下Apache的80埠是否監聽了
# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::*
這裡修改一下監聽埠,修改為4433,因為80埠需要備案才可以從外網進行訪問
vim /usr/local/apache24/conf/httpd.conf 52 Listen 4433 202 ServerName localhost:4433 # ServerName不修改啟動時會有提醒,但是不影響啟動和訪問
重啟httpd服務
systemctl restart httpd
瀏覽器訪問,這裡使用命令行測試一下
二、安裝MySQL服務
1、安裝依賴插件庫文件
yum install -y ncurses-devel bison gnutls-devel cmake
2、準備MySQL數據存放目錄,創建mysql用戶
mkdir -p /data/mysql groupadd -r mysql useradd -r -g mysql -s /sbin/nologin mysql
3、運行以下命令更改數據目錄屬主和屬組
chown -R mysql:mysql /data/mysql
4、解壓軟體包,檢查編譯環境、編譯安裝
tar xvf mysql-5.6.24.tar.gz -C /usr/local/src/
cd /usr/local/src/mysql-5.6.24
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql56 \
-DMYSQL_DATADIR=/mnt/data \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SYSTEMD=1 \
-DINSTALL_SYSTEMD_UNITDIR=/usr/lib/systemd/system && make -j6 && make install
5、修改安裝目錄的屬主屬組為mysql
chown -R mysql:mysql /usr/local/mysql56/
6、初始化資料庫並複製配置文件
cd /usr/local/mysql56/ /usr/local/mysql56/scripts/mysql_install_db --user=mysql --datadir=/data/mysql mv /etc/my.cnf /etc/my.cnf.bak cp /usr/local/mysql56/support-files/my-default.cnf /etc/my.cnf
7、修改配置文件中的安裝路徑及數據目錄存放路徑
echo -e "basedir = /usr/local/mysql56\ndatadir = /data/mysql\n" >> /etc/my.cnf
8、修改MySQL的啟動配置文件
vim /usr/lib/systemd/system/mysql.service [Unit] Description=MySQL Community Server After=network.target After=syslog.target [Install] WantedBy=multi-user.target Alias=mysql.service [Service] User=mysql Group=mysql PermissionsStartOnly=true ExecStart=/usr/local/mysql56/bin/mysqld TimeoutSec=600 Restart=always PrivateTmp=false
9、設置MySQL的PATH環境變數
echo "export PATH=$PATH:/usr/local/mysql56/bin" > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.sh
10、啟動MySQL服務並設置開機自啟動
systemctl daemon-reload && systemctl enable mysql
systemctl start mysql
11、修改MySQL的root用戶密碼
mysqladmin -u root password
12、測試登錄MySQL資料庫
mysql -uroot -p
三、安裝PHP環境
1、安裝相關的依賴包
yum install -y libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel
2、下載php的軟體包
wget http://cn2.php.net/get/php-7.0.32.tar.bz2/from/this/mirror
重命名一下
cp mirror php-7.0.32.tar.bz2
解壓軟體包
tar xf php-7.0.32.tar.bz2 -C /usr/local/src/ && echo OK
3、編譯安裝php7.0.32
說明:若ECS實例規格記憶體較小,配置時可關閉不需要的PHP擴展,節省記憶體。例如,在./configure命令中添加--disable-fileinfo選項,關閉fileinfo擴展
cd /usr/local/src/php-7.0.32 ./configure --prefix=/usr/local/php7 \ --with-config-file-scan-dir=/etc/php.d \ --with-apxs2=/usr/local/httpd24/bin/apxs \ --with-config-file-path=/etc \ --with-pdo-mysql=mysqlnd \--enable-mbstring \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --with-openssl \ --enable-xml \ --enable-sockets \ --enable-fpm \ --with-bz2 && make -j6 && make install
拷貝php的配置文件
cp php.ini-production /etc/php.ini
4、修改apache的配置文件
① 找到ServerName參數,添加ServerName localhost:4433 (這裡web使用4433埠)
② 找到Directory參數,在Require all denied
前面添加#
,然後添加Require all granted
<Directory />
AllowOverride none
#Require all denied
Require all granted
</Directory>
③ 找到DirectoryIndex index.html
,將它替換為DirectoryIndex index.php index.html
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
④ 添加支持的類型
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
⑤添加一個php的測試頁
vim /usr/local/httpd24/htdocs/index.php <?php phpinfo(); ?>
5、重啟Apache服務,訪問php測試頁,IP:埠
要確保上面的測試頁可以訪問再繼續部署網站
Apache虛擬主機,搭建wordpress站點
1、修改Apache主配置文件
vim /usr/local/httpd24/conf/httpd.conf 找到虛擬主機,打開註釋即可,或者在目錄下新建虛擬主機的配置文件,然後在主配置文件中使用 Include 引用
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
2、編輯虛擬主機配置文件:
vim /usr/local/httpd24/conf/extra/httpd-vhosts.conf
<VirtualHost *:4433> ServerAdmin [email protected] DocumentRoot "/usr/local/httpd24/htdocs/wordpress" #ServerName www.wp.com ErrorLog "logs/wordpress-error_log" CustomLog "logs/wordpress-access_log" common </VirtualHost>
3、解壓wordpress論壇壓縮包到剛剛虛擬主機中定義的目錄下
cd /usr/local/httpd24/htdocs/ [root@Server1 htdocs]# tar xf /usr/local/src/wordpress-5.0.4-zh_CN.tar.gz
重啟服務,然後瀏覽器訪問IP或者功能變數名稱
這裡用的是4433埠所以訪問時要帶埠 x.x.x.x:4433
按照提示繼續安裝即可