博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LAMP架构
阅读量:6255 次
发布时间:2019-06-22

本文共 42475 字,大约阅读时间需要 141 分钟。

hot3.png

LAMP架构介绍

  • Linux+Apache(httpd)+MySQL+PHP
  • PHP网站(谷歌、百度、猿课、淘宝)
  • 三个角色可以在一台机器上,也可以分开(httpd+PHP必须要在一起)
  • httpd、PHP、MySQL三者如何工作

  • httpd、PHP、MySQL三者如何工作

Apache(httpd)和PHP是一个整体,PHP是以一个模块的形式和Apache(httpd)结合在一起的,Apache(httpd)不能直接和MySQL通信,只能通过PHP模块连接MySQL传递数据,然后PHP模块将搜集到数据传递Apache(httpd),Apache(httpd)再讲数据传递给用户。这种行为叫做动态请求。

用户浏览器通过Apache(httpd)访问网站上一些静态的文件(图片),然后返回给用户,并没有通过MySQL,叫静态请求。MySQL里面存储数据,并不存储图片信息。


MySQL/Mariadb介绍

  • MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2018年被sun公司收购,2009年sun公司被oracle公司收购
  • MySQL官网:
  • Mariadb 为MySQL的一个分支,官网
  • Maridb主要由SKySQL公司(现更名为Mariadb公司)
  • Community社区版本,Enterprise企业版,GA(Generally Available)指的是通用版本,在生产环境中用的,DMR(Development Milestone Release)开发里程碑发布版,RC(Release Candidarte)发行候选版本,Beta开放测试版本,Alpha 内部测试版本

MySQL安装

安装MySQL

  • MySQL的几个常用的安装包:rpm、源码包、二进制免编译
  • cd /usr/local/src 源码包及资源存放在此目录下
  • wget MySQL二进制包下载地址
  • tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
  • mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
  • cd /usr/local/mysql
  • useradd mysql
  • mkdir /data/
  • ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
  • cp support-files/my-default.cnf /etc/my.cnf
  • cp support-files/mysql.server /etc/init.d/mysqld
  • vi /etc/init.d/mysqld
  • 定义basedir和datadir
  • /etc/init.d/mysqld start

安装MySQL思路

  1. 将二进制包下载到/usr/local/src目录下
  2. 解压下载的二进制包
  3. 移动解压完的二进制目录包至 /usr/local/下 并将二进制包的名字更改为mysql
  4. 进入 /usr/local/mysql 目录中,创建一个mysql用户,创建data目录(为了存放mysql数据)
  5. 初始化完成
  6. 拷贝编辑配置文件和启动脚本
  7. 启动MySQL

