Set up Discuz under CentOS! Forum

Source: Internet
Author: User

Set up Discuz under CentOS! Forum

Previously, I introduced how to set up LAMPhttp: // www.centoscn.com/CentosServer/www/2015/0831/6090.html.

After LAMP is set up, the webpage can be parsed normally. Now we will build a Discuz! Forum.

1. Install Discuz!

1. Create a directory to store webpages.

[Root @ tpp ~] # Mkdir/data/www [root @ tpp ~] # Cd/data/www [root @ tpp www] # wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_ SC _GBK.zip // download the latest Discuz! [Root @ tpp www] # unzip Discuz_X3.2_ SC _GBK.zip // decompress [root @ tpp www] # lsDiscuz_X3.2_ SC _GBK.zip readme upload utility

2. program files are stored in the upload directory, so all the files are moved to the www directory and redundant files are deleted.

[root@tpp www]# mv upload/* ./    [root@tpp www]# lsadmin.php connect.php       favicon.ico install   readme  template utilityapi    cp.php         forum.php  member.php robots.txt uc_clientapi.php  crossdomain.xml     group.php  misc.php  search.php uc_serverarchiver  data          home.php   plugin.php source   uploadconfig   Discuz_X3.2_SC_GBK.zip index.php  portal.php static   userapp.php[root@tpp www]# rm -rf readme/ utility/ upload/ Discuz_X3.2_SC_GBK.zip  

3. configure a VM

[Root @ tpp www] # vim/usr/local/apache2/conf/httpd. conf # Include conf/extra/httpd-vhosts.conf // find and open this VM configuration file as follows: Include conf/extra/httpd-vhosts.conf
[Root @ tpp www] # vim/usr/local/apache2/conf/extra/httpd-vhosts.conf // edit the VM configuration file, there are two template cases at the end of the file, delete one and modify the other to: <VirtualHost *: 80> # ServerAdmin webmaster@dummy-host.example.com // administrator mailbox, we can remove DocumentRoot "/data/www" // change to the previously created directory ServerName www.tpp.com // set the domain name ServerAlias www.ppt.com // you can set multiple domain names # ErrorLog "logs/dummy-host.example.com-error_log "/ /error log # CustomLog "logs/dummy-host.example.com-access_log" common // access log </VirtualHost>

Next, open port 80.

[Root @ tpp www] # vim/usr/local/apache2/conf/httpd. conf <Directory/> Options FollowSymLinks AllowOverride None Order deny, allow Deny from all </Directory> changed to: <Directory/> Options FollowSymLinks AllowOverride all Order deny, allow Allow from all </Directory>

Save and exit, check whether the configuration is correct, and restart

[root@tpp www]# /usr/local/apache2/bin/apachectl -tSyntax OK[root@tpp www]# /usr/local/apache2/bin/apachectl restart

4. Configure the hosts file

Find the hosts file under the local C: \ Windows \ System32 \ drivers \ etc, add the following content, save and exit.

192.168.0.104 www.tpp.com www.ppt.com www.ppt1.com

5. Enter www.tpp.com in the browser. This will jump to Discuz! Installation interface.

After agreeing to the installation, we can see that many of them are not writable, so we need to grant them permissions.

First, check the identity of the Apache process.

[root@tpp www]# ps aux |grep httpdaemon  4566 0.0 1.0 30140 11028 ?    S  04:42  0:00 /usr/local/apache2/bin/httpd -k startdaemon  4567 0.0 0.9 28724 9480 ?    S  04:42  0:00 

We can see that it is a daemon. Next we will grant all files with no permissions to the daemon group.

[root@tpp www]# chown -R daemon config data uc_client/data uc_server/data

After the page is refreshed, all the pages become green. The next step is completely new installation.

6. Configure the database.

[Root @ tpp www] #/usr/local/mysql/bin/mysqlmysql> create database discuz; // create a database named discuzmysql> grant all on discuz. * to 'tpp '@ 'localhost' identified by 'tpplinux'; // all permissions, user tpp, password tpplinux

7. Then we go back to the original page

Enter the Database Name: discuz, Database User name: tpp, Database Password: tpplinux, other default; Administrator admin password 123456, next step; after the installation is complete, click "your forum has been installed. Click here to access" in the bottom right corner ".

Ii. Configure Apache

1. Configure user authentication for a virtual host

Requirement: the user needs to authenticate the 123.txt file in the/data/www/abcdirectory.

[root@tpp www]# mkdir abc[root@tpp www]# cd abc[root@tpp abc]# cp /etc/passwd 123.txt[root@tpp abc]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

Add

<Directory/data/www/abc> AllowOverride AuthConfig AuthName "Custom" AuthType Basic AuthUserFile/data /. htpasswd # Here/data /. htpasswd can be used to write a path or name without restrictions (this Chinese sentence is only used for annotation, do not add it, or an error will be reported) require valid-user </Directory>

Save and create an apache user

[root@tpp abc]# /usr/local/apache2/bin/htpasswd -c /data/.htpasswd tpp

The-c parameter is used to create the user tpp for the first time. If you add a user for the first time, the-c parameter is not used, because-c Indicates creation. if you add the parameter, the file will be overwritten.

[root@tpp abc]# /usr/local/apache2/bin/apachectl -tSyntax OK[root@tpp abc]# /usr/local/apache2/bin/apachectl restart

Next we will visit www.tpp.com/abc/123.txtfor example:

Garbled characters are related to character sets. The configuration file is "Custom" and can be written in English.

2. Configure Domain Name Redirection

Requirement: Forward the domain name www.ppt.com(or www.ppt 1.com) to www.tpp.com.
Implementation:

[Root @ tppabc] # Add the following content to vim/usr/local/apache2/conf/extra/httpd-vhosts.conf // VM

<IfModule mod_rewrite.c>  RewriteEngine on  RewriteCond %{HTTP_HOST} ^www.ppt.com$  RewriteRule ^(.*)$ http://www.tpp.com/$1 [R=301,L]</IfModule>

If multiple domain names are redirected to one domain name

<IfModule mod_rewrite.c>  RewriteEngine on  RewriteCond %{HTTP_HOST} ^www.ppt.com [OR]  RewriteCond %{HTTP_HOST} ^www.ppt1.com$  RewriteRule ^/(.*)$ http://www.tpp.com/$1 [R=301,L]</IfModule>

As shown in:

Then re-detect and load Apache

[Root @ tpp htdocs] #/usr/local/apache2/bin/apachectl-t

Syntax OK

[Root @ tpp htdocs] #/usr/local/apache2/bin/apachectl graceful

Next we will automatically jump to www.tpp.com when the browser inputs www.ppt.comw.www.ppt 1.com.

3. Configure apache access logs and separate them by one day.

[root@tpp~]#vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Change to the error log and access log named by date

ErrorLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/tpp.com-error_%Y%m%d.log 86400"  SetEnvIf Request_URI ".*\.gif$" image-request  SetEnvIf Request_URI ".*\.jpg$" image-request  SetEnvIf Request_URI ".*\.png$" image-request  SetEnvIf Request_URI ".*\.bmp$" image-request  SetEnvIf Request_URI ".*\.swf$" image-request  SetEnvIf Request_URI ".*\.js$" image-request  SetEnvIf Request_URI ".*\.css$" image-requestCustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/tpp.com-access_%Y%m%d.log 86400" combined env=!image-request

For example:

The commands are all absolute paths, rotatelogs is the splitting tool, % Y % m % d time is the unit of separation, 86400 seconds is one day. SetEnvIf is customized. env can be called for the following access logs, that is, files ending with gif jpg are not recorded.

Next, we will test and load Apache again.

[Root @ tpp logs] #/usr/local/apache2/bin/apachectl-t

Syntax OK

[Root @ tpp logs] #/usr/local/apache2/bin/apachectl graceful

Then, refresh the page and you will see a log generated, such:

4. Configure static cache in Apache

Set the static files on the web page as cache, and do not need to be called after the files are cached, saving bandwidth.

[Root @ tpp www] # vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

Next, define a module under the previous log file definition.

<IfModulemod_expires.c>

ExpiresActiveon

ExpiresByTypeimage/gif "accessplus1days"

ExpiresByTypeimage/jpeg "accessplus24hours"

ExpiresByTypeimage/png "accessplus24hours"

ExpiresByTypetext/css "nowplus2 hours"

ExpiresByTypeapplication/x-javascript "nowplus2hours" ExpiresByTypeapplication/javascript "nowplus2hours"

ExpiresByTypeapplication/x-shockwave-flash "nowplus2hours"

ExpiresDefault "nowplus0min"

</IfModule>

As shown in:

Next, we will test and load Apache again.

[Root @ tpp www] #/usr/local/apache2/bin/apachectl-t

Syntax OK

[Root @ tpp www] #/usr/local/apache2/bin/apachectl graceful

Next, we will test whether the file is successful. Create two files in the/data/www/directory: 1.txt 1.jpg. txt is not the static file defined above.

[Root @ tpp www] # touch 1.txt 1.jpg

[Root @ tpp www] # curl-x127.0.0.1: 80 www.tpp.com/1.txt-I

[Root @ tpp www] # curl-x127.0.0.1: 80 www.tpp.com/1.jpg-I

5. configure anti-theft links in Apache

[Root @ tpp www] # vim/usr/local/apache2/conf/extra/httpd-vhosts.conf // Add the following modules

SetEnvIfNoCaseReferer "^ http://www.tpp.com" local_ref

SetEnvIfNoCaseReferer "www.guhantai.cn" local_ref

SetEnvIfNoCaseReferer "^ $" local_ref

<Filesmatch "\. (txt | doc | mp3 | zip | rar | jpg | gif | png)">

OrderAllow, Deny

Allowfromenv = local_ref

</Filesmatch>

As shown in (Be sure to pay attention to spaces, or an error will be reported ):


Our txt | doc | mp3 | zip | rar | jpg | gif | png files cannot be referenced by other websites as network links.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.