千家信息网

CentOS 7 源码编译安装LAMP架构,搭建Discuz论坛(详细过程解析)

发表于:2026-11-04 作者:千家信息网编辑
千家信息网最后更新 2026年11月04日,LAMP平台概述什么是LAMP目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境。构成组件Linux、Apache、 MySQL、 PHP/Per/PythonLAMP的优势成本低
千家信息网最后更新 2026年11月04日CentOS 7 源码编译安装LAMP架构,搭建Discuz论坛(详细过程解析)

LAMP平台概述

什么是LAMP

目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境。

构成组件

Linux、Apache、 MySQL、 PHP/Per/Python

LAMP的优势

成本低廉
可定制、易于开发
方便易用、安全和稳定

LAMP源码编译安装实例

一、安装Apache服务器

(1)通过Samba服务,从我的宿主机将整个LAMP部署所需的压缩包,挂载到"/mnt/"目录下。

smbclient -L //192.168.100.50/   //查看共享的文件mount.cifs //192.168.100.50/LAMP-C7 /mnt/   //挂载我们所需要的文件

(2)将安装Apache需要的用到的压缩包解压到"/opt/"目录下。

[root@localhost mnt]# tar zxvf apr-1.6.2.tar.gz -C /opt/   //跨平台所需组件包.......                  //省略过程[root@localhost mnt]# tar zxvf apr-util-1.6.0.tar.gz -C /opt/   //跨平台所需组件包.......                  //省略过程[root@localhost mnt]# tar jxvf httpd-2.4.29.tar.bz2 -C /opt/   //服务包.......                  //省略过程

(3)将两个组件包的目录文件移动到httpd文件目录下面,并分别重命名为apr、apr-util

[root@localhost mnt]# cd ../opt/[root@localhost opt]# lsapr-1.6.2  apr-util-1.6.0  httpd-2.4.29  rh[root@localhost opt]# mv apr-1.6.2/ httpd-2.4.29/srclib/apr[root@localhost opt]# lsapr-util-1.6.0  httpd-2.4.29  rh[root@localhost opt]# mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util[root@localhost opt]# lshttpd-2.4.29  rh[root@localhost opt]# 

(4)安装编译Apache服务以及服务所需的相关工具。

[root@localhost opt]# yum -y install \> gcc \> gcc-c++ \> make \> pcre-devel \> expat-devel \> perl.......                  //省略过程

(5)进入到"/opt/httpd-2.4.29/"目录下,进行对Apache服务器的配置。

[root@localhost opt]# lshttpd-2.4.29  rh[root@localhost opt]# cd httpd-2.4.29/[root@localhost httpd-2.4.29]# lsABOUT_APACHE     BuildBin.dsp    emacs-style     LAYOUT        NOTICE            srclibacinclude.m4     buildconf       httpd.dep       libhttpd.dep  NWGNUmakefile     supportApache-apr2.dsw  CHANGES         httpd.dsp       libhttpd.dsp  os                testApache.dsw       CMakeLists.txt  httpd.mak       libhttpd.mak  README            VERSIONINGapache_probes.d  config.layout   httpd.spec      LICENSE       README.cmakeap.d             configure       include         Makefile.in   README.platformsbuild            configure.in    INSTALL         Makefile.win  ROADMAPBuildAll.dsp     docs            InstallBin.dsp  modules       server[root@localhost httpd-2.4.29]# ./configure \> --prefix=/usr/local/httpd \                       //安装路径> --enable-so \                                          //启用动态加载模块支持> --enable-rewrite \                                 //启用网页地址重写功能> --enable-charset-lite \                         //启用字符集支持> --enable-cgi                                         //启用CGI脚本程序支持.......                  //省略过程

(6)编译安装Apache服务。

[root@localhost httpd-2.4.29]# make && make install.......                  //省略过程(编译时间较长耐心等待)#make进行编译,将源代码转换为可执行程序。make  install 进行安装。

(7)将"/usr/local/httpd/bin/"目录下的"apachectl"文件移动到"/etc/init.d/"目录下,并在文件开头添加chkconfig识别配置,然后将其添加为标准的Linux系统服务。