[root@xuexi-001 ~]# cd /usr/local/src/······//进入到src目录下[root@xuexi-001 src]# ls······//查看当前目录下的文件mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# tar -zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz······//解压下载好的Mysql文件[root@xuexi-001 src]# lsmysql-5.6.36-linux-glibc2.5-x86_64  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql······//移动mysql-5.6.36-linux-glibc2.5-x86_64目录至/usr/local/下并改名字为 mysql[root@xuexi-001 src]# cd /usr/local/mysql/[root@xuexi-001 mysql]# lsbin      data  include  man         README   share      support-filesCOPYING  docs  lib      mysql-test  scripts  sql-bench[root@xuexi-001 mysql]# useradd mysql[root@xuexi-001 mysql]# mkdir /data/ [root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql······//执行初始化FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper······ //报错 提示错误信息,缺少perl和Dumper包[root@xuexi-001 mysql]# yum list |grep perl |grep -i dumper······//进行模糊搜索 grep -i 忽略大小写perl-Data-Dumper.x86_64                  2.145-3.el7                   base     perl-Data-Dumper-Concise.noarch          2.020-6.el7                   epel     perl-Data-Dumper-Names.noarch            0.03-17.el7                   epel     perl-XML-Dumper.noarch                   0.81-17.el7                   base  ······//在不确认是依赖于哪个包的情况下 这几个包都安装上,这里需要安装的包是 perl-Data-Dumper[root@xuexi-001 mysql]# yum install -y perl-Data-Dumper[root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql······ //执行初始化 提示报错信息,缺少libaioInstalling MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory[root@xuexi-001 mysql]# yum install -y libaio······//安装libaio这个包[root@xuexi-001 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql······ //执行初始化成功Installing MySQL system tables...2018-06-23 00:22:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2018-06-23 00:22:31 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2018-06-23 00:22:31 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3004 ...2018-06-23 00:22:31 3004 [Note] InnoDB: Using atomics to ref count buffer pool pages2018-06-23 00:22:31 3004 [Note] InnoDB: The InnoDB memory heap is disabled2018-06-23 00:22:31 3004 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2018-06-23 00:22:31 3004 [Note] InnoDB: Memory barrier is not used2018-06-23 00:22:31 3004 [Note] InnoDB: Compressed tables use zlib 1.2.32018-06-23 00:22:31 3004 [Note] InnoDB: Using Linux native AIO2018-06-23 00:22:31 3004 [Note] InnoDB: Using CPU crc32 instructions2018-06-23 00:22:31 3004 [Note] InnoDB: Initializing buffer pool, size = 128.0M2018-06-23 00:22:31 3004 [Note] InnoDB: Completed initialization of buffer pool2018-06-23 00:22:31 3004 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!2018-06-23 00:22:31 3004 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB2018-06-23 00:22:31 3004 [Note] InnoDB: Database physically writes the file full: wait...2018-06-23 00:22:31 3004 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB2018-06-23 00:22:32 3004 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2018-06-23 00:22:33 3004 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02018-06-23 00:22:33 3004 [Warning] InnoDB: New log files created, LSN=457812018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer not found: creating new2018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer created2018-06-23 00:22:33 3004 [Note] InnoDB: 128 rollback segment(s) are active.2018-06-23 00:22:33 3004 [Warning] InnoDB: Creating foreign key constraint system tables.2018-06-23 00:22:33 3004 [Note] InnoDB: Foreign key constraint system tables created2018-06-23 00:22:33 3004 [Note] InnoDB: Creating tablespace and datafile system tables.2018-06-23 00:22:33 3004 [Note] InnoDB: Tablespace and datafile system tables created.2018-06-23 00:22:33 3004 [Note] InnoDB: Waiting for purge to start2018-06-23 00:22:33 3004 [Note] InnoDB: 5.6.36 started; log sequence number 02018-06-23 00:22:33 3004 [Note] Binlog end2018-06-23 00:22:33 3004 [Note] InnoDB: FTS optimize thread exiting.2018-06-23 00:22:33 3004 [Note] InnoDB: Starting shutdown...2018-06-23 00:22:35 3004 [Note] InnoDB: Shutdown completed; log sequence number 1625977OK·····//第一个Filling help tables...2018-06-23 00:22:35 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2018-06-23 00:22:35 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.2018-06-23 00:22:35 0 [Note] ./bin/mysqld (mysqld 5.6.36) starting as process 3026 ...2018-06-23 00:22:35 3026 [Note] InnoDB: Using atomics to ref count buffer pool pages2018-06-23 00:22:35 3026 [Note] InnoDB: The InnoDB memory heap is disabled2018-06-23 00:22:35 3026 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2018-06-23 00:22:35 3026 [Note] InnoDB: Memory barrier is not used2018-06-23 00:22:35 3026 [Note] InnoDB: Compressed tables use zlib 1.2.32018-06-23 00:22:35 3026 [Note] InnoDB: Using Linux native AIO2018-06-23 00:22:35 3026 [Note] InnoDB: Using CPU crc32 instructions2018-06-23 00:22:35 3026 [Note] InnoDB: Initializing buffer pool, size = 128.0M2018-06-23 00:22:35 3026 [Note] InnoDB: Completed initialization of buffer pool2018-06-23 00:22:35 3026 [Note] InnoDB: Highest supported file format is Barracuda.2018-06-23 00:22:35 3026 [Note] InnoDB: 128 rollback segment(s) are active.2018-06-23 00:22:35 3026 [Note] InnoDB: Waiting for purge to start2018-06-23 00:22:35 3026 [Note] InnoDB: 5.6.36 started; log sequence number 16259772018-06-23 00:22:35 3026 [Note] Binlog end2018-06-23 00:22:35 3026 [Note] InnoDB: FTS optimize thread exiting.2018-06-23 00:22:35 3026 [Note] InnoDB: Starting shutdown...2018-06-23 00:22:37 3026 [Note] InnoDB: Shutdown completed; log sequence number 1625987OK······//第二个To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:  ./bin/mysqladmin -u root password 'new-password'  ./bin/mysqladmin -u root -h xuexi-001 password 'new-password'Alternatively you can run:  ./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:  cd . ; ./bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.pl  cd mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web at  http://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comWARNING: Found existing config file ./my.cnf on the system.Because this file might be in use, it was not replaced,but was used in bootstrap (unless you used --defaults-file)and when you later start the server.The new default config file was created as ./my-new.cnf,please compare it with your file and take the changes you need.WARNING: Default config file /etc/my.cnf exists on the systemThis file will be read by default by the MySQL serverIf you do not want to use this, either remove it, or use the--defaults-file argument to mysqld_safe when starting the server····· //检查执行是否成功,检查文件里面有两个OK。另一种方法 使用echo $?  看看结果是否是0[root@xuexi-001 mysql]# echo $?0[root@xuexi-001 mysql]# ls support-files/my-default.cnf support-files/my-default.cnf······//mysql模板配置文件[root@xuexi-001 mysql]# cp support-files/my-default.cnf /etc/my.cnf······ // mysql的配置文件叫 my.cnf 而且是固定在/etc/目录下[root@xuexi-001 mysql]# ls /etc/my.cnf/etc/my.cnf······// 系统中有一个自带的/etc/my.cnf如果想使用自带的my.cnf 需要更改里面的配置文件内容[root@xuexi-001 mysql]# vi /etc/my.cnf[mysqld]datadir=/data/mysql······// 需要更改mysql路径socket=/tmp/mysql.sock······//socket改为/tmp/下# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.# If you need to run mysqld under a different user or group,# customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]#log-error=/var/log/mariadb/mariadb.log#pid-file=/var/run/mariadb/mariadb.pid······//后面这两行内容暂时不用可以注释## include all files from the config directory##!includedir /etc/my.cnf.d······//配置文件完成后,需要拷贝启动脚本[root@xuexi-001 mysql]# cp support-files/mysql.server /etc/init.d/mysqld······//将启动脚本文件拷贝至/etc/init.d/下并改名为mysqld[root@xuexi-001 mysql]# vi /etc/init.d/mysqld ······//编辑启动脚本文件#!/bin/sh# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB# This file is public domain and comes with NO WARRANTY of any kind# MySQL daemon start/stop script.······# If you change base dir, you must also change datadir. These may get# overwritten by settings in the MySQL configuration files.basedir=/usr/local/mysqldatadir=/data/mysql······//需要更改的两个地方# Default value, in seconds, afterwhich the script should timeout waiting# for server start. ······[root@xuexi-001 mysql]# chmod 755 /etc/init.d/mysqld ······//赋予755权限,默认权限为755[root@xuexi-001 mysql]# ls -l /etc/init.d/mysqld -rwxr-xr-x 1 root root 10592 6月  23 00:51 /etc/init.d/mysqld[root@xuexi-001 mysql]# chkconfig --add mysqld······//设置开机启动,须将mysqld加入到系统服务启动列表中[root@xuexi-001 mysql]# chkconfig --list\注:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。       要列出 systemd 服务,请执行 'systemctl list-unit-files'。      查看在具体 target 启用的服务请执行      'systemctl list-dependencies [target]'。mysqld         	0:关	1:关	2:开	3:开	4:开	5:开	6:关netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关······//查看系统服务启动列表其他方式启动[root@xuexi-001 mysql]# service mysqld start[root@xuexi-001 mysql]# /etc/init.d/mysqld start······[root@xuexi-001 mysql]# service mysqld startStarting MySQL.Logging to '/data/mysql/xuexi-001.err'.. SUCCESS! [root@xuexi-001 mysql]# ps aux |grep mysql······//查看启动的进程root       3652  0.0  0.0  11772  1604 pts/0    S    01:10   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pidmysql      3789  0.8 24.0 1300780 449572 pts/0  Sl   01:10   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sockroot       3831  0.0  0.0 112676   980 pts/0    R+   01:12   0:00 grep --color=auto mysql[root@xuexi-001 mysql]# netstat -lntp······//查看监听的端口Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      934/sshd            tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1136/master         tcp6       0      0 :::22                   :::*                    LISTEN      934/sshd            tcp6       0      0 ::1:25                  :::*                    LISTEN      1136/master         tcp6       0      0 :::3306                 :::*                    LISTEN      3789/mysqld         如果没有将启动脚本/etc/init.d/下或者没有启动脚本可以使用以下方法启动(命令行启动)[root@xuexi-001 mysql]# service mysqld stopShutting down MySQL.. SUCCESS! ······//停止mysql服务[root@xuexi-001 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &[1] 4112[root@xuexi-001 mysql]# 180623 01:23:00 mysqld_safe Logging to '/data/mysql/xuexi-001.err'.180623 01:23:00 mysqld_safe Starting mysqld daemon with databases from /data/mysql^C······//使用命令行启动服务[root@xuexi-001 mysql]# !ps······//查看启动进程ps aux | grep mysqlroot       4112  0.0  0.0 113260  1616 pts/0    S    01:22   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysqlmysql      4237  1.9 24.0 1300780 449536 pts/0  Sl   01:22   0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sockroot       4260  0.0  0.0 112676   984 pts/0    R+   01:23   0:00 grep --color=auto mysql
# --defaults-file=/etc/my.cnf ·····//指定配置文件所在的路径

