WEB应用组合——LAMP软件源码编译安装

LAMP

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写:
Linux,系统
Apache,网页服务
MariaDB或MySQL,数据库管理系统(我这里以mySQL为例去做)
PHP、Perl或Python,语言
虽然这些开放源代码程序本身并不是专门设计成同另几个程序一起工作的,但由于它们的廉价和普遍,这个组合开始流行(大多数Linux发行版本捆绑了这些软件)。当一起使用的时候,它们表现的像一个具有活力的“解决方案包”(Solution Packages)。其他的方案包有苹果的WebObjects(最初是应用服务器),Java/J2EE和微软的.NET架构。
LAMP包的脚本组件中包括了CGI web接口,它在90年代初期变得流行。这个技术允许网页浏览器的用户在服务器上执行一个程序,并且和接受静态的内容一样接受动态的内容。程序员使用脚本语言来创建这些程序因为它们能很容易有效的操作文本流,甚至当这些文本流并非源自程序自身时也是。正是由于这个原因系统设计者经常称这些脚本语言为胶水语言。

LAMP 平台搭建

因为LAMP是四个软件组合使用的,所以要以此安装四个软件,PHP对前几个软件在安装时有配置路径的要求,所以PHP得最后安装
软件安装顺序:Linux(这个是系统啊,肯定是在这上面进行运行)
Apache
MySQL(这个和apache随便先安装哪个)
PHP

虽然现在有一键安装的程序了,但是为了从源码编译安装展示一次,我还是一步一步的来做吧。
在这里插入图片描述
链接放出来吧,各位如果需要就自己拿
LAMP一键安装软件链接

源码安装前准备

gcc和gcc-c++ 都是编译器
make make工具
pcre-devel 正则表达式支持工具
expat-devel 网站解析标签语言工具
perl perl语言工具

[root@5centos yum.repos.d]# yum -y install gcc gcc-c++ make pcre-devel expat-devel perl
作为依赖被升级:
  cpp.x86_64 0:4.8.5-39.el7                gcc-gfortran.x86_64 0:4.8.5-39.el7 
  libgcc.x86_64 0:4.8.5-39.el7             libgfortran.x86_64 0:4.8.5-39.el7  
  libgomp.x86_64 0:4.8.5-39.el7            libquadmath.x86_64 0:4.8.5-39.el7  
  libquadmath-devel.x86_64 0:4.8.5-39.el7  libstdc++.x86_64 0:4.8.5-39.el7    
  libstdc++-devel.x86_64 0:4.8.5-39.el7    perl-libs.x86_64 4:5.16.3-295.el7  

完毕!

APACHE安装

依赖安装

[root@localhost apache]# tar xzvf apr-1.6.2.tar.gz
[root@localhost apache]# tar xzvf apr-util-1.6.0.tar.gz
[root@localhost apache]# tar -xjvf httpd-2.4.29.tar.bz2 
[root@localhost apache]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@localhost apache]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

配置文件