[root@localhost httpd-2.4.29]#ls /usr/local/httpd/bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd[root@localhost httpd-2.4.29]# ls /etc/init.d/functions  httpd  netconsole  network  README[root@localhost httpd-2.4.29]# #/usr/local/httpd/目录下的,主要子目录的用途:#/usr/local/httpd/bin                 //存放各种执行程序文件#/usr/local/httpd/conf              //存放各种配置文件#/usr/local/httpd/htdocs         //存放网页文档#/usr/local/httpd/logs             //存放日志文件#/usr/local/httpd/modules     //存放各种模块文件#/usr/local/httpd/cgi-bin        //存放各种CGI程序文件[root@localhost httpd-2.4.29]# vim /etc/init.d/httpd #!/bin/sh# chkconfig: 35 85 21   //服务识别参数,在级别3、5中启动:启动和关闭的顺序分别为85、21# description: Apache is a World Wide Web server   //服务描述信息## Licensed to the Apache Software Foundation (ASF) under one or more..........                        //省略部分内容[root@localhost httpd-2.4.29]# chkconfig --add httpd              //将httpd服务添加为系统服务[root@localhost httpd-2.4.29]#

(8)编辑httpd服务的主配置文件,配置网站名称,这里以为"www.yun.com:80"为例。将监听地址改为网站服务器的IP地址"192.168.52.132:80",端口为80,我这里直接监听当前主机的IP地址。将监听ipv6IP地址的命令行注释掉。

[root@localhost httpd-2.4.29]# vim /usr/local/httpd/conf/httpd.conf ServerName www.yun.com:80         //配置网站名称Listen 192.168.52.132:80                 //配置IPv4监听地址#Listen 80


(9)优化配置文件与执行路径,在系统默认的配置文件目录"/etc/下"建立httpd服务配置文件的软链接,同时在系统识别的环境变量目录"/usr/local/bin/"下,建立httpd服务执行程序的软链接。

