什么是LAMP
●目前最为成熟的一种企业网站应用模式,可提供动态Web
站点应用及开发环境
构成组件
●Linux、Apache、 MySQL、PHP/Perl/Python
LAMP的优势
●成本低廉
●可定制、易于开发
●方便易用、安全和稳定
apr-1.6.2.tar.gz apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2
[root@localhost ~]# iptables -F //清空防火墙
[root@localhost ~]# setenforce 0 //关闭安全功能
[root@localhost ~]# cd /opt //切换到opt目录
[root@localhost opt]# mkdir apache mysql php //创建一下部署的三个架构目录
[root@localhost opt]# ls //查看列表
apache mysql php rh
[root@localhost opt]# cd apache/
[root@localhost apache]# rz -E //把三个包复制过来
rz waiting to receive.
[root@localhost apache]# ls
apr-1.6.2.tar.gz apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2
//apr是一个库 而apr-util是apr提供的工具组 APache运行依赖这两个工具
apr-1.6.2.tar.gz //MAC记录与端口扫描脚本
apr-util-1.6.0.tar.gz //pxe.txt
httpd-2.4.29.tar.bz2 //开发系统监控脚本.txt
解压跨平台组件包和源码包
[root@localhost apache]# tar jxvf httpd-2.4.29.tar.bz2
...省略内容
[root@localhost apache]# tar zxvf apr-1.6.2.tar.gz
..省略内容
[root@localhost apache]# tar zxvf apr-util-1.6.0.tar.gz
..省略内容
[root@localhost apache]# ls //查看文件
apr-1.6.2 apr-1.6.2.tar.gz apr-util-1.6.0 apr-util-1.6.0.tar.gz httpd-2.4.29 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 apache]# ls httpd-2.4.29/srclib/
apr apr-util Makefile.in
手工安装要预先装环境
gcc 、gcc+必不可少 、make
pcre-devel:支持正则表达式
expat-devel:支持解析xml格式
perl:支持per语言
[root@localhost apache]# yum -y install \
> gcc \
> gcc-c++ \
> make \
> pcre-devel \
> expat-devel \
> perl
...省略内容
[root@localhost httpd-2.4.29]# ./configure \
> --prefix=/usr/local/httpd \ #指定路径
> --enable-so \ #默认的。支持动态共享模块 若不支持,php无法以模块方式跟Apache结合工作
> --enable-rewrite \ #开启重写功能,如防盗链保护
> --enable-charset-lite \ #开启字符集
> --enbale-cgi #开启通用网关接口
[root@localhost httpd-2.4.29]# make //编译
..省略内容
[root@localhost httpd-2.4.29]# make install //安装
...省略内容
//电脑配置较老的话这边安装比较慢 老板你可以去喝喝茶看:2看小电视
//把启动脚本放在/etc/init.d下重命名为httpd
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
//查看目录下的httpd文件
[root@localhost httpd-2.4.29]# ls /etc/init.d/
functions httpd netconsole network README
[root@localhost httpd-2.4.29]# vim httpd
[root@localhost httpd-2.4.29]# cd /etc/init.d/
[root@localhost init.d]# vim httpd
//添加下面这两行,指定服务器启动级别和开机顺序,35表示在3和5级别启动 第85启动 21关闭
//添加服务便于service识别
[root@localhost init.d]# chkconfig --add httpd
//创建http.conf配置文件的软连接到/etc下面 就可以直接边界配置文件,比较方便
[root@localhost init.d]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
[root@localhost init.d]# vim /etc/httpd.conf
//将http的命令文件创建软连接到/usr/local/bin下
[root@localhost init.d]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost init.d]# ls /usr/local/httpd/bin/
ab apxs envvars-std htdigest logresolve
apachectl checkgid fcgistarter htpasswd rotatelogs
apr-1-config dbmmanage htcacheclean httpd
apu-1-config envvars htdbm httxt2dbm
//验证语法
[root@localhost init.d]# httpd -t
Syntax OK
[root@localhost init.d]# service httpd start
[root@localhost init.d]# netstat -ntap | grep 80
tcp 0 0 20.0.0.41:80 0.0.0.0:* LISTEN 121847/httpd
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 18020/X
tcp6 0 0 :::6000 :::* LISTEN 18020/X
//服务端口是80
//切换到opt/mysql
[root@localhost ~]# cd /opt/mysql/
//把软件包复制到目录底下
[root@localhost mysql]# rz -E
rz waiting to receive.
//查看软件包
[root@localhost mysql]# ls
mysql-5.6.26.tar.gz
//ncurses-devel是字符终端下的基本库
//autoconf生成可以自动配置软件源代码
//cmake跨平台编译安装工具
[root@localhost mysql]# yum install ncurses-devel autoconf cmake -y
//解压缩
[root@localhost mysql]# tar zxvf mysql-5.6.26.tar.gz
[root@localhost mysql]# ls
//mysql-5.6.26解压后的源码包
mysql-5.6.26 mysql-5.6.26.tar.gz
[root@localhost mysql]# cd mysql-5.6.26/
[root@localhost mysql-5.6.26]# ls
BUILD Doxyfile-perfschema mysys strings
BUILD-CMAKE extra mysys_ssl support-files
client include packaging tests
cmake INSTALL-SOURCE plugin unittest
CMakeLists.txt INSTALL-WIN-SOURCE README VERSION
cmd-line-utils libevent regex vio
config.h.cmake libmysql scripts win
configure.cmake libmysqld sql zlib
COPYING libservices sql-bench
dbug man sql-common
Docs mysql-test storage
//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/ \ #指定数据文件目录,由mysql用户管理
> -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock #指定通信文件,连接数据库的必要文件
[root@localhost mysql-5.6.26]# make
...省略内容
[root@localhost mysql-5.6.26]# make install
...省略内容
//电脑配置低的话比较慢 细心等待喝喝茶
[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
//切换到init.d路径
[root@localhost mysql-5.6.26]# cd /etc/init.d/
//查看列表
[root@localhost init.d]# ls
functions httpd httpd.conf mysqld netconsole network README
//mysqld没有执行权限
[root@localhost init.d]# ll
总用量 56
-rw-r--r--. 1 root root 18281 8月 24 2018 functions
-rwxr-xr-x. 1 root root 3553 8月 3 17:52 httpd
lrwxrwxrwx. 1 root root 32 8月 3 18:22 httpd.conf -> /usr/local/httpd/conf/httpd.conf
-rw-r--r--. 1 root root 10870 8月 3 21:59 mysqld
-rwxr-xr-x. 1 root root 4569 8月 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 8月 24 2018 network
-rw-r--r--. 1 root root 1160 10月 31 2018 README
//增加权限
[root@localhost init.d]# chmod +x mysqld
//将mysqld添加到service服务器中
[root@localhost init.d]# chkconfig --add /etc/init.d/mysqld
//设置mysqld在运行级别35都开机自启动
[root@localhost init.d]# chkconfig --level 35 mysqld on
[root@localhost init.d]# vim /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
//创建用户mysql,制定shell为/sbin/nologin,这样用户就不能被用于登录linux系统
[root@localhost init.d]# useradd -s /sbin/nologin mysql
//查看mysql用户信息
[root@localhost init.d]# id mysql
uid=1001(mysql) gid=1001(mysql) 组=1001(mysql)
//因为要用mysql这个用户运行,所以要将/usr/local/mysql的所属组和属主改为mysql用户,才有写的权限
[root@localhost init.d]# chown -R mysql.mysql /usr/local/mysql
[root@localhost init.d]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin data include lib mysql-test scripts sql-bench
COPYING docs INSTALL-BINARY man README share support-files
[root@localhost mysql]# cd scripts/
[root@localhost scripts]# ls
mysql_install_db
[root@localhost scripts]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \ #指定用户 这边不创建用户就会报错
> --ldata=/var/lib/mysql \ #指定数据库文件所在位置
> --basedir=/usr/local/mysql \ #数据库服务所在位置
> --datedir=/home/mysql #数据库位置
指定两个位置
一个是服务存放位置
一个是数据存放位置
[root@localhost scripts]# vim /etc/init.d/mysqld
//设置两个服务的路径
asedir=/usr/local/mysql
datadir=/home/mysql
//重启服务
[root@localhost scripts]# service mysqld start
Starting MySQL. SUCCESS!
[root@localhost scripts]# netstat -ntap|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 2873/mysqld
//-u:用户名 -p:旧密码
[root@localhost scripts]# mysqladmin -u root -p password "abc123"
Enter password: //原本密码是空的 直接回车ok
Warning: Using a password on the command line interface can be insecure.
[root@localhost scripts]# mysql -u root -p
Enter password: //输入你设置的密码 abc123
..省略
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> exit //exit/quit都可退出
Bye
[root@localhost scripts]# yum -y install \
> gd \ #安装GD库环境 图像处理的工具
> libpng \ #由png拓展的图片
> libpng-devel \
> pcre \
> pcre-devel \
> libxml2-devel \
> libjpeg-devel
[root@localhost scripts]# cd /opt
[root@localhost opt]# ls
apache mysql php rh
[root@localhost opt]# cd php/
[root@localhost php]# ls
[root@localhost php]# rz -E #把压缩包复制过来
rz waiting to receive.
[root@localhost php]# ls #已经有了
php-5.6.11.tar.bz2
[root@localhost php]# tar jxvf php-5.6.11.tar.bz2 #解压
[root@localhost php]# ls
php-5.6.11 php-5.6.11.tar.bz2
[root@localhost php-5.6.11]# ./configure \
> --prefix=/usr/local/php5 \ #PHP的安装目录
> --with-gd \ #GD库
> --with-zlib \ #压缩函数库
> --with-apxs2=/usr/local/httpd/bin/apxs \ #设置Apache服务提供的apxs模块支持程序的文件位置
> --with-mysql=/usr/local/mysql \ #设置MySQL数据库服务程序的安装位置
> --with-config-file-path=/usr/local/php5 \ #PHP配置文件的位置
> --enable-mbstring #启用对字节字符串功能,便于支持中文等代码
[root@localhost php-5.6.11]# make
...省略内容
[root@localhost php-5.6.11]# make install
...省略内容
//移动启动脚本到安装目录下
[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini
//创建软链接让bin里面一些命令让系统所识别
[root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/
//让apache支持PHP
[root@localhost php-5.6.11]# vim /etc/httpd.conf
[root@localhost php-5.6.11]# service httpd stop
[root@localhost php-5.6.11]# service httpd start
[root@localhost php-5.6.11]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
//删除原本内容 添加以下内容
<?php
phpinfo();
?>
:wq 保存退出
[root@localhost htdocs]# mv index.html index.php
[root@localhost htdocs]# ls
index.php
[root@localhost mysql]# cd /opt
[root@localhost opt]# ls
apache mysql php rh
[root@localhost opt]# rz -E //论坛安装包直接复制过来
rz waiting to receive.
[root@localhost opt]# ls //查看一下
apache Discuz_X2.5_SC_UTF8.zip mysql php rh
[root@localhost opt]# unzip Discuz_X2.5_SC_UTF8.zip //解压缩
t@localhost opt]# ls
apache mysql readme upload
Discuz_X2.5_SC_UTF8.zip php rh utility
[root@localhost opt]# cp -r upload/ /usr/local/httpd/htdocs/bbs //把upload复制到apache工作目录站点
[root@localhost opt]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
bbs index.php
[root@localhost htdocs]# ls bbs/ //查看bbs目录
admin.php crossdomain.xml install source
api data member.php static
api.php favicon.ico misc.php template
archiver forum.php plugin.php uc_client
config group.php portal.php uc_server
connect.php home.php robots.txt userapp.php
cp.php index.php search.php
[root@localhost bbs]# ll
总用量 76
-rw-r--r--. 1 root root 2603 8月 4 08:46 admin.php
drwxr-xr-x. 11 root root 163 8月 4 08:46 api
-rw-r--r--. 1 root root 727 8月 4 08:46 api.php
drwxr-xr-x. 2 root root 23 8月 4 08:46 archiver
drwxr-xr-x. 2 root root 90 8月 4 08:46 config
-rw-r--r--. 1 root root 922 8月 4 08:46 connect.php
-rw-r--r--. 1 root root 253 8月 4 08:46 cp.php
-rw-r--r--. 1 root root 106 8月 4 08:46 crossdomain.xml
drwxr-xr-x. 13 root root 216 8月 4 08:46 data
-rw-r--r--. 1 root root 5558 8月 4 08:46 favicon.ico
-rw-r--r--. 1 root root 2110 8月 4 08:46 forum.php
-rw-r--r--. 1 root root 823 8月 4 08:46 group.php
-rw-r--r--. 1 root root 1223 8月 4 08:46 home.php
-rw-r--r--. 1 root root 5448 8月 4 08:46 index.php
drwxr-xr-x. 5 root root 64 8月 4 08:46 install
-rw-r--r--. 1 root root 1040 8月 4 08:46 member.php
-rw-r--r--. 1 root root 1381 8月 4 08:46 misc.php
-rw-r--r--. 1 root root 1757 8月 4 08:46 plugin.php
-rw-r--r--. 1 root root 985 8月 4 08:46 portal.php
-rw-r--r--. 1 root root 582 8月 4 08:46 robots.txt
-rw-r--r--. 1 root root 1158 8月 4 08:46 search.php
drwxr-xr-x. 10 root root 168 8月 4 08:46 source
drwxr-xr-x. 6 root root 72 8月 4 08:46 static
drwxr-xr-x. 3 root root 38 8月 4 08:46 template
drwxr-xr-x. 6 root root 92 8月 4 08:46 uc_client
drwxr-xr-x. 13 root root 241 8月 4 08:46 uc_server
-rw-r--r--. 1 root root 1691 8月 4 08:46 userapp.php
这边描述./conifg ./date等权限不足
[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/
[root@localhost bbs]# mysql -uroot -p //进入数据库
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
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.00 sec)
mysql> creat database bbs; //创建数据库bbs
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat database bbs' at line 1
mysql> create database bbs;
Query OK, 1 row affected (0.00 sec)
mysql> show databases; //列出当前用户可查看的所有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> use bbs; //数据库里面是空的
Database changed
mysql> show tables;
Empty set (0.00 sec)
mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123'; //提升权限指定bbs数据库所有表格给用户给任意终端远程登录 使用admin123密码
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) //刷新
选择全新安装,点击下一步
在服务器地址后面加/bbs/admin.php会到后台管理员登陆界面