[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \      ##指定路径
> --enable-so \                       ##开启核心功能模块
> --enable-rewrite \                 ##开启重写功能
> --enable-charset-lite \           ##开启字符集
> --enable-cgi                         ##开启通用网关接口

make编译安装

[root@localhost httpd-2.4.29]# make &&make install
……省略部分内容……
Installing man pages and online manual
mkdir /usr/local/httpd/man
mkdir /usr/local/httpd/man/man1
mkdir /usr/local/httpd/man/man8
mkdir /usr/local/httpd/manual
make[1]: 离开目录“/lamp/httpd-2.4.29”

配置脚本

[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  ###如下图
[root@localhost httpd-2.4.29]# chkconfig --add httpd

在这里插入图片描述

编辑httpd数据文件

[root@localhost httpd-2.4.29]# vim /usr/local/httpd/conf/httpd.conf
#
ServerName www.ora.com:80     ###定义域名
Listen 20.0.0.140:80                 ###监听自己的IP
#Listen 80                               ###关闭IPv6监听

创建软连接并开启服务

[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]# setenforce 0
[root@localhost httpd-2.4.29]# ipt
iptables          iptables-save     iptc
iptables-restore  iptables-xml      iptunnel
[root@localhost httpd-2.4.29]# iptables -F
[root@localhost httpd-2.4.29]# httpd -t
Syntax OK
[root@localhost httpd-2.4.29]# apachectl -t
Syntax OK
[root@localhost httpd-2.4.29]# systemctl start httpd

验证HTTP服务

在这里插入图片描述

MySql安装

安装环境

[root@localhost lamp]# yum -y install ncurses-devel autoconf cmake
……省略部分……
Running transaction
  正在安装    : cmake-2.8.12.2-2.el7.x86_64                     1/2 
  正在安装    : ncurses-devel-5.9-14.20130511.el7_4.x86_64      2/2 
  验证中      : ncurses-devel-5.9-14.20130511.el7_4.x86_64      1/2 
  验证中      : cmake-2.8.12.2-2.el7.x86_64                     2/2 

已安装:
  cmake.x86_64 0:2.8.12.2-2.el7                                     
  ncurses-devel.x86_64 0:5.9-14.20130511.el7_4                      

完毕!

准备安装mysql

[root@localhost lamp]# tar xzvf mysql-5.6.26.tar.gz 
……省略部分……
mysql-5.6.26/libmysqld/examples/builder-sample/images/logo.ico
mysql-5.6.26/libmysqld/examples/builder-sample/images/db.ico
mysql-5.6.26/libmysqld/examples/builder-sample/emb_samples.dfm
mysql-5.6.26/libmysqld/CMakeLists.txt
mysql-5.6.26/libmysqld/libmysqld.def
mysql-5.6.26/libmysqld/libmysqld.rc

在这里插入图片描述

cmake 编译 安装

[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    ###指定通信文件
……省略部分……
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    SYSCONFIDIR

-- Build files have been written to: /lamp/mysql-5.6.26
[root@localhost mysql-5.6.26]# make && make install
……开始等,大概要十分钟
-- Installing: /usr/local/mysql/sql-bench/bench-count-distinct
-- Installing: /usr/local/mysql/sql-bench/innotest2b
-- Installing: /usr/local/mysql/sql-bench/innotest1a
-- Installing: /usr/local/mysql/sql-bench/run-all-tests
-- Installing: /usr/local/mysql/sql-bench/innotest2
-- Installing: /usr/local/mysql/sql-bench/test-wisconsin
-- Installing: /usr/local/mysql/sql-bench/compare-results
-- Installing: /usr/local/mysql/sql-bench/bench-init.pl

复制文件进行配置

[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]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.6.26]# chmod +x /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/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

创建用户

[root@localhost mysql-5.6.26]# useradd -s /sbin/nologin mysql
useradd:用户“mysql”已存在
[root@localhost mysql-5.6.26]# id mysql
uid=27(mysql) gid=27(mysql) 组=27(mysql)
[root@localhost mysql-5.6.26]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost mysql-5.6.26]# ll /usr/local/mysql/
总用量 152
drwxr-xr-x.  2 mysql mysql   4096 8月   4 09:45 bin
-rw-r--r--.  1 mysql mysql  17987 7月  15 2015 COPYING
drwxr-xr-x.  3 mysql mysql     18 8月   4 09:45 data
drwxr-xr-x.  2 mysql mysql     55 8月   4 09:45 docs
drwxr-xr-x.  3 mysql mysql   4096 8月   4 09:45 include
-rw-r--r--.  1 mysql mysql 104897 7月  15 2015 INSTALL-BINARY
drwxr-xr-x.  3 mysql mysql   4096 8月   4 09:45 lib
drwxr-xr-x.  4 mysql mysql     30 8月   4 09:45 man
drwxr-xr-x. 10 mysql mysql   4096 8月   4 09:45 mysql-test
-rw-r--r--.  1 mysql mysql   2496 7月  15 2015 README
drwxr-xr-x.  2 mysql mysql     30 8月   4 09:45 scripts
drwxr-xr-x. 28 mysql mysql   4096 8月   4 09:45 share
drwxr-xr-x.  4 mysql mysql   4096 8月   4 09:45 sql-bench
drwxr-xr-x.  2 mysql mysql    136 8月   4 09:45 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
……省略部分……
New default config file was created as /usr/local/mysql/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

编辑启动脚本

[root@localhost mysql]# vim /etc/init.d/mysqld 

在这里插入图片描述

启动服务并设置用户密码

[root@localhost mysql]# systemctl start mysqld
Warning: mysqld.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost mysql]# systemctl daemon-reload
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# netstat -ntap | grep 3306     ## 3306为mysql端口
tcp6       0      0 :::3306                 :::*                 
   LISTEN      53488/mysqld
  Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.6.26 Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

PHP安装

安装环境

[root@localhost yum.repos.d]# yum -y install \
> gd \
> libpng \
> libpng-devel \
> pcre \
> pcre-devel \
> libxml2-devel \
> libjpeg-devel
……省略部分……
已安装:
  libjpeg-turbo-devel.x86_64 0:1.2.90-8.el7                         
  libpng-devel.x86_64 2:1.5.13-7.el7_2                              
  libxml2-devel.x86_64 0:2.9.1-6.el7.4                              

作为依赖被安装:
  xz-devel.x86_64 0:5.2.2-1.el7   zlib-devel.x86_64 0:1.2.7-18.el7  

作为依赖被升级:
  libxml2.x86_64 0:2.9.1-6.el7.4                                    
  libxml2-python.x86_64 0:2.9.1-6.el7.4                             

完毕!

配置文件 编译 安装

[root@localhost php-5.6.11]# tar xjvf php-5.6.11.tar.bz2
[root@localhost php-5.6.11]# cd 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
[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

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

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

在这里插入图片描述

验证

在这里插入图片描述

搭建论坛

[root@localhost htdocs]# mysql -u root -p
...省略内容
mysql> create database bbq;		###数据库创建   bbs
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bbq                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.00 sec)
mysql> grant all on bbq.* to 'bbquser '@'%' identified by 'asd123;	###给用户bbquser设置密码asd123并设置所有权限,所有终端都可登录'
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;	###数据库刷新
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

解压论坛安装包,设置权限

[root@localhost LAMP-C7]# unzip Discuz_X2.5_SC_UTF8.zip -d /opt/dis
[root@localhost opt]# ls
dis  httpd-2.4.29  mysql-5.6.26  php-5.6.11  rh
[root@localhost opt]# cd dis
[root@localhost dis]# ls
readme  upload  utility
[root@localhost dis]# cp -r upload/ /usr/local/httpd/htdocs/bbq
[root@localhost dis]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
bbq  index.php
[root@localhost htdocs]# ls bbq
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 htdocs]# cd bbq
[root@localhost bbq]# ls -l
...省略部分……
[root@localhost bbq]# chown -R daemon ./config
[root@localhost bbq]# chown -R daemon ./data
[root@localhost bbq]# chown -R daemon ./uc_client/
[root@localhost bbq]# chown -R daemon ./uc_server/data/

设置论坛网页

在这里插入图片描述
在这里插入图片描述
输入 20.0.0.140/bbs/admin.php 20.0.0.140是本机IP
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Ora_G/article/details/107768115