1、準備工做php
準備一臺centos7.4的系統html
關閉防火牆和selinuxmysql
[root@centos7 ~]# systemctl stop firewalld.service [root@centos7 ~]# systemctl disable firewalld.service [root@centos7 ~]# vim /etc/selinux/config SELINUX=disabled [root@centos7 ~]# systemctl reboot
2、準備搭建Discuz所須要的軟件包,這是使用的是編譯安裝全部軟件linux
須要的軟件有:apr-1.6.2.tar.gz、Discuz_X3.4_GIT_SC_UTF8.zip、mariadb-5.5.60-linux-x86_64.tar.gz 、xcache-3.2.0.tar.bz二、apr-util-1.6.0.tar.gz 、httpd-2.4.29.tar.bz二、php-5.6.36.tar.xzsql
3、編譯安裝httpd2.4數據庫
這裏是編譯安裝httpd,而httpd須要由apr,這裏將centos7自帶的apr和apr-util卸載apache
[root@centos7 ~]# yum remove -y apr.x86_64 apr-util.x86_64
2.將apr-1.6.2.tar.gz、apr-util-1.6.0.tar.gz 、httpd-2.4.29.tar.bz2解壓縮vim
[root@centos7 ~]# tar xf apr-1.6.2.tar.gz ;tar xf apr-util-1.6.0.tar.gz ;tar xf httpd-2.4.29.tar.bz2
3.將apr-1.6.2.tar.gz、apr-util-1.6.0.tar.gz移動到httpd-2.4.29/srclib目錄下,並將名字改成apr和apr-utilcentos
[root@centos7 ~]# mv apr-1.6.2 httpd-2.4.29/srclib/apr [root@centos7 ~]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
4.在編譯安裝以前須要安裝幾個軟件包,否則在編譯過程當中會報錯bash
[root@centos7 httpd-2.4.29]# yum -y groupinstall "Development Tools" [root@centos7 httpd-2.4.29]# yum -y install pcre-devel openssl-devel expat-devel
5.開始編譯安裝
[root@centos7 ~]# cd httpd-2.4.29/ [root@localhost httpd-2.4.29]# ./configure --prefix=/app/httpd24 --sysconfdir=/etc/httpd24/conf --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork [root@centos7 httpd-2.4.29]# make -j 4 #這裏根據cpu的數量本身定義 [root@centos7 httpd-2.4.29]# make install
6.建立apache用戶
[root@centos7 httpd-2.4.29]# useradd -r -m -d /var/www -s /sbin/nologin apache [root@centos7 httpd-2.4.29]# mkdir /var/www/html
7.爲了方便這裏添加PATH變量
[root@centos7 bin]# vim /etc/profile.d/test.sh export PATH=/app/httpd24/bin:$PATH [root@centos7 bin]# source /etc/profile.d/test.sh
8.將編譯好的httpd服務添加到歸systemd管理
[root@centos7 ~]# vim /usr/lib/systemd/system/httpd.service [Unit] Description=The Apache HTTP Server After=network.target Documentation=man:httpd(8) Documentation=man:apachectl(8) [Service] Type=forking ExecStart=/app/httpd24/bin/apachectl start ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful ExecStop=/bin/kill -WINCH ${MAINPID} KillSignal=SIGCONT PrivateTmp=true [Install] WantedBy=multi-user.target [root@centos7 ~]# systemctl daemon-reload #更新systemd [root@centos7 ~]# systemctl restart httpd.service
9.簡單修改配置文件
User apache Group apache ServerName www.test.com:80 DocumentRoot "/var/www/html" #這裏爲了使用上和rpm包安裝沒有區別,因此也放入該目錄下 <Directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> [root@centos7 ~]# systemctl restart httpd.service
10.測試httpd2.4
[root@centos7 ~]# vim /var/www/html/index.html <h1>test html index.html</h1>
4、編譯安裝mariadb數據庫
1.解壓縮,因爲編譯mariadb時間太長,這裏是從mariadb官方網站上下載已經編譯好的包,因此解壓縮時須要解壓縮到/usr/local/目錄下而且須要叫mysql
[root@centos7 ~]# tar xf mariadb-5.5.60-linux-x86_64.tar.gz -C /usr/local/ [root@centos7 ~]# cd /usr/local/ [root@centos7 local]# ln -s mariadb-5.5.60-linux-x86_64/ mysql
2.建立用戶
[root@centos7 local]# useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
3.設置配置文件
[root@centos7 mysql]# cd /usr/local/mysql/ [root@centos7 mysql]# mkdir /etc/mysql [root@centos7 mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf [root@centos7 mysql]# vim /etc/mysql/my.cnf [mysqld] datadir = /app/mysqldb #指定數據庫文件存放位置 innodb_file_per_table = on #指定每個表是一個文件 skip_name_resolve = on #不進行反解析
4.安裝數據庫
[root@centos7 mysql]# scripts/mysql_install_db --datadir=/app/mysql --user=mysql
5.設置PATH變量
[root@centos7 bin]# vim /etc/profile.d/test.sh export PATH=/usr/local/mysql/bin:/app/httpd24/bin:$PATH [root@centos7 bin]# source /etc/profile.d/test.sh
6.拷貝啓動腳本,讓服務可使用systemctl管理
[root@centos7 mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@centos7 mysql]# chkconfig --add mysqld [root@centos7 mysql]# chkconfig mysqld on
7.mariadb5版本要想讓mysql用戶在/var/log/目錄下寫日誌須要單獨給權限
[root@centos7 mysql]# mkdir /var/log/mariadb [root@centos7 mysql]# setfacl -m u:mysql:rwx /var/log/ [root@centos7 mysql]# setfacl -m u:mysql:rwx /var/log/mariadb
8.重啓服務
[root@centos7 log]# systemctl restart mysqld.service
9.建立初始化數據庫
[root@centos7 log]# mysql_secure_installation /usr/local/mysql/bin/mysql_secure_installation: line 393: find_mysql_client: command not found 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!
10.建立對應的數據庫和受權用戶
[root@centos7 log]# mysql -uroot -pcentos MariaDB [(none)]> create database luntan; MariaDB [(none)]> grant all on luntan.* to luntanuser@"%" identified by "centos";
五.編譯安裝php,若使用php5版本,則須要mariadb,使用10版本的mariadb不兼容
1.解壓縮
[root@centos7 ~]# tar xf php-5.6.36.tar.xz
2.安裝編譯安裝所須要的軟件包,這裏須要epel源
[root@centos7 php-5.6.36]# yum -y install libxml2-devel bzip2-devel libmcrypt-devel
3.編譯安裝
[root@centos7 php-5.6.36]# ./configure --prefix=/app/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php.d --with-bz22 [root@centos7 php-5.6.36]# make -j 4 [root@centos7 php-5.6.36]# make install
4.複製配置文件
[root@centos7 php-5.6.36]# cp php.ini-production /etc/php.ini
5.編輯httpd服務的配置文件
[root@centos7 php-5.6.36]# vim /etc/httpd24/conf/httpd.conf <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> AddType application/x-httpd-php .php AddType application/x-httpd-php-soure .phps
6.測試php與mysql數據庫連通性
[root@centos7 html]# vim index.php <?php $conn = mysql_connect('127.0.0.1','luntanuser','centos'); if ($conn) echo "OK"; else echo "Failure"; mysql_close(); ?> [root@centos7 html]# systemctl restart httpd.service
6、安裝Discuz
[root@centos7 ~]# unzip Discuz_X3.4_GIT_SC_UTF8.zip [root@centos7 ~]# mv dir_SC_UTF8/ /var/www/html/ [root@centos7 upload]# ln -s dir_SC_UTF8/ lt [root@centos7 ~]# cd /var/www/html/dir_SC_UTF8/upload/config/ [root@centos7 config]# cp config_global_default.php config_global.php [root@centos7 config]# cp config_ucenter_default.php config_ucenter.php [root@centos7 html]# setfacl -Rm u:apache:rwx dir_SC_UTF8/
在網頁上輸入http://192.168.86.7/lt/upload/install/