centos7利用LAMP实现Discuz的搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7利用LAMP实现Discuz的搭建相关的知识,希望对你有一定的参考价值。
一、准备工作
准备一台centos7.4的系统
关闭防火墙和selinux
[[email protected] ~]# systemctl stop firewalld.service [[email protected] ~]# systemctl disable firewalld.service [[email protected] ~]# vim /etc/selinux/config SELINUX=disabled [[email protected] ~]# systemctl reboot
二、准备搭建Discuz所需要的软件包,这是使用的是编译安装所有软件
需要的软件有: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.bz2、apr-util-1.6.0.tar.gz 、httpd-2.4.29.tar.bz2、php-5.6.36.tar.xz
三、编译安装httpd2.4
这里是编译安装httpd,而httpd需要由apr,这里将centos7自带的apr和apr-util卸载
[[email protected] ~]# 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解压缩
[[email protected] ~]# 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-util
[[email protected] ~]# mv apr-1.6.2 httpd-2.4.29/srclib/apr [[email protected] ~]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
4.在编译安装之前需要安装几个软件包,不然在编译过程中会报错
[[email protected] httpd-2.4.29]# yum -y groupinstall "Development Tools" [[email protected] httpd-2.4.29]# yum -y install pcre-devel openssl-devel expat-devel
5.开始编译安装
[[email protected] ~]# cd httpd-2.4.29/ [[email protected] 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 [[email protected] httpd-2.4.29]# make -j 4 #这里根据cpu的数量自己定义 [[email protected] httpd-2.4.29]# make install
6.创建apache用户
[[email protected] httpd-2.4.29]# useradd -r -m -d /var/www -s /sbin/nologin apache [[email protected] httpd-2.4.29]# mkdir /var/www/html
7.为了方便这里添加PATH变量
[[email protected] bin]# vim /etc/profile.d/test.sh export PATH=/app/httpd24/bin:$PATH [[email protected] bin]# source /etc/profile.d/test.sh
8.将编译好的httpd服务添加到归systemd管理
[[email protected] ~]# 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 [[email protected] ~]# systemctl daemon-reload #更新systemd [[email protected] ~]# 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> [[email protected] ~]# systemctl restart httpd.service
10.测试httpd2.4
[[email protected] ~]# vim /var/www/html/index.html <h1>test html index.html</h1>
四、编译安装mariadb数据库
1.解压缩,由于编译mariadb时间太长,这里是从mariadb官方网站上下载已经编译好的包,所以解压缩时需要解压缩到/usr/local/目录下并且需要叫mysql
[[email protected] ~]# tar xf mariadb-5.5.60-linux-x86_64.tar.gz -C /usr/local/ [[email protected] ~]# cd /usr/local/ [[email protected] local]# ln -s mariadb-5.5.60-linux-x86_64/ mysql
2.创建用户
[[email protected] local]# useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql
3.设置配置文件
[[email protected] mysql]# cd /usr/local/mysql/ [[email protected] mysql]# mkdir /etc/mysql [[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf [[email protected] mysql]# vim /etc/mysql/my.cnf [mysqld] datadir = /app/mysqldb #指定数据库文件存放位置 innodb_file_per_table = on #指定每一个表是一个文件 skip_name_resolve = on #不进行反解析
4.安装数据库
[[email protected] mysql]# scripts/mysql_install_db --datadir=/app/mysql --user=mysql
5.设置PATH变量
[[email protected] bin]# vim /etc/profile.d/test.sh export PATH=/usr/local/mysql/bin:/app/httpd24/bin:$PATH [[email protected] bin]# source /etc/profile.d/test.sh
6.拷贝启动脚本,让服务可以使用systemctl管理
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig mysqld on
7.mariadb5版本要想让mysql用户在/var/log/目录下写日志需要单独给权限
[[email protected] mysql]# mkdir /var/log/mariadb [[email protected] mysql]# setfacl -m u:mysql:rwx /var/log/ [[email protected] mysql]# setfacl -m u:mysql:rwx /var/log/mariadb
8.重启服务
[[email protected] log]# systemctl restart mysqld.service
9.创建初始化数据库
[[email protected] 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.创建对应的数据库和授权用户
[[email protected] log]# mysql -uroot -pcentos MariaDB [(none)]> create database luntan; MariaDB [(none)]> grant all on luntan.* to [email protected]"%" identified by "centos";
五.编译安装php,若使用php5版本,则需要mariadb,使用10版本的mariadb不兼容
1.解压缩
[[email protected] ~]# tar xf php-5.6.36.tar.xz
2.安装编译安装所需要的软件包,这里需要epel源
[[email protected] php-5.6.36]# yum -y install libxml2-devel bzip2-devel libmcrypt-devel
3.编译安装
[[email protected] 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 [[email protected] php-5.6.36]# make -j 4 [[email protected] php-5.6.36]# make install
4.复制配置文件
[[email protected] php-5.6.36]# cp php.ini-production /etc/php.ini
5.编辑httpd服务的配置文件
[[email protected] 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数据库连通性
[[email protected] html]# vim index.php <?php $conn = mysql_connect('127.0.0.1','luntanuser','centos'); if ($conn) echo "OK"; else echo "Failure"; mysql_close(); ?> [[email protected] html]# systemctl restart httpd.service
六、安装Discuz
[[email protected] ~]# unzip Discuz_X3.4_GIT_SC_UTF8.zip [[email protected] ~]# mv dir_SC_UTF8/ /var/www/html/ [[email protected] upload]# ln -s dir_SC_UTF8/ lt [[email protected] ~]# cd /var/www/html/dir_SC_UTF8/upload/config/ [[email protected] config]# cp config_global_default.php config_global.php [[email protected] config]# cp config_ucenter_default.php config_ucenter.php [[email protected] html]# setfacl -Rm u:apache:rwx dir_SC_UTF8/
在网页上输入http://192.168.86.7/lt/upload/install/
以上是关于centos7利用LAMP实现Discuz的搭建的主要内容,如果未能解决你的问题,请参考以下文章
centos7.3 编译安装lamp,利用wordpress实现个人博客搭建