如果使用命令行的模式启动的mysql,要想关闭Mysql就需要使用killall mysqld

[root@xuexi-001 mysql]# killall mysqld[root@xuexi-001 mysql]# 180623 01:27:33 mysqld_safe mysqld from pid file /data/mysql/xuexi-001.pid ended[1]+  完成                  /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql[root@xuexi-001 mysql]# !psps aux | grep mysqlroot       4308  0.0  0.0 112676   980 pts/0    R+   01:27   0:00 grep --color=auto mysql

不到万不得已不要使用kill ,可使用kill + pid 数据传输过程中强制杀死会造成数据的丢失以及磁盘的损坏 ,最好使用killall + 服务名称 ,killall相对安全。使用killall会先停止当前的写读操作,然后将没有写入到磁盘的数据慢慢写入到磁盘中去,直到数据传输完成,才把进程杀死。

# 如果遇到mysql 进程始终杀不死,ps 还会有进程,说明数据量很大正在写入磁盘,不能强制杀死使用Kill -9 , 有可能丢数据甚至损坏表。只能等着数据传输完成。

安装Mariadb

  • cd /usr/local/src
  • wget
  • tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  • cd /usr/local/mariadb
  • ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
  • cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  • vi /usr/local/mariadb/my.cnf
  • //定义basedir和datadir
  • cp support-files/mysql.server /etc/init.d/mariadb
  • vim /etc/init.d/mariadb //定义basedir、datadir、conf以及启动参数
  • /etc/init.d/mariadb start

安装mariadb 思路

  1. 切换到目录 /usr/local/src
  2. 下载mariadb 并解压
  3. 将解压后的目录文件移动到/usr/local/mariadb并改名为mariadb
  4. 创建mysql用户,/data/mariadb 并执行初始化
  5. 拷贝配置文件cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  6. 拷贝启动脚本 cp support-files/mysql.server /etc/init.d/mariadb
  7. vim /etc/init.d/mariadb //定义basedir、datadir、conf以及启动参数

basedir=/usr/local/mariadb

datadir=/data/mariadb

conf=/usr/local/mariadb

  1. 启动 mariadb /etc/init.d/mariadb start

操作演示

[root@xuexi-001 ~]# cd /usr/local/src/[root@xuexi-001 src]# lsmariadb-10.2.6-linux-glibc_214-x86_64.tar.gzmysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# tar -zxvf mariadb-10.2.6-linux-glibc_214-x86_64[root@xuexi-001 src]# lsmariadb-10.2.6-linux-glibc_214-x86_64mariadb-10.2.6-linux-glibc_214-x86_64.tar.gzmysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb[root@xuexi-001 src]# cd /usr/local/mariadb/[root@xuexi-001 mariadb]# lsbin                 DESTINATION        lib           scriptsCOPYING             docs               man           shareCOPYING.thirdparty  EXCEPTIONS-CLIENT  mysql-test    sql-benchCREDITS             include            README.md     support-filesdata                INSTALL-BINARY     README-wsrep[root@xuexi-001 mariadb]# useradd mysql[root@xuexi-001 mariadb]# mkdir /data/[root@xuexi-001 mariadb]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadbInstalling MariaDB/MySQL system tables in '/data/mariadb' ...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !To do so, start the server, then issue the following commands:'/usr/local/mariadb//bin/mysqladmin' -u root password 'new-password''/usr/local/mariadb//bin/mysqladmin' -u root -h xuexi-001 password 'new-password'Alternatively you can run:'/usr/local/mariadb//bin/mysql_secure_installation'which will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the MariaDB Knowledgebase at http://mariadb.com/kb or theMySQL manual for more instructions.You can start the MariaDB daemon with:cd '/usr/local/mariadb/' ; /usr/local/mariadb//bin/mysqld_safe --datadir='/data/mariadb'You can test the MariaDB daemon with mysql-test-run.plcd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.plPlease report any problems at http://mariadb.org/jiraThe latest information about MariaDB is available at http://mariadb.org/.You can find additional information about the MySQL part at:http://dev.mysql.comConsider joining MariaDB's strong and vibrant community:https://mariadb.org/get-involved/[root@xuexi-001 mariadb]# echo $?0[root@xuexi-001 mariadb]# ls support-files/binary-configure        my-large.cnf         mysql-log-rotate  wsrep_notifymagic                   my-medium.cnf        mysql.servermy-huge.cnf             my-small.cnf         policymy-innodb-heavy-4G.cnf  mysqld_multi.server  wsrep.cnf[root@xuexi-001 mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf[root@xuexi-001 mariadb]# cp support-files/mysql.server /etc/init.d/mariadb[root@xuexi-001 mariadb]# vi /etc/init.d/mariadbbasedir=/usr/local/mariadbdatadir=/data/mariadbconf=/usr/local/mariadb/my.cnf······ //需要修改的配置内容$bindir/mysqld_safe --defarults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &······ //需要修改的配置内容[root@xuexi-001 mariadb]# service mariadb startReloading systemd:                                         [  确定  ]Starting mariadb (via systemctl):                          [  确定  ][root@xuexi-001 mariadb]# ps aux |grep mariadbroot       2099  0.0  0.0 115388  1752 ?        S    21:47   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pidmysql      2215  3.8  3.0 1125124 56608 ?       Sl   21:47   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/xuexi-001.err --pid-file=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306root       2257  0.0  0.0 112676   984 pts/0    R+   21:48   0:00 grep --color=auto mariadb[root@xuexi-001 mariadb]# netstat -ltnpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      919/sshd            tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1264/master         tcp6       0      0 :::22                   :::*                    LISTEN      919/sshd            tcp6       0      0 ::1:25                  :::*                    LISTEN      1264/master         tcp6       0      0 :::3306                 :::*                    LISTEN      2215/mysqld

出现的问题:

[root@xuexi-001 mariadb]# ps aux |grep mariadbroot       2099  0.0  0.0 115388  1752 ?        S    21:47   0:00 /bin/sh /usry.cnf --datadir=/data/mysql --pid-file=/data/mysql/xuexi-001.pidmysql      2215  0.2  3.4 1125124 64252 ?       Sl   21:47   0:00 /usr/local/mir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/liile=/data/mysql/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306root       2311  0.0  0.0 112676   984 pts/0    R+   21:54   0:00 grep --color

在以上操作过程中指定了datadir=/data/mariadb 这里显示的是--datadir=/data/mysql

解决这个问提需要在Mariadb 配置文件中增加 datadir=/data/mariadb 因为同时启用了MySQL和mariadb 系统会从/etc/my.cnf中寻找

[root@xuexi-001 mariadb]# vi /usr/local/mariadb/my.cnf[mysqld]datadir = /data/mariadb······//增加这一行
[root@xuexi-001 mariadb]# killall mysqld······//先关掉mysql 服务[root@xuexi-001 mariadb]# service mariadb startStarting mariadb (via systemctl):                          [  确定  ][root@xuexi-001 mariadb]# ps aux | grep mariadbroot       2757  0.0  0.0 115388  1748 ?        S    22:11   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/xuexi-001.pidmysql      2876  1.3  3.1 1125024 59228 ?       Sl   22:11   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/xuexi-001.err --pid-file=/data/mariadb/xuexi-001.pid --socket=/tmp/mysql.sock --port=3306root       2912  0.0  0.0 112676   984 pts/0    R+   22:11   0:00 grep --color=auto mariadb

Apache 安装

  • Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache
  • Apache官网www.apache.org
  • wget
  • wget
  • wget
  • apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
  • tar zxvf httpd-2.4.33.tar.gz
  • tar zxvf apr-util-1.5.4.tar.gz
  • tar zxvf apr-1.5.2.tar.gz
  • cd /usr/local/src/apr-1.5.2
  • ./configure --prefix=/usr/local/apr
  • make && make install
  • cd /usr/local/src/apr-util-1.5.4
  • ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  • make && make install
  • cd /usr/local/src/httpd-2.4.33
  • ./configure \ //这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
  • --prefix=/usr/local/apache2.4 \
  • --with-apr=/usr/local/apr \
  • --with-apr-util=/usr/local/apr-util \
  • --enable-so \ 支持动态模块
  • --enable-mods-shared=most
  • make && make install
  • ls /usr/local/apache2.4/modules
  • /usr/local/apache2.4/bin/httpd -M //查看加载的模块

Apache 安装思路

  1. 先下载好软件包,并解压
  2. 首先安装apr

./configure --prefix=/usr/local/apr

make && make install

  1. 再安装apr-util

./configure

--prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

  1. 安装httpd

./configure

--prefix=/usr/local/apache2.4

--with-apr=/usr/local/apr

--with-apr-util=/usr/local/apr-util

--enable-so

--enable-mods-shared=most

make && make install


操作演示

安装apr

[root@xuexi-001 ~]# cd /usr/local/src/[root@xuexi-001 src]# lsapr-1.6.3.tar.gz       httpd-2.4.33.tar.gzmariadb-10.2.6-linux-glibc_214-x86_64.tar.gzapr-util-1.5.4.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# tar -zxvf apr-1.6.3.tar.gz [root@xuexi-001 src]# tar -zxvf apr-util-1.5.4.tar.gz [root@xuexi-001 src]# tar -zxvf httpd-2.4.33.tar.gz [root@xuexi-001 src]# lsapr-1.6.3              httpd-2.4.33apr-1.6.3.tar.gz       httpd-2.4.33.tar.gzapr-util-1.5.4         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gzapr-util-1.5.4.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# cd apr-1.6.3[root@xuexi-001 apr-1.6.3]# lsapr-config.in  build-outputs.mk  helpers       misc           stringsapr.dep        CHANGES           include       mmap           supportapr.dsp        CMakeLists.txt    libapr.dep    network_io     tablesapr.dsw        config.layout     libapr.dsp    NOTICE         testapr.mak        configure         libapr.mak    NWGNUmakefile  threadprocapr.pc.in      configure.in      libapr.rc     passwd         timeapr.spec       docs              LICENSE       poll           toolsatomic         dso               locks         random         userbuild          emacs-mode        Makefile.in   READMEbuildconf      encoding          Makefile.win  README.cmakebuild.conf     file_io           memory        shmem[root@xuexi-001 apr-1.6.3]# ./configure --prefix=/usr/local/apr[root@xuexi-001 apr-1.6.3]# echo $?0[root@xuexi-001 apr-1.6.3]# make &&  make install[root@xuexi-001 apr-1.6.3]# echo $?0

安装apr-util

[root@xuexi-001 src]# cd apr-util-1.5.4[root@xuexi-001 apr-util-1.5.4]# lsaprutil.dep       CHANGES            include         NWGNUmakefileaprutil.dsp       CMakeLists.txt     ldap            READMEaprutil.dsw       config.layout      libaprutil.dep  README.cmakeaprutil.mak       configure          libaprutil.dsp  renames_pendingapr-util.pc.in    configure.in       libaprutil.mak  strmatchapr-util.spec     crypto             libaprutil.rc   testapu-config.in     dbd                LICENSE         uribuckets           dbm                Makefile.in     xlatebuild             docs               Makefile.win    xmlbuildconf         encoding           memcachebuild.conf        export_vars.sh.in  miscbuild-outputs.mk  hooks              NOTICE[root@xuexi-001 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/[root@xuexi-001 apr-util-1.5.4]# echo $?0[root@xuexi-001 apr-util-1.6.1]# make && make installxml/apr_xml.c:35:19: 致命错误:expat.h:没有那个文件或目录 #include 
yum -y install libtool libtool-ltdl-devel.x86_64 expat-devel pcre.x86_64 pcre-devel.x86_64 gcc

安装httpd

[root@xuexi-001 ~]# cd /usr/local/src/[root@xuexi-001 src]# lsapr-1.6.3              httpd-2.4.33apr-1.6.3.tar.gz       httpd-2.4.33.tar.gzapr-util-1.5.4         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gzapr-util-1.5.4.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz[root@xuexi-001 src]# cd httpd-2.4.33[root@xuexi-001 httpd-2.4.33]# lsABOUT_APACHE     CMakeLists.txt  INSTALL         NWGNUmakefileacinclude.m4     config.layout   InstallBin.dsp  osApache-apr2.dsw  configure       LAYOUT          READMEApache.dsw       configure.in    libhttpd.dep    README.cmakeapache_probes.d  docs            libhttpd.dsp    README.platformsap.d             emacs-style     libhttpd.mak    ROADMAPbuild            httpd.dep       LICENSE         serverBuildAll.dsp     httpd.dsp       Makefile.in     srclibBuildBin.dsp     httpd.mak       Makefile.win    supportbuildconf        httpd.spec      modules         testCHANGES          include         NOTICE          VERSIONING[root@xuexi-001 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most[root@xuexi-001 httpd-2.4.33]# make [root@xuexi-001 httpd-2.4.33]# make install

启动服务

[root@xuexi-001 httpd-2.4.33]# cd /usr/local/apache2/······//切换到apache2目录下[root@xuexi-001 apache2]# lsbin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules······// 注:较常用目录bin(可执行文件存放目录)、conf(配置文件所在目录)、htdocs(存放一个访问页)、logs(日志文件存放目录)、modules(存放扩展模块)。 查看Apache所加载的模块:root@xuexi-001 apache2]# /usr/local/apache2/bin/apachectl -M或者使用[root@xuexi-001 apache2]# /usr/local/apache2/bin/httpd -MAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this messageLoaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) ······//AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::65d2:adc:20d3:8c74. Set the 'ServerName' directive globally to suppress this message#此处错误提示没影响。启动:[root@xuexi-001 apache2]# /usr/local/apache2/bin/apachectl startAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this message检测状态:[root@xuexi-001 apache2]# ps aux | grep httpdroot      53115  0.0  0.1  95580  2528 ?        Ss   23:21   0:00 /usr/local/apache2/bin/httpd -k startdaemon    53116  0.4  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k startdaemon    53117  0.0  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k startdaemon    53118  0.2  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k startroot      53201  0.0  0.0 112720   972 pts/0    R+   23:22   0:00 grep --color=auto httpd[root@xuexi-001 apache2]# netstat -lntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      922/sshd            tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1275/master         tcp6       0      0 :::80                   :::*                    LISTEN      53115/httpd         tcp6       0      0 :::22                   :::*                    LISTEN      922/sshd            tcp6       0      0 ::1:25                  :::*                    LISTEN      1275/master

安装中出现的错误:

[root@xuexi-001 apr-1.6.3]# ./configure --prefix=/usr/local/aprchecking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking target system type... x86_64-pc-linux-gnuConfiguring APR libraryPlatform: x86_64-pc-linux-gnuchecking for working mkdir -p... yesAPR Version: 1.6.3checking for chosen layout... aprchecking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: in `/usr/local/src/apr-1.6.3':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more details······// 没有安装gcc语言编译器需要安装gcc[root@xuexi-001 apr-1.6.3]# yum install -y gcc
collect2: error: ld returned 1 exit statusmake[2]: *** [htpasswd] 错误 1make[2]: 离开目录“/usr/local/src/httpd-2.4.33/support”make[1]: *** [all-recursive] 错误 1make[1]: 离开目录“/usr/local/src/httpd-2.4.33/support”make: *** [all-recursive] 错误 1[root@xuexi-001 httpd-2.4.33]# yum install -y libxml2-devel说明:缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持[root@xuexi-001 ~]# rm -rf /usr/local/apr-util/[root@xuexi-001 ~]# cd /usr/local/src/apr-util-1.6.1[root@xuexi-001 apr-util-1.6.1]# make clean······// 安装完libxml2-devel 包之后,需要删除apr-util 文件以及清除缓存,并重新安装apr-util[root@xuexi-001 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[root@xuexi-001 apr-util-1.6.1]# make && make install······//还需要重新编译httpd 也是需要先清除缓存,方法同上[root@xuexi-001 src]# cd httpd-2.4.33[root@xuexi-001 httpd-2.4.33]# make clean[root@xuexi-001 httpd-2.4.33]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most[root@xuexi-001 httpd-2.4.33]# make[root@xuexi-001 httpd-2.4.33]# make install

PHP 5

  • PHP官网www.php.net
  • 当前主流版本为5.6/7.1
  • cd /usr/local/src/
  • wget
  • tar zxf php-5.6.36.tar.gz
  • cd php-5.6.36
  • ./configure--prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  • make && make install
  • cp php.ini-production /usr/local/php/etc/php.ini

PHP5 的安装

[root@xuexi-001 ~]# cd /usr/local/src/[root@xuexi-001 src]# lsapr-1.6.3         apr-util-1.6.1.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gzapr-1.6.3.tar.gz  httpd-2.4.33           mysql-5.6.36-linux-glibc2.5-x86_64.tar.gzapr-util-1.6.1    httpd-2.4.33.tar.gz    php-5.6.36.tar.bz2[root@xuexi-001 src]# tar -zxvf php-5.6.36.tar.gz [root@xuexi-001 src]# lsapr-1.6.3              httpd-2.4.33                                  php-5.6.36apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gzapr-util-1.6.1         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gzapr-util-1.6.1.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@xuexi-001 php-5.6.36]#   ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc  --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif [root@xuexi-001 php-5.6.36]# make && make install [root@xuexi-001 php-5.6.36]# ls -l /usr/local/apache2/modules/libphp5.so -rwxr-xr-x 1 root root 37744104 6月  25 01:01 /usr/local/apache2/modules/libphp5.so······//PHP模块文件 [root@xuexi-001 php-5.6.36]# vi /usr/local/apache2/conf/httpd.conf ······//apache 的配置文件  [root@xuexi-001 php-5.6.36]# cp php.ini-production  /usr/local/php/etc/php.ini

报错:configure: error: Cannot find OpenSSL's <evp.h>

解决: [root@xuexi-001 php-5.6.36]# yum install -y openssl-devel.x86_64

报错: configure: error: Please reinstall the BZip2 distribution

解决: [root@xuexi-001 php-5.6.36]# yum install -y bzip2-devel

报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> configure: error: jpeglib.h not found.

解决: [root@xuexi-001 php-5.6.36]# yum install -y libjpeg-devel

报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes configure: error: png.h not found.

解决: [root@xuexi-001 php-5.6.36]# yum install -y libpng-devel

报错: checking whether to enable JIS-mapped Japanese font support in GD... no If configure fails try --with-vpx-dir=<DIR> checking for jpeg_read_header in -ljpeg... yes checking for png_write_image in -lpng... yes If configure fails try --with-xpm-dir=<DIR> configure: error: freetype-config not found.

解决: [root@xuexi-001 php-5.6.36]# yum install -y freetype-devel

报错: configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决: [root@xuexi-001 php-5.6.36]# yum install -y epel-release [root@xuexi-001 php-5.6.36]# yum install -y libmcrypt-devel

PHP 7安装

  • cd /usr/local/src/
  • wget
  • tar jxvf php-7.1.6.tar.bz2
  • cd php-7.1.6
  • ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  • make && make install
  • ls /usr/local/apache2.4/modules/libphp7.so
  • cp php.ini-production /usr/local/php7/etc/php.ini

[root@xuexi-001 ~]# cd /usr/local/src/[root@xuexi-001 src]# lsapr-1.6.3              httpd-2.4.33                                  php-5.6.36apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gzapr-util-1.6.1         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  apr-util-1.6.1.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz     php-7.1.6.tar.bz2[root@xuexi-001 src]# tar -jxvf php-7.1.6.tar.bz2 [root@xuexi-001 src]# lsapr-1.6.3              httpd-2.4.33                                  php-5.6.36apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gzapr-util-1.6.1         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  php-7.1.6apr-util-1.6.1.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz     php-7.1.6.tar.bz2[root@xuexi-001 src]# cd php-7.1.6[root@xuexi-001 php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc  --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif[root@xuexi-001 php-7.1.6]# make && make install[root@xuexi-001 php-7.1.6]# cp php.ini-production  /usr/local/php7/etc/php.ini查看加载的模块:[root@xuexi-001 php-7.1.6]# /usr/local/php7/bin/php -m[PHP Modules]bz2CorectypedatedomexiffileinfofiltergdhashiconvjsonlibxmlmbstringmcryptmysqliopensslpcrePDOpdo_mysqlpdo_sqlitePharposixReflectionsessionSimpleXMLsoapsocketsSPLsqlite3standardtokenizerxmlxmlreaderxmlwriterzlib[Zend Modules]
[root@xuexi-001 php-7.1.6]# vi /usr/local/apache2/conf/httpd.conf······//如果不想用哪个就在配置文件前面加# 注释掉LoadModule php5_module        modules/libphp5.soLoadModule php7_module        modules/libphp7.so

Apache和php结合

配置httpd支持php

  • httpd主配置文件/usr/local/apache2/conf/httpd.conf
  • vim /usr/local/apache2/conf/httpd.conf //修改以下4个地方
  • ServerName
  • Require all denied
  • AddType application/x-httpd-php .php
  • DirectoryIndex index.html index.php
  • /usr/local/apache2.4/bin/apachectl -t //测试语法
  • /usr/local/apache2.4/bin/apachectl start //启动服务
  • netstat -lntp
  • curl localhost
  • vim /usr/local/apache2.4/htodcs/test.php //增加如下内容
  • <?php

  • echo 123;
  • ?>
  • curl localhost/test.php

#去除此段警告提示// 修改配置文件第一处

[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl restartAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9625:3e1d:12c7:4fe6. Set the 'ServerName' directive globally to suppress this message
[root@xuexi-001 ~]# vim /usr/local/apache2/conf/httpd.conf #ServerName www.example.com:80此处的# 删除改为ServerName www.example.com:80[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl restarthttpd not running, trying to start/usr/local/apache2/bin/apachectl: 行 79:  1563 段错误               $HTTPD -k $ARGV提示错误信息,此时需要将安装好的PHP5和PHP7中两个中的一个关掉,不能同时开启两个PHP.[root@xuexi-001 ~]# vim /usr/local/apache2/conf/httpd.confLoadModule php5_module        modules/libphp5.so#LoadModule php7_module        modules/libphp7.so[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl starthttpd (pid 1591) already running[root@xuexi-001 ~]# ps aux |grep httpdroot       1591  0.0  0.4 255720  8868 ?        Ss   16:09   0:00 /usr/local/apache2/bin/httpd -k restartdaemon     1592  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restartdaemon     1593  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restartdaemon     1594  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restartroot       1685  0.0  0.0 112720   968 pts/0    R+   16:10   0:00 grep --color=auto httpd

#修改配置文件第二处

1.首先访问网站,直接输入IP ---> 显示无法访问,先检查网络是否通。

检查网络是否通。网络可以Ping通,网络没有问题
C:\Users\Administrator>ping 192.168.5.130正在 Ping 192.168.5.130 具有 32 字节的数据:来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64来自 192.168.5.130 的回复: 字节=32 时间<1ms TTL=64192.168.5.130 的 Ping 统计信息:    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位):    最短 = 0ms,最长 = 0ms,平均 = 0ms

2.检查80端口是否通,首先打开windows上telnet服务

测试80端口是否通,80端口不通

3.在linux 虚拟机上设定一条规则 临时添加80端口

[root@xuexi-001 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT

4.在windows 上测试80端口。显示这种It works!代表80端口已经通了

5.打开网页测试。网页测试成功

防止在打开虚拟主机配置文件的时候显示403

[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.confRequire all denied······// 将此处 denied 修改为 granted[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -tSyntax OK······//检查配置文件语法是否正确[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful·······//`重新加载配置文件,并不会重启。

#修改配置文件第三处

增加一行 与php相关的配置

AddType application/x-httpd-php .php

[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf     AddType application/x-compress .Z    AddType application/x-gzip .gz .tgz······//在配置文件中找到这两行,在这两行后面加入下面这一行有关PHP的,帮助PHP解析。    AddType application/x-httpd-php .php
#修改配置文件第四处

添加内容(索引页)

在配置文件内容找到DirectoryIndex index.html ,这后面加入 index.php ,改为 DirectoryIndex index.html index.php

[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.conf 
DirectoryIndex index.html index.php[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -tSyntax OK[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful······// 检查配置文件,并重新加载配置文件

验证Apache 支持不支持解析PHP

先写一个PHP的脚本

[root@xuexi-001 ~]# vi /usr/local/apache2/htdocs/1.php
~

访问 : 192.168.5.130/1.php

如果PHP 没有被解析,需要从以下几点排查问题

1.查看PHP模块有没有加载

[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -MLoaded Modules: core_module (static) so_module (static) http_module (static) mpm_event_module (static) authn_file_module (shared) authn_core_module (shared) authz_host_module (shared) authz_groupfile_module (shared) authz_user_module (shared) authz_core_module (shared) access_compat_module (shared) auth_basic_module (shared) reqtimeout_module (shared) filter_module (shared) mime_module (shared) log_config_module (shared) env_module (shared) headers_module (shared) setenvif_module (shared) version_module (shared) unixd_module (shared) status_module (shared) autoindex_module (shared) dir_module (shared) alias_module (shared) php5_module (shared)

如果没有加载,可以查看有没有模块文件,如果有文件并没有显示,就要查看配置文件中有没有libphp5.so

[root@xuexi-001 ~]# ls /usr/local/apache2/modules/libphp5.so /usr/local/apache2/modules/libphp5.so[root@xuexi-001 ~]# vi /usr/local/apache2/conf/httpd.confLoadModule php5_module        modules/libphp5.so

2.查看配置文件中有没有添加 “AddType application/x-httpd-php .php” .php前面有空格

3.在配置文件内容找到DirectoryIndex index.html ,这后面加入 index.php ,改为 DirectoryIndex index.html index.php

转载于:https://my.oschina.net/u/3850965/blog/1836000

你可能感兴趣的文章
Lua--------------------unity3D与Slua融合使用
查看>>
IP视频通信中的"丢包恢复技术”(LPR)
查看>>
java序列化/反序列化之xstream、protobuf、protostuff 的比较与使用例子
查看>>
xcode编译报错unknown error -1=ffffffffffffffff Command /bin/sh failed with exit code 1
查看>>
linux定时任务crontab设置
查看>>
$.ajax返回的JSON格式的数据后无法执行success的解决方法
查看>>
Android 多媒体MediaPlayer使用详解
查看>>
Golang源码探索(三) GC的实现原理
查看>>
魔方NewLife.Cube升级v2.0
查看>>
Silverlight 引路蜂二维图形库示例:颜色
查看>>
使用PS保存PDF为图片(JPG)
查看>>
40款不容错过的个人摄影设计作品集网站
查看>>
使用 PIVOT 和 UNPIVOT 行转列
查看>>
【Spring实战】—— 5 设值注入
查看>>
应聘华为 16道经典面试题及回答思路
查看>>
iOS tabbar 自定义小红点 消息显示,定制边框、颜色、高宽
查看>>
JavaScript:JavaScript语法的详细介绍
查看>>
java校验时间格式 HH:MM
查看>>
C# SQL 整表插入
查看>>
CSS3效果:animate实现点点点loading动画效果(二)
查看>>