從零開始 CentOs 7 搭建論壇BBS Discuz_X3.2


由於公司項目需要一個互動平台,可以發起活動,發消息留言,討論過后發現這竟然是一個論壇的功能。

於是就不打算耗費功夫開發相關功能,直接另外搭一套BBS算球。。。

 

一直覺得搭建BBS不是一件難事,目前有很多成熟的產品都支持直接建站,找了一些資料看了后發現還是需要很多知識和架構的,下面是詳細的搭建過程

重新安裝了一台CentOs 7虛擬機,安裝過程資料很多,大家去搜索下


      系統配置相關

系統版本:CentOS-7-x86_64-Minimal-1503-01.iso

主機名: BBS

IP: 10.10.10.14   這是虛擬機自動分配

防火牆: firewall 已經關閉

關閉 SELINUX

 

下面列出建站需要的服務支持

1. Apache 服務

2. Mysql 安裝

3. Php 安裝

4. 服務配置

5. Discuz! 安裝


 

服務安裝


1、安裝 Apache

a、使用 yum 搜索相關軟件

[root@BBS ~]# yum search httpd
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
======================================================== N/S matched: httpd ========================================================
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

 

b、進行 httpd 軟件安裝

     yum install httpd.x86_64

系統就會開始安裝,這時下面會列舉很多 httpd 服務的依賴,直接 y 同意安裝,這個安裝看網速,一般會很快

c、安裝成功后查看 httpd 狀態

[root@BBS ~]# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: inactive (dead)

    dead 說明服務沒有啟動,啟動這個服務:systemctl start httpd.service

[root@BBS ~]# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
   Active: active (running) since 四 2015-11-05 17:47:08 CST; 6s ago
 Main PID: 19288 (httpd)
   Status: "Processing requests..."

    Loaded-disabled不是隨機啟動狀態,這個需要修改:systemctl enable httpd.service

d、進行服務器相關配置,很多資料建議修改 Listen 端口為 8080,默認是 80,其實不需要修改,如果有修改配置需要重啟服務。此處默認端口配置。

     vi /etc/httpd/conf/httpd.conf

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

 

e、測試我們的服務器是否安裝完成,打開 IE,輸入本機 IP 加上端口號即可訪問服務器管理頁面 。

     本機是 10.10.10.14,所以我的地址為:http://10.10.10.14/

     image

   

如果想要地址欄顯示為網址形式的話,同樣可以修改配置文件的數據項 ServerName,我設置成公司縮寫luoan,保存重啟服務生效。

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName bbs.luoan.com:80

 

image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

這樣是不是更像那么回事了,哈哈,對了,上面網址要瀏覽器能解析的話需要另外配置DNS服務器或者修改本地hosts,詳細后續會將搭建DNS服務器篇發布出來。

OK,這下服務器就安裝完成了。

2、安裝 Mysql

進入系統搜索時才發現 CentOs 7 里面的庫已經不支持 mysql 安裝了,由於下載又要到官網很麻煩,就大概看了下庫里面存在哪種數據庫,經過查資料找到了一個叫 mariadb 的東西,據說是 mysql 原班人馬出來另立的數據庫,由於擔心sun 會將 mysql 閉源什么的,這都是好人啊

那就暫定用這個數據庫了

[root@bbs ~]# yum install MariaDB-server MariaDB-client
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
軟件包 1:mariadb-5.5.44-1.el7_1.x86_64 已安裝並且是最新版本
軟件包 1:mariadb-libs-5.5.44-1.el7_1.x86_64 已安裝並且是最新版本
 
         

等待他一直安裝完成后就可以啟動 mariadb 服務了。

[root@bbs ~]# systemctl start mariadb.service
[root@bbs ~]# systemctl enable mariadb.service

執行完這個命令下面就可以直接使用 mysql 命令了,跟 mysql 操作完全一樣,至於里面細節就不去管他了,也用不到。

