LAMP搭建论坛(Linux-Apache-Mysql-PHP)

一、什么是LAMP

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写

准备环境包:
百度网盘分享链接: https://pan.baidu.com/s/1E5AepxVTgQouSyOgNf9jMg 提取码: kvpb
先用smb共享的方式将下载下来的软件包,通过远程挂载的方式到Linux系统
在这里插入图片描述

二、搭建服务

1、Apache安装

[root@localhost ~]# mkdir /LAMP                         //创建挂载点
[root@localhost ~]# mount.cifs //192.168.17.1/LAMP /LAMP         //链接共享
Password for root@//192.168.17.1/LAMP:  
[root@localhost ~]# df -hT                             
文件系统            类型      容量  已用  可用 已用% 挂载点
/dev/sda5           xfs        32G  3.3G   29G   11% /
devtmpfs            devtmpfs  898M     0  898M    0% /dev
tmpfs               tmpfs     912M     0  912M    0% /dev/shm
tmpfs               tmpfs     912M  9.0M  903M    1% /run
tmpfs               tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda2           xfs       4.0G   33M  4.0G    1% /home
/dev/sda1           xfs       497M  167M  331M   34% /boot
tmpfs               tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs               tmpfs     183M   28K  183M    1% /run/user/0
//192.168.17.1/LAMP cifs      293G  111G  183G   38% /LAMP
[root@localhost ~]# cd LAMP
[root@localhost LAMP]# ls
apr-1.6.2.tar.gz           httpd-2.4.29.tar.bz2  mysql-5.6.26.tar.gz
apr-util-1.6.0.tar.gz      httpd-2.4.2.tar.gz    php-5.6.11.tar.bz2
Discuz_X2.5_SC_UTF8.zip    john-1.8.0.tar.gz
extundelete-0.2.4.tar.bz2  LAMP-php5.6.txt
[root@localhost LAMP]# tar zvxf apr-1.6.2.tar.gz -C /opt
[root@localhost LAMP]# tar zvxf apr-util-1.6.0.tar.gz -C /opt
[root@localhost LAMP]# tar jvxf httpd-2.4.29.tar.bz2 -C /opt      //解压3个包到opt
[root@localhost LAMP]# cd /opt
[root@localhost opt]# ls                            //将两个apr文件移动到httpd中
apr-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]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
[root@localhost opt]# ls
httpd-2.4.29  rh
[root@localhost opt]# cd httpd-2.4.29/
[root@localhost httpd-2.4.29]# ls                 
ABOUT_APACHE     CMakeLists.txt  INSTALL         NWGNUmakefile
acinclude.m4     config.layout   InstallBin.dsp  os
Apache-apr2.dsw  configure       LAYOUT          README
Apache.dsw       configure.in    libhttpd.dep    README.cmake
apache_probes.d  docs            libhttpd.dsp    README.platforms
ap.d             emacs-style     libhttpd.mak    ROADMAP
build            httpd.dep       LICENSE         server
BuildAll.dsp     httpd.dsp       Makefile.in     srclib
BuildBin.dsp     httpd.mak       Makefile.win    support
buildconf        httpd.spec      modules         test
CHANGES          include         NOTICE          VERSIONING
[root@localhost httpd-2.4.29]# yum install -y gcc gcc-c++ pcre-devel pcre expat-devel       //安装语言包  
[root@localhost httpd-2.4.29]#./configure \        
--prefix=/usr/local/httpd \
--enable-so --enable-rewrite \
--enable-charset-lite \
--enable-cgi                  //配置选项如安装路径,启用字符集支持等
[root@localhost httpd-2.4.29]#make              //编译
[root@localhost httpd-2.4.29]#make install     //安装
[root@localhost httpd-2.4.29]#cd /usr/local/httpd/bin  //切换至安装路径
[root@localhost bin]# ls
ab            apu-1-config  dbmmanage    fcgistarter   htdigest  httxt2dbm
apachectl     apxs          envvars      htcacheclean  htpasswd  logresolve
apr-1-config  checkgid      envvars-std  htdbm         httpd     rotatelogs
[root@localhost bin]# cp apachectl /etc/init.d/httpd    
//将apachevtl脚本复制为/etc/init.d/httpd,并在文件开头添加chkconfig识别配置
[root@localhost bin]# vim /etc/init.d/httpd      
#!/bin/sh
#chkconfig: 35 85 21         //服务识别参数,在级别3、5中启动;启动个关闭顺序分别为85、21
#description: Apache is a World Wide Web server     //服务描述信息
……省略
[root@localhost bin]# chkconfig --add httpd        //将httpd添加为系统服务
[root@localhost bin]# cd ..
[root@localhost httpd]# ls
bin    cgi-bin  error   icons    lib   man     modules
build  conf     htdocs  include  logs  manual
[root@localhost httpd]# cd conf
[root@localhost conf]# ls
extra  httpd.conf  magic  mime.types  original
[root@localhost conf]# pwd
/usr/local/httpd/conf     //路径较长,可以优化路径,使用ln -s建立软链接
[root@localhost conf]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
[root@localhost conf]# ln -s /usr/local/httpd/bin/* /usr/local/bin
[root@localhost conf]# vim /etc/httpd.conf     //进入配置文件修改监听地址等信息
[root@localhost conf]# httpd -t
Syntax OK
[root@localhost conf]# service httpd start           //启用服务
[root@localhost conf]# netstat -ntap | grep 80
tcp        0      0 192.168.17.132:80       0.0.0.0:*               LISTEN      105929/httpd        
[root@localhost conf]# systemctl stop firewalld.service   //关闭防火墙
[root@localhost conf]# setenforce 0


2、Mysql安装

----------------------Mysql安装---------------------------

[root@localhost ~]#cd /LAMP
[root@localhost LAMP]# ls
apr-1.6.2.tar.gz         extundelete-0.2.4.tar.bz2  john-1.8.0.tar.gz    php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz    httpd-2.4.29.tar.bz2       LAMP-php5.6.txt
Discuz_X2.5_SC_UTF8.zip  httpd-2.4.2.tar.gz         mysql-5.6.26.tar.gz
[root@localhost abc]#tar zvxf mysql-5.6.26.gz -C /opt          //解压至opt
[root@localhost abc]# cd /opt/mysql-5.6.26/
[root@localhost mysql-5.6.26]# ls
BUILD           config.h.cmake       extra               libmysqld    packaging  sql-bench      unittest
BUILD-CMAKE     configure.cmake      include             libservices  plugin     sql-common     VERSION
client          COPYING              INSTALL-SOURCE      man          README     storage        vio
cmake           dbug                 INSTALL-WIN-SOURCE  mysql-test   regex      strings        win
CMakeLists.txt  Docs                 libevent            mysys        scripts    support-files  zlib
cmd-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
//指定安装路径、字符集、配置文件目录、数据目录及定义sock通信文件,连接数据库的必要文件
[root@localhost mysql-5.6.26]# make                         //安装
[root@localhost mysql-5.6.26]# make install                 //编译
[root@localhost mysql-5.6.26]# ls
BUILD                COPYING                  INSTALL-SOURCE      mysys_ssl         strings
BUILD-CMAKE          CPackConfig.cmake        INSTALL-WIN-SOURCE  packaging         support-files
client               CPackSourceConfig.cmake  libevent            plugin            tests
cmake                CTestTestfile.cmake      libmysql            README            unittest
CMakeCache.txt       dbug                     libmysqld           regex             VERSION
CMakeFiles           Docs                     libservices         scripts           VERSION.dep
cmake_install.cmake  Doxyfile-perfschema      make_dist.cmake     source_downloads  vio
CMakeLists.txt       extra                    Makefile            sql               win
cmd-line-utils       include                  man                 sql-bench         zlib
config.h.cmake       info_macros.cmake        mysql-test          sql-common
configure.cmake      install_manifest.txt     mysys               storage
[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf  
cp:是否覆盖"/etc/my.cnf"? yes        //复制配置文件至/etc/my-default.cnf
[root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld  
//复制脚本配置文件
[root@localhost mysql-5.6.26]# cd /etc/init.d             //切换至路径下查看mysqld无执行权限
[root@localhost init.d]# ls
functions  httpd  mysqld  netconsole  network  README
[root@localhost init.d]# chmod 755 mysqld                //添加执行权限
[root@localhost init.d]# ls
functions  httpd  mysqld  netconsole  network  README
[root@localhost init.d]# chkconfig --add /etc/init.d/mysqld         //将服务添加系统
[root@localhost init.d]# chkconfig --level 35 mysqld on             //将35级别开启
[root@localhost init.d]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@localhost init.d]# source /etc/profile
[root@localhost init.d]# echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/root/bin:/usr/local/mysql/bin
[root@localhost init.d]# useradd -s /sbin.nologin mysql
[root@localhost init.d]# id mysql
uid=1000(mysql) gid=1000(mysql) 组=1000(mysql)
[root@localhost init.d]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost init.d]# cd /usr/local/mysql/
[root@localhost mysql]# ls -l
总用量 148
drwxr-xr-x  2 mysql mysql   4096 12月 10 23:03 bin
-rw-r--r--  1 mysql mysql  17987 7月  15 2015 COPYING
drwxr-xr-x  3 mysql mysql     18 12月 10 23:03 data
drwxr-xr-x  2 mysql mysql     55 12月 10 23:03 docs
drwxr-xr-x  3 mysql mysql   4096 12月 10 23:03 include
-rw-r--r--  1 mysql mysql 104897 7月  15 2015 INSTALL-BINARY
drwxr-xr-x  3 mysql mysql    291 12月 10 23:03 lib
drwxr-xr-x  4 mysql mysql     30 12月 10 23:03 man
drwxr-xr-x 10 mysql mysql   4096 12月 10 23:03 mysql-test
-rw-r--r--  1 mysql mysql   2496 7月  15 2015 README
drwxr-xr-x  2 mysql mysql     30 12月 10 23:03 scripts
drwxr-xr-x 28 mysql mysql   4096 12月 10 23:03 share
drwxr-xr-x  4 mysql mysql   4096 12月 10 23:03 sql-bench
drwxr-xr-x  2 mysql mysql    136 12月 10 23:03 support-files
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db \      //初始化数据库
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql                         //配置 用户、工作目录等
[root@localhost mysql]#vim /etc/init.d/mysqld           //更改启动脚本
…………省略
basedir=/usr/local/mysql     
datadir=/home/mysql
…………省略
[root@localhost mysql]# service mysqld start     //启动服务
Starting MySQL..ne SUCCESS! 
[root@localhost mysql]# netstat -ntap | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      124016/mysqld       
[root@localhost mysql]# mysqladmin -u root -p password "123"     //更改密码
Enter password:                                            //提示输入旧密码,无旧密码直接回车
Warning: Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -u root -p                  //登录mysql
Enter password: 
mysql> 

3、php安装

[root@localhost ~]# yum -y install gd libpng libpng-devel pcre pcre-devel libxml2-devel libjpeg-devel
//安装语言包
[root@localhost LAMP]# tar jvxf php-5.6.11.tar.bz2 -C /opt     //将php安装包解压至opt
[root@localhost LAMP]# 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 \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring 
//进行./configure配置安装路径等
[root@localhost php-5.6.11]# make && make install
[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]# vim /etc/httpd.conf                   //配置httpd主配置文件
……省略部分内容
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
……省略部分内容
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php       //插入
    AddType application/x-httpd-php-source .phps       //插入
 …………省略内容
 [root@localhost php-5.6.11]# vim /usr/local/httpd/htdocs/index.php  //添加index.php 并进行网页测试
<?php
phpinfo();
?>
[root@localhost htdocs]# service httpd restart
[root@localhost htdocs]# service mysqld restart
//所有服务全部重启

在这里插入图片描述

4、安装论坛

Enter password: 
mysql> create database bbs;                 //创建bbs库
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbs                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)

 mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin321';                   //把bbs数据库里面所有表的权限授予给bbsuser,并设置密码 
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;               // //刷新数据库
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost htdocs]# cd /LAMP
[root@localhost LAMP]# ls
apr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip    httpd-2.4.29.tar.bz2  john-1.8.0.tar.gz  mysql-5.6.26.tar.gz
apr-util-1.6.0.tar.gz  extundelete-0.2.4.tar.bz2  httpd-2.4.2.tar.gz    LAMP.txt           php-5.6.11.tar.bz2
[root@localhost LAMP]# unzip Discuz_X2.5_SC_UTF8.zip -d /opt/      //解压
[root@localhost LAMP]# cd /opt
[root@localhost opt]# ls
httpd-2.4.29  mysql-5.6.26  php-5.6.11  readme  rh  upload  utility
[root@localhost opt]# cp -r upload/ /usr/local/httpd/htdocs/bbs
[root@localhost bbs]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
bbs  index.php

#####这时进入网页192.168.17.128/bbs进入安装向导
#####状态提示目录不存在不可以,原因没有执行权限
[root@localhost htdocs]# cd bbs
[root@localhost bbs]# ls
admin.php  archiver     cp.php           favicon.ico  home.php   member.php  portal.php  source    uc_client
api        config       crossdomain.xml  forum.php    index.php  misc.php    robots.txt  static    uc_server
api.php    connect.php  data             group.php    install    plugin.php  search.php  template  userapp.php
[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
//权限添加完成后就可到网站中进行安装及登录了

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

发布了72 篇原创文章 · 获赞 44 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ML908/article/details/103498028
今日推荐