[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/[root@localhost httpd-2.4.29]#

(10)对服务的命令对配置内容进行语法检查,用"httpd -t"或"apachectl -t"都可以,"Syntax OK"表示没有语法错误,没有错误我们直接开启服务,然后检查能否监听TCP的80端口。最后关闭防火墙和增强性安全功能。

[root@localhost httpd-2.4.29]# httpd -tSyntax OK[root@localhost httpd-2.4.29]# apachectl -tSyntax OK[root@localhost httpd-2.4.29]# service httpd start    //开启服务[root@localhost httpd-2.4.29]# netstat -ntap | grep 80   //检查能否监听TCP的80端口tcp        0      0 192.168.52.132:80       0.0.0.0:*               LISTEN      34935/httpd         [root@localhost httpd-2.4.29]# systemctl stop firewalld.service    //关闭防火墙[root@localhost httpd-2.4.29]# setenforce 0   //关闭增强性安全功能[root@localhost httpd-2.4.29]# 

(11)用我们的宿主机去访问搭建好的http服务。

二、安装MySQL服务

(1)安装编译MySQL服务以及服务所需的相关工具。

[root@localhost httpd-2.4.29]# yum install -y ncurses-devel autoconf cmake.......                  //省略过程

(2)将MySQL服务的源码包解压到"/opt/"目录下。

[root@localhost mnt]#cd /mnt/[root@localhost mnt]# tar zxvf mysql-5.6.26.tar.gz -C /opt/.......                  //省略过程

(3)进入"opt/mysql-5.6.26/",对服务进行配置。

[root@localhost mnt]# cd /opt/mysql-5.6.26/[root@localhost mysql-5.6.26]# lsBUILD           config.h.cmake       extra               libmysqld    packaging  sql-bench      unittestBUILD-CMAKE     configure.cmake      include             libservices  plugin     sql-common     VERSIONclient          COPYING              INSTALL-SOURCE      man          README     storage        viocmake           dbug                 INSTALL-WIN-SOURCE  mysql-test   regex      strings        winCMakeLists.txt  Docs                 libevent            mysys        scripts    support-files  zlibcmd-line-utils  Doxyfile-perfschema  libmysql            mysys_ssl    sql        tests[root@localhost mysql-5.6.26]# cmake  \> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \             //指定安装路径> -DDEFAULT_CHARSET=utf8 \                                           //指定默认字符集> -DDEFAULT_COLLATION=utf8_general_ci \                   //指定默认字符集的校对规则> -DEXTRA_CHARSETS=all \                                              //指定额外支持的其它字符集> -DSYSCONFIDIR=/etc \                                                       //指定初始化参数文件目录> -DMYSQL_DATADIR=/home/mysql/ \                                //指定数据文件目录> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock        //指定连接数据库的文件.......                  //省略过程

(4)编译安装MySQL。

[root@localhost mysql-5.6.26]# make&&make install.......                  //省略过程(编译时间较长耐心等待)#make进行编译,将源代码转换为可执行程序。make  install 进行安装。

(5)建立配置文件,用我们源码包里自带的默认配置文件,去覆盖系统默认的MySQL服务配置文件。

[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnfcp:是否覆盖"/etc/my.cnf"? yes[root@localhost mysql-5.6.26]#

(6)先将将脚本文件"mysql.server"从"support-files/"目录下复制到"/etc/init.d/"目录下,重命名为"mysqld",同时给脚本文件添加执行权限。然后将MySQL服务添加为系统服务,并设置MySQL的环境变量。

[root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld   //将脚本文件复制到/etc/init.d/目录[root@localhost mysql-5.6.26]# ls -l /etc/init.d/mysqld -rw-r--r--. 1 root root 10870 10月 18 17:28 /etc/init.d/mysqld[root@localhost mysql-5.6.26]# chmod +x /etc/init.d/mysqld                //添加执行权限[root@localhost mysql-5.6.26]# ls -l /etc/init.d/mysqld -rwxr-xr-x. 1 root root 10870 10月 18 17:28 /etc/init.d/mysqld[root@localhost mysql-5.6.26]# chkconfig --add /etc/init.d/mysqld      //添加为系统服务[root@localhost mysql-5.6.26]# chkconfig  mysqld --level 35 on[root@localhost mysql-5.6.26]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile    //设置环境变量[root@localhost mysql-5.6.26]# source /etc/profile                //重新执行一下,刷新配置[root@localhost mysql-5.6.26]# echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin[root@localhost mysql-5.6.26]# 

(7)创建一个mysql用户,设为禁止登陆。然后将"/usr/local/mysql/"目录下的所有文件目录的属主、属组改为mysql。

[root@localhost mysql-5.6.26]# useradd -s /sbin/nologin mysql                          //添加用户[root@localhost mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/          //更改属主、属组,-R表示递归[root@localhost mysql-5.6.26]# ls -l /usr/local/mysql/总用量 152drwxr-xr-x.  2 mysql mysql   4096 10月 18 17:27 bin-rw-r--r--.  1 mysql mysql  17987 7月  15 2015 COPYINGdrwxr-xr-x.  3 mysql mysql     18 10月 18 17:27 datadrwxr-xr-x.  2 mysql mysql     55 10月 18 17:27 docsdrwxr-xr-x.  3 mysql mysql   4096 10月 18 17:27 include-rw-r--r--.  1 mysql mysql 104897 7月  15 2015 INSTALL-BINARYdrwxr-xr-x.  3 mysql mysql   4096 10月 18 17:27 libdrwxr-xr-x.  4 mysql mysql     30 10月 18 17:27 mandrwxr-xr-x. 10 mysql mysql   4096 10月 18 17:27 mysql-test-rw-r--r--.  1 mysql mysql   2496 7月  15 2015 READMEdrwxr-xr-x.  2 mysql mysql     30 10月 18 17:27 scriptsdrwxr-xr-x. 28 mysql mysql   4096 10月 18 17:27 sharedrwxr-xr-x.  4 mysql mysql   4096 10月 18 17:27 sql-benchdrwxr-xr-x.  2 mysql mysql    136 10月 18 17:27 support-files[root@localhost mysql-5.6.26]#

(8)初始化数据库。

[root@localhost mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db \> --user=mysql \                                       //管理用户> --ldata=/var/lib/mysql \                         //数据目录> --basedir=/usr/local/mysql \                //工作目录> --datadir=/home/mysql                       //数据目录.......                  //省略过程

(9)为连接数据库的文件"mysql.sock"在目录"/home/mysql/"下建立一个软链接,方便使用。

[root@localhost mysql-5.6.26]# ln -s /var/lib/mysql/mysql.sock  /home/mysql/mysql.sock[root@localhost mysql-5.6.26]#

(10)对配置文件进行修改,添加我们的工作目录与数据存放目录。

[root@localhost mysql-5.6.26]# vim  /etc/init.d/mysqldbasedir=/usr/local/mysqldatadir=/home/mysql

(11)开启mysql服务,同时检查是否监听到TCP协议端口3306。

[root@localhost mysql-5.6.26]# service mysqld start                //启动服务Starting MySQL. SUCCESS! [root@localhost mysql-5.6.26]# netstat -anpt | grep 3306tcp6       0      0 :::3306                 :::*                    LISTEN      53852/mysqld        [root@localhost mysql-5.6.26]#

(12)修改mysql数据库的管理员密码。

[root@localhost mysql-5.6.26]# mysqladmin -u root -p password "abc123"Enter password:                      //这里输入原始密码,原始密码为空,直接回车即可Warning: Using a password on the command line interface can be insecure.[root@localhost mysql-5.6.26]#

(13)尝试进入mysql数据库,检查数据库是否搭建成功。

[root@localhost mysql-5.6.26]# mysql -u root -p                  //登录Enter password:                                      //输入上一步设置的密码Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.6.26 Source distributionCopyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;                    //查看数据库+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               |+--------------------+4 rows in set (0.00 sec)mysql> quit                                              //退出Bye[root@localhost mysql-5.6.26]#

三、安装PHP服务

(1)安装编译PHP服务以及服务所需的相关工具。

[root@localhost mysql-5.6.26]# yum -y install \> gd \> libpng \> libpng-devel \> pcre \> pcre-devel \> libxml2-devel \> libjpeg-devel.......                  //省略过程

(2)将PHP服务的源码包解压到"/opt/"目录下。

[root@localhost mysql-5.6.26]#cd /mnt/[root@localhost mnt]# lsapr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz[root@localhost mnt]# tar jxvf php-5.6.11.tar.bz2 -C /opt/.......                  //省略过程

(3)进入"/opt/php-5.6.11/"目录下,对PHP服务进行配置。

[root@localhost mnt]# cd /opt/php-5.6.11/[root@localhost php-5.6.11]# ./configure \> --prefix=/usr/local/php5 \                                //指定安装路径> --with-gd \                                                        //图片处理库> --with-zlib \                                                      //压缩函数库> --with-apxs2=/usr/local/httpd/bin/apxs \     //设置Apache HTTP Server提供的apxs模块支持程序的文件位置> --with-mysql=/usr/local/mysql \                   //设置MySQL数据库服务程序安装位置> --with-config-file-path=/usr/local/php5 \     //设置PHP的配置文件php.ini将要存放的位置> --enable-mbstring                                         //启用多字节字符串功能.......                  //省略过程

(4)编译安装PHP

[root@localhost php-5.6.11]# make&& make install.......                  //省略过程(编译时间较长耐心等待)#make进行编译,将源代码转换为可执行程序。make  install 进行安装。

(5)将源码包里的配置文件复制到"/usr/local/php5/"目录下,并重命名为"php.ini",然后同时在系统识别的环境变量目录"/usr/local/bin/"下,建立PHP服务执行程序的软链接。

[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini[root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/[root@localhost php-5.6.11]#

(6)对httpd服务的配置文件"httpd.conf"进行修改,使httpd服务器支持PHP页面解析功能。

[root@localhost php-5.6.11]# vim /etc/httpd.conf    DirectoryIndex index.html index.php              //添加默认首页识别php格式文件类型    AddType application/x-httpd-php .php          //添加对".php"类型网页文件的支持    AddType application/x-httpd-php-source .phps


(7)重新启动httpd服务,不建议用"restart",因为"restart"有些进程不会结束。

[root@localhost php-5.6.11]# service httpd stop[root@localhost php-5.6.11]# service httpd start [root@localhost php-5.6.11]# 

(8)修改首页文件内容,并将首页文件"index.html"重命名为"index.php"。

[root@localhost php-5.6.11]# cd /usr/local/httpd/htdocs/[root@localhost htdocs]# lsindex.html[root@localhost htdocs]# vim index.html [root@localhost htdocs]# mv index.html index.php[root@localhost htdocs]# lsindex.php[root@localhost htdocs]#

(9)此时再用我们的宿主机去访问http服务,结果如下。

四、安装论坛

(1)进入MySQL,为论坛创建一个名为"bbs"的数据库,

[root@localhost htdocs]# cd /mnt/[root@localhost mnt]# lsapr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz[root@localhost mnt]# mysql -u root -p               //登录Enter password:                   //输入密码Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.6.26 Source distributionCopyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> create database bbs;                                        //创建数据库Query OK, 1 row affected (0.03 sec)mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123';            //给bbs数据库中的所有表格提升权限,同时创建管理数据库的用户"bbsuser",设置密码。"%"表示可以从所有终端访问Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;                                   //刷新数据库Query OK, 0 rows affected (0.01 sec)mysql> quit                                         //退出Bye[root@localhost mnt]#

(2)将Discuz压缩包,解压到"/opt/"目录下,命名为"dis"。

[root@localhost mnt]# lsapr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz[root@localhost mnt]# unzip Discuz_X2.5_SC_UTF8.zip -d /opt/dis

(3)用"cp -r"命令把"upload/"目录递归复制到,httpd服务存放网页文档的目录"/usr/local/httpd/htdocs/"下面,命名为bbs。

[root@localhost mnt]# cd /opt/[root@localhost opt]# lsdis  httpd-2.4.29  mysql-5.6.26  php-5.6.11  rh[root@localhost opt]# cd dis/[root@localhost dis]# lsreadme  upload  utility[root@localhost dis]# cp -r upload/ /usr/local/httpd/htdocs/bbs[root@localhost bbs]#

(4)分别将下列文件或目录的属主改为"daemon"。

[root@localhost dis]# cd /usr/local/httpd/htdocs/bbs/[root@localhost bbs]# lsadmin.php  config           data         home.php    misc.php    search.php  uc_clientapi        connect.php      favicon.ico  index.php   plugin.php  source      uc_serverapi.php    cp.php           forum.php    install     portal.php  static      userapp.phparchiver   crossdomain.xml  group.php    member.php  robots.txt  template[root@localhost bbs]# chown -R daemon ./config                                      //更改属主[root@localhost bbs]# chown -R daemon ./data                                        //更改属主[root@localhost bbs]# chown -R daemon ./uc_client                               //更改属主[root@localhost bbs]# chown -R daemon ./uc_server/data                    //更改属主[root@localhost bbs]# 

(5)在我们的宿主机浏览器输入http://192.168.52.132/bbs,进入论坛安装界面点击我同意。

(6)点击下一步。

(7)选择全新安装,点击下一步。

(8)按照下图输入数据库相关信息,然后点击下一步,安装数据库。

安装完毕如下图:

(9)重新输入http://192.168.52.132/bbs,成功进入论坛。

服务 文件 目录 配置 数据 过程 数据库 编译 程序 系统 支持 地址 密码 监听 输入 源码 功能 同时 字符 环境 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广州万易互联网科技有限公司 科技互联网产品 互联网最新的科技有限公司 广州互联网科技公司 互联网科技公司电话 深圳天众互联网科技公司 互联网前沿科技 以后互联网后是啥科技 现代互联网科技股 重庆互联网医院沙龙医盟信息科技 苏州五指互联网络科技有限 链环科技传统企业怎么转型互联网 国大互联网教育科技有限公司薪资 美国互联网科技实力 山东星卡互联网科技有限公司官网 从那以后互联网科技有限公司 昆明中奇联合互联网科技 国产互联网科技公司 恒生科技指数 中概互联网 广州全民伙伴互联网科技有限公司 中关村互联网科技集团 科技金融是不是互联网金融 互联网科技资迅 港股互联网科技股 云电互联网科技 汉立互联网科技有限公司联系电话 银川新华互联网科技职业技术培训学校图片 栖莱科技互联网股份有限公司 民营互联网公司国防科技 江苏苏星互联网科技有限公司
0