[root@bbs ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

 

下面還要設置 mysql 的密碼權限,默認密碼為空,此處新密碼設置為 root

[root@bbs ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation:行379: find_mysql_client: 未找到命令

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

 

是不是so easy!!!

3、安裝 PHP

同樣的模式,先搜索一下看看存在哪些包

[root@bbs ~]# yum search php
已加載插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
========================================================= N/S matched: php =========================================================
graphviz-php.x86_64 : PHP extension for graphviz
php.x86_64 : PHP scripting language for creating dynamic web sites
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Enchant spelling extension for PHP applications
php-fpm.x86_64 : PHP FastCGI Process Manager
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pdo.x86_64 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pgsql.x86_64 : A PostgreSQL database module for PHP
php-process.x86_64 : Modules for PHP script using system process interfaces
php-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php-recode.x86_64 : A module for PHP applications for using the recode library
php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
rrdtool-php.x86_64 : PHP RRDtool bindings
uuid-php.x86_64 : PHP support for Universally Unique Identifier library
php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon

查看后面的一些注釋發現我們可能需要這幾個包,不要問我為什么知道這些報需要裝,因為知道,所以知道,這是男人的直覺 額

當然你可以選擇 yum –y php* 全部安裝,應該沒問題。

[root@bbs ~]# yum -y install php php-bcmath php-cli php-common php-gd php-ldap php-mbstring php-mysql php-mysqlnd php-pear php-pdo php-xml php-xmlrpc

執行命令發現有沖突發現確實引用了兩個連接數據庫的包那就去掉一個。因為官方建議用后面一個包 mysqlnd。

[root@bbs ~]# yum -y install php php-bcmath php-cli php-common php-gd php-ldap php-mbstring php-mysqlnd php-pear php-pdo php-xml php-xmlrpc

OK 安裝完成。

 

#重啟MariaDB:systemctl restart mariadb.service

#重啟apache:systemctl restart httpd.service

4、服務配置

a、編輯 Apache 服務器的配置文件

[root@bbs ~]# vi /etc/httpd/conf/httpd.conf

修改下面這些屬性

#修改允許.htaccess
AllowOverride All 
# 修改頁面支持屬性
DirectoryIndex index.html index.htm Default.html Default.htm index.php
# 新增支持 . pl 腳本
AddHandler cgi-script .cgi .pl

systemctl restart httpd.service #重啟apache

 

b、配置 php

[root@bbs ~]# vi /etc/php.ini

修改下面參數:

# 改為 date.timezone = PRC
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = RPC

# 新增禁用的函數,需要使用時再放開
; This directive allows you to disable certain functions for security reasons.
; It receives a comma-delimited list of function names. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
; http://php.net/disable-functions
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

# 支持php短標簽
; short_open_tag
;   Default Value: On
;   Development Value: Off
;   Production Value: Off
short_open_tag = On

# 設置表示允許訪問當前目錄(即PHP腳本文件所在之目錄)和/tmp/目錄,可以防止php木馬跨站,如果改了之后安裝程序有問題(例如:織夢內容管理系統),可以注銷此行,或者直接寫上程序的目錄/data/www.osyunwei.com/:/tmp/
open_basedir = .:/tmp/

#重啟MariaDB:systemctl restart mariadb.service

#重啟apache:systemctl restart httpd.service

c、進行php頁面測試

[root@bbs html]# cd /var/www/html
[root@bbs html]# vi index.php

里面的內容很簡單,但是我看到別人的教程還是寫錯了,我也被坑了,出了個空白頁面  -  -

<?php
phpinfo();
?>

 

在客戶端瀏覽器輸入服務器IP地址,可以看到如下圖所示相關的配置信息

image

5、安裝 discuz

a、這個程序系統沒有集成,需要自己下載,去官方論壇上找了個discuz3.2x的中文簡體版下載地址

產品介紹
Discuz! X3.2 在繼承和完善 Discuz! X3.1 的基礎上,針對社區移動端進行了新的嘗試。推出微信登錄、微社區等功能。安全穩定的程序為站長提供更加可靠的保障。
下載地址
簡體中文GBK
http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
繁體中文 BIG5
http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_TC_BIG5.zip
簡體 UTF8
http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
繁體 UTF8
http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_TC_UTF8.zip

 

下面我們就直接使用 wget 下載下來安裝,如果沒有這個命令,使用 yum 安裝就行了,我下載的是GBK的包,如果出現亂碼請下載UTF8的。

[root@bbs download]# yum -y install wget
[root@bbs download]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
--2015-11-06 17:45:41--  http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip
正在解析主機 download.comsenz.com (download.comsenz.com)... 101.227.130.115
正在連接 download.comsenz.com (download.comsenz.com)|101.227.130.115|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:12402802 (12M) [application/zip]
正在保存至: “Discuz_X3.2_SC_GBK.zip”

100%[==========================================================================================>] 12,402,802  7.74MB/s 用時 1.5s   

2015-11-06 17:45:43 (7.74 MB/s) - 已保存 “Discuz_X3.2_SC_GBK.zip” [12402802/12402802])

OK 下載完成。

直接解壓文件,由於是個zip包 ,坑爹 linux 肯定沒工具解,直接安裝 yum -y install unzip

[root@bbs download]# unzip Discuz_X3.2_SC_GBK.zip
[root@bbs download]# ls -l
總用量 12120
-rw-r--r--.  1 root root 12402802 6月   9 10:58 Discuz_X3.2_SC_GBK.zip
drwxr-xr-x.  2 root root       97 6月   9 10:21 readme
drwxr-xr-x. 12 root root     4096 6月   9 10:21 upload
drwxr-xr-x.  4 root root       68 6月   9 10:21 utility

OK,解壓成功,出來了3個目錄。

 

b、將 upload 目錄轉移到web請求目錄下

[root@bbs download]# cp -R ./upload /var/www/html

c、進去upload給予幾個目錄權限訪問

[root@bbs download]# chown apache:apache -R ./upload 
[root@bbs upload]# chmod -R 777 config
[root@bbs upload]# chmod -R 777 data
[root@bbs upload]# chmod -R 777 uc_client
[root@bbs upload]# chmod -R 777 uc_server

d、打開瀏覽器開始安裝論壇,這一步網上都是說什么站點的根目錄,然后域名加上 install 就可以訪問了,我根本沒有站點,所以嘗試了很久未知所以然,找不到入口該是多蛋疼,蛋碎了

image

又去查看資料具體入口跳轉的php頁面,發現是 forum.php,這下簡單了,在upload 目錄下有這個頁面。直接訪問果然出來。看瀏覽器的解析結果分析,如果自己在根目錄下的一層文件夾需要添加在路徑上。

http://10.10.10.14/upload/forum.php

image

e、開始安裝論壇,點擊“我同意”后,進去系統檢測頁面。如果一切提示OK,就繼續下一步,如果提示有錯誤,就先去解決,一般都是上面第【c】步讓你給文件權限的問題,既然上面都執行了 這里一般不會報錯。一直下一步,下一步設置管理員密碼,就成功安裝了。

image

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM