Linux系统架构-----LAMP(手工编译安装)

目录

 

一.LAMP的基本概念

二.安装Apache网站服务器

三.安装MySQL服务

四.构建PHP运行环境

五.在LAMP架构里添加Discuz论坛


一.LAMP的基本概念

  • LAMP架构是目前成熟的企业网站应用模式之一,是协同工作的一整套系统和相关软件,且能够提供动态web站点服务以及应用开发环境
  • LAMP包括Linux操作系统、Apache网站服务器、MySql数据库、PHP(或perl、Python)网页编程语言
  • 其中apache和mysql的安装没有顺序要求,但是PHP的安装必须放到最后,负责沟通wed服务器和数据库系统以协同工作
  • 安装环境获取Discuz_X2.5_SC_UTF8.zip  mysql-5.6.26.tar.gz  apr-1.6.2.tar.gz       httpd-2.4.29.tar.bz2     php-5.6.11.tar.bz2   
    apr-util-1.6.0.tar.gz等安装包

二.安装Apache网站服务器

  • 解压apache相关的安装包
[root@localhost mnt]# ls
apr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz
[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 xjvf httpd-2.4.29.tar.bz2 -C /opt
[root@localhost mnt]# cd
[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]# 
  • 安装apache相关的环境包
[root@localhost opt]# yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
  • 配置apache服务
[root@localhost httpd-2.4.29]#./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
//--prefix,指明安装路径
//--enable-so,启用核心模块
//--rewrite,启用网页地址重写功能
//--charset-lite,启用字符集
//--cgi,启用CGI脚本,通用网关接口
  • 编译以及安装
[root@localhost httpd-2.4.29]# make && make install 
  • 添加httpd系统服务
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[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 //服务描述信息
#

[root@localhost httpd-2.4.29]# chkconfig --add httpd   //将httpd添加为系统服务
[root@localhost httpd-2.4.29]# 
  • 编辑主配置文件
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf

Listen 192.168.43.155:80
#Listen 80
ServerName www.kgc.com:80
  • 优化主配置文件和启动脚本,创建软链接
[root@localhost ~]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
[root@localhost ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin
[root@localhost ~]# 
  • 关闭防火墙,开启服务
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0
[root@localhost ~]# service httpd start         
[root@localhost ~]# netstat -natp | grep httpd 
tcp        0      0 192.168.43.155:80       0.0.0.0:*               LISTEN      39045/httpd         
[root@localhost ~]# 
  • 验证结果

三.安装MySQL服务

  • 一般避免端口冲突可以查看mysql软件是否安装
[root@localhost ~]# rpm -q mysql-server mysql
未安装软件包 mysql-server 
未安装软件包 mysql 
[root@localhost ~]# 
  • 解压mysql的软件包
[root@localhost mnt]# ls
apr-1.6.2.tar.gz       Discuz_X2.5_SC_UTF8.zip  LAMP-php5.6.txt      php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz  httpd-2.4.29.tar.bz2     mysql-5.6.26.tar.gz
[root@localhost mnt]# tar xzvf mysql-5.6.26.tar.gz -C /opt
  • 安装必要的环境包
[root@localhost mnt]# yum install ncurses-devel autoconf cmake -y
  • 配置,需要在/opt/mysql-5.6.26/这个目录下
[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


//-DCMAKE_INSTALL_PREFIX指定路径
//-DDEFAULT_CHARSET字符集
//-DDEFAULT_COLLATION通用字符集
//-DEXTRA_CHARSETS扩展字符集
//-DSYSCONFIDIR配置文件的目录
//-DMYSQL_DATADIR数据文件目录
//-DMYSQL_UNIX_ADDR通信文件,定义连接数据库的文件,服务启动之后才会生成文件
  • 编译与安装
[root@localhost mysql-5.6.26]# make && make install
  • 建立配置文件,覆盖本机原有的my.cnf文件
[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@localhost mysql-5.6.26]# 

  • 添加系统服务
[root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.6.26]# 
  • 给予权限
[root@localhost mysql-5.6.26]# cd /etc/init.d
[root@localhost init.d]# ls
functions  httpd  mysqld  netconsole  network  README
[root@localhost init.d]# chmod 755 /etc/init.d/mysqld       
[root@localhost init.d]# chkconfig --add /etc/init.d/mysqld
[root@localhost init.d]# chkconfig  mysqld --level 35 on
[root@localhost init.d]# ls
functions  httpd  mysqld  netconsole  network  README
[root@localhost init.d]# 
  • 追加环境变量
[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/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
[root@localhost init.d]# 
  • 添加数据库用户,且更改属性
[root@localhost init.d]# useradd -s /sbin/nologin mysql
[root@localhost init.d]# chown -R mysql:mysql /usr/local/mysql
[root@localhost init.d]# cd /usr/local
[root@localhost local]# ls -l
总用量 4
drwxr-xr-x.  2 root  root  4096 12月 11 18:52 bin
drwxr-xr-x.  2 root  root     6 11月  5 2016 etc
drwxr-xr-x.  2 root  root     6 11月  5 2016 games
drwxr-xr-x. 15 root  root   175 12月 11 18:50 httpd
drwxr-xr-x.  2 root  root     6 11月  5 2016 include
drwxr-xr-x.  2 root  root     6 11月  5 2016 lib
drwxr-xr-x.  2 root  root     6 11月  5 2016 lib64
drwxr-xr-x.  2 root  root     6 11月  5 2016 libexec
drwxr-xr-x. 13 mysql mysql  213 12月 11 19:22 mysql
drwxr-xr-x.  2 root  root     6 11月  5 2016 sbin
drwxr-xr-x.  5 root  root    49 12月  9 11:46 share
drwxr-xr-x.  2 root  root     6 11月  5 2016 src
[root@localhost local]# 
  • 初始化数据库,必须在此之前创建用户
[root@localhost local]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql \
> --datadir=/home/mysql
  • 创建通信文件的软链接
[root@localhost local]# ln -s /var/lib/mysql/mysql.sock  /home/mysql/mysql.sock
[root@localhost local]# 
  • 修改启动脚本
[root@localhost local]# vim  /etc/init.d/mysqld

 46 basedir=/usr/local/mysql
 47 datadir=/home/mysql
 48 

  • 开启mysql服务
[root@localhost local]# service mysqld start 
Starting MySQL.. SUCCESS! 
[root@localhost local]# 
  • 给创建的mysql用户设置密码
[root@localhost local]# mysqladmin -u root -p password "abc123"
Enter password: 
Warning: Using a password on the command line interface can be insecure.
[root@localhost local]# 
  • 验证结果
[root@localhost local]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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.01 sec)

mysql> 

四.构建PHP运行环境

  • 解压PHP包
[root@localhost mnt]# tar xjvf php-5.6.11.tar.bz2 -C /opt
  • 安装必要环境
[root@localhost opt]#yum -y install \
gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
  • 进行PHP的相关配置
[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


//--with-gd是图片库
//--with-zlib支持压缩
//--with-apxs2Apache服务
//--with-mysql设置mysql服务
//--with-config-file-path,设置PHP的配置文件php.ini的位置
//--enable-mbstring,启用字符串
  • 编译且安装PHP
[root@localhost php-5.6.11]# make && make install
  • 建立主配置文件php.ini,以及生成软链接
[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]# ln -s /usr/local/php5/sbin/* /usr/l
lib/     lib64/   libexec/ local/   
[root@localhost php-5.6.11]# ln -s /usr/local/php5/sbin/* /usr/local/sbin
[root@localhost php-5.6.11]# 
  • 在apache的主配置文件中,增加php信息,使得apache支持php
[root@localhost php-5.6.11]# vim /etc/httpd.conf
254 #
255 <IfModule dir_module>
256     DirectoryIndex index.php index.html
257 </IfModule>

......
391     #
392     AddType application/x-compress .Z
393     AddType application/x-gzip .gz .tgz
394     AddType application/x-httpd-php .php
395     AddType application/x-httpd-php-source .phps

  • 编辑apache的主页面
[root@localhost php-5.6.11]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mv index.html index.php
[root@localhost htdocs]# ls
index.php
[root@localhost htdocs]# vim index.php 

<?php
phpinfo();
?>
  • 先重启apache服务,再验证php功能
[root@localhost htdocs]# service httpd stop
[root@localhost htdocs]# service httpd start 
[root@localhost htdocs]# 

五.在LAMP架构里添加Discuz论坛

  • 解压Discuz论坛软件包
[root@localhost mnt]# ls
apr-1.6.2.tar.gz         httpd-2.4.29.tar.bz2  php-5.6.11.tar.bz2
apr-util-1.6.0.tar.gz    LAMP-php5.6.txt
Discuz_X2.5_SC_UTF8.zip  mysql-5.6.26.tar.gz
[root@localhost mnt]# unzip /mnt/Discuz_X2.5_SC_UTF8.zip -d /opt/dis
[root@localhost mnt]# cd /opt
[root@localhost opt]# ls
dis  httpd-2.4.29  mysql-5.6.26  php-5.6.11  rh
[root@localhost opt]# ls dis
readme  upload  utility
[root@localhost opt]# 

  • 进入mysql,创建一个数据库,在该数据库中创建一个账户和密码,刷新数据库

[root@localhost htdocs]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.26 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

mysql> create database sky;            //创建数据库
Query OK, 1 row affected (0.00 sec)

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

mysql> GRANT all ON sky.* TO 'skyuser'@'%' IDENTIFIED BY 'admin123';    //创建账户和密码
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges         //刷新数据库
    -> ;
Query OK, 0 rows affected (0.01 sec)

mysql> 
  • 复制Discuz中的包到新创建的数据库中
[root@localhost htdocs]# cd /opt/dis
[root@localhost dis]# ls
readme  upload  utility
[root@localhost dis]# cp -r upload/ /usr/local/httpd/htdocs/sky
  • 修改数据库中包的属性
[root@localhost dis]# cd /usr/local/httpd/htdocs/sky/
[root@localhost sky]# ls
admin.php  config           data         home.php    misc.php    search.php  uc_client
api        connect.php      favicon.ico  index.php   plugin.php  source      uc_server
api.php    cp.php           forum.php    install     portal.php  static      userapp.php
archiver   crossdomain.xml  group.php    member.php  robots.txt  template
[root@localhost sky]# ls -l
总用量 76
-rw-r--r--.  1 root root 2603 12月 11 21:48 admin.php
drwxr-xr-x. 11 root root  163 12月 11 21:48 api
-rw-r--r--.  1 root root  727 12月 11 21:48 api.php
drwxr-xr-x.  2 root root   23 12月 11 21:48 archiver
drwxr-xr-x.  2 root root   90 12月 11 21:48 config
-rw-r--r--.  1 root root  922 12月 11 21:48 connect.php
-rw-r--r--.  1 root root  253 12月 11 21:48 cp.php
-rw-r--r--.  1 root root  106 12月 11 21:48 crossdomain.xml
drwxr-xr-x. 13 root root  216 12月 11 21:48 data
-rw-r--r--.  1 root root 5558 12月 11 21:48 favicon.ico
-rw-r--r--.  1 root root 2110 12月 11 21:48 forum.php
-rw-r--r--.  1 root root  823 12月 11 21:48 group.php
-rw-r--r--.  1 root root 1223 12月 11 21:48 home.php
-rw-r--r--.  1 root root 5448 12月 11 21:48 index.php
drwxr-xr-x.  5 root root   64 12月 11 21:48 install
-rw-r--r--.  1 root root 1040 12月 11 21:48 member.php
-rw-r--r--.  1 root root 1381 12月 11 21:48 misc.php
-rw-r--r--.  1 root root 1757 12月 11 21:48 plugin.php
-rw-r--r--.  1 root root  985 12月 11 21:48 portal.php
-rw-r--r--.  1 root root  582 12月 11 21:48 robots.txt
-rw-r--r--.  1 root root 1158 12月 11 21:48 search.php
drwxr-xr-x. 10 root root  168 12月 11 21:48 source
drwxr-xr-x.  6 root root   72 12月 11 21:48 static
drwxr-xr-x.  3 root root   38 12月 11 21:48 template
drwxr-xr-x.  6 root root   92 12月 11 21:48 uc_client
drwxr-xr-x. 13 root root  241 12月 11 21:48 uc_server
-rw-r--r--.  1 root root 1691 12月 11 21:48 userapp.php
[root@localhost sky]# chown -R daemon ./config
[root@localhost sky]# chown -R daemon ./data
[root@localhost sky]# chown -R daemon ./uc_client
[root@localhost sky]# chown -R daemon ./uc_server/data
[root@localhost sky]# ls -l
总用量 76
-rw-r--r--.  1 root   root 2603 12月 11 21:48 admin.php
drwxr-xr-x. 11 root   root  163 12月 11 21:48 api
-rw-r--r--.  1 root   root  727 12月 11 21:48 api.php
drwxr-xr-x.  2 root   root   23 12月 11 21:48 archiver
drwxr-xr-x.  2 daemon root   90 12月 11 21:48 config
-rw-r--r--.  1 root   root  922 12月 11 21:48 connect.php
-rw-r--r--.  1 root   root  253 12月 11 21:48 cp.php
-rw-r--r--.  1 root   root  106 12月 11 21:48 crossdomain.xml
drwxr-xr-x. 13 daemon root  216 12月 11 21:48 data
-rw-r--r--.  1 root   root 5558 12月 11 21:48 favicon.ico
-rw-r--r--.  1 root   root 2110 12月 11 21:48 forum.php
-rw-r--r--.  1 root   root  823 12月 11 21:48 group.php
-rw-r--r--.  1 root   root 1223 12月 11 21:48 home.php
-rw-r--r--.  1 root   root 5448 12月 11 21:48 index.php
drwxr-xr-x.  5 root   root   64 12月 11 21:48 install
-rw-r--r--.  1 root   root 1040 12月 11 21:48 member.php
-rw-r--r--.  1 root   root 1381 12月 11 21:48 misc.php
-rw-r--r--.  1 root   root 1757 12月 11 21:48 plugin.php
-rw-r--r--.  1 root   root  985 12月 11 21:48 portal.php
-rw-r--r--.  1 root   root  582 12月 11 21:48 robots.txt
-rw-r--r--.  1 root   root 1158 12月 11 21:48 search.php
drwxr-xr-x. 10 root   root  168 12月 11 21:48 source
drwxr-xr-x.  6 root   root   72 12月 11 21:48 static
drwxr-xr-x.  3 root   root   38 12月 11 21:48 template
drwxr-xr-x.  6 daemon root   92 12月 11 21:48 uc_client
drwxr-xr-x. 13 root   root  241 12月 11 21:48 uc_server
-rw-r--r--.  1 root   root 1691 12月 11 21:48 userapp.php
[root@localhost sky]# 
  • 验证功能

发布了94 篇原创文章 · 获赞 108 · 访问量 6414

猜你喜欢

转载自blog.csdn.net/qq_42761527/article/details/103494977