LAMP架構

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)再講數據傳遞給用戶。這種行爲叫作動態請求。php

用戶瀏覽器經過Apache(httpd)訪問網站上一些靜態的文件(圖片),而後返回給用戶,並無經過MySQL,叫靜態請求。MySQL裏面存儲數據,並不存儲圖片信息。html


MySQL/Mariadb介紹

  • MySQL是一個關係型數據庫,由mysql ab公司開發,mysql在2018年被sun公司收購,2009年sun公司被oracle公司收購
  • MySQL官網:https://www.mysql.com
  • Mariadb 爲MySQL的一個分支,官網https://maridb.com
  • 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 http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz 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思路python

  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]# ls
mysql-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]# ls
bin      data  include  man         README   share      support-files
COPYING  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
······ //執行初始化 提示報錯信息,缺乏libaio
Installing 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 pages
2018-06-23 00:22:31 3004 [Note] InnoDB: The InnoDB memory heap is disabled
2018-06-23 00:22:31 3004 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-06-23 00:22:31 3004 [Note] InnoDB: Memory barrier is not used
2018-06-23 00:22:31 3004 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-06-23 00:22:31 3004 [Note] InnoDB: Using Linux native AIO
2018-06-23 00:22:31 3004 [Note] InnoDB: Using CPU crc32 instructions
2018-06-23 00:22:31 3004 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-06-23 00:22:31 3004 [Note] InnoDB: Completed initialization of buffer pool
2018-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 MB
2018-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 MB
2018-06-23 00:22:32 3004 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2018-06-23 00:22:33 3004 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2018-06-23 00:22:33 3004 [Warning] InnoDB: New log files created, LSN=45781
2018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer not found: creating new
2018-06-23 00:22:33 3004 [Note] InnoDB: Doublewrite buffer created
2018-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 created
2018-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 start
2018-06-23 00:22:33 3004 [Note] InnoDB: 5.6.36 started; log sequence number 0
2018-06-23 00:22:33 3004 [Note] Binlog end
2018-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 1625977
OK
·····//第一個

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 pages
2018-06-23 00:22:35 3026 [Note] InnoDB: The InnoDB memory heap is disabled
2018-06-23 00:22:35 3026 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-06-23 00:22:35 3026 [Note] InnoDB: Memory barrier is not used
2018-06-23 00:22:35 3026 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-06-23 00:22:35 3026 [Note] InnoDB: Using Linux native AIO
2018-06-23 00:22:35 3026 [Note] InnoDB: Using CPU crc32 instructions
2018-06-23 00:22:35 3026 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-06-23 00:22:35 3026 [Note] InnoDB: Completed initialization of buffer pool
2018-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 start
2018-06-23 00:22:35 3026 [Note] InnoDB: 5.6.36 started; log sequence number 1625977
2018-06-23 00:22:35 3026 [Note] Binlog end
2018-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 1625987
OK
······//第二個

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE 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_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly 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.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: 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 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
····· //檢查執行是否成功,檢查文件裏面有兩個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 risks
symbolic-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/mysql
datadir=/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 start
Starting 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.pid
mysql      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.sock
root       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 stop
Shutting 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 mysql
root       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/mysql
mysql      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.sock
root       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 mysqldmysql

[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]# !ps
ps aux | grep mysql
root       4308  0.0  0.0 112676   980 pts/0    R+   01:27   0:00 grep --color=auto mysql

不到萬不得已不要使用kill ,可以使用kill + pid 數據傳輸過程當中強制殺死會形成數據的丟失以及磁盤的損壞 ,最好使用killall + 服務名稱 ,killall相對安全。使用killall會先中止當前的寫讀操做,而後將沒有寫入到磁盤的數據慢慢寫入到磁盤中去,直到數據傳輸完成,才把進程殺死。linux

# 若是遇到mysql 進程始終殺不死,ps 還會有進程,說明數據量很大正在寫入磁盤,不能強制殺死使用Kill -9 , 有可能丟數據甚至損壞表。只能等着數據傳輸完成。

安裝Mariadb

  • cd /usr/local/src
  • wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • 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/mariadbweb

datadir=/data/mariadbsql

conf=/usr/local/mariadb數據庫

  1. 啓動 mariadb /etc/init.d/mariadb start

操做演示

[root@xuexi-001 ~]# cd /usr/local/src/
[root@xuexi-001 src]# ls
mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
mysql-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]# ls
mariadb-10.2.6-linux-glibc_214-x86_64
mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
mysql-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]# ls
bin                 DESTINATION        lib           scripts
COPYING             docs               man           share
COPYING.thirdparty  EXCEPTIONS-CLIENT  mysql-test    sql-bench
CREDITS             include            README.md     support-files
data                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/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE 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 test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL 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.pl
cd '/usr/local/mariadb//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider 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_notify
magic                   my-medium.cnf        mysql.server
my-huge.cnf             my-small.cnf         policy
my-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/mariadb

basedir=/usr/local/mariadb
datadir=/data/mariadb
conf=/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 start
Reloading systemd:                                         [  肯定  ]
Starting mariadb (via systemctl):                          [  肯定  ]
[root@xuexi-001 mariadb]# ps aux |grep mariadb
root       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.pid
mysql      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=3306
root       2257  0.0  0.0 112676   984 pts/0    R+   21:48   0:00 grep --color=auto mariadb
[root@xuexi-001 mariadb]# netstat -ltnp
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      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

出現的問題:apache

[root@xuexi-001 mariadb]# ps aux |grep mariadb
root       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.pid
mysql      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=3306
root       2311  0.0  0.0 112676   984 pts/0    R+   21:54   0:00 grep --color

在以上操做過程當中指定了datadir=/data/mariadb 這裏顯示的是--datadir=/data/mysqljson

解決這個問提須要在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 start
Starting mariadb (via systemctl):                          [  肯定  ]
[root@xuexi-001 mariadb]# ps aux | grep mariadb
root       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.pid
mysql      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=3306
root       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 http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.33.tar.gz
  • wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.2.tar.gz
  • wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
  • 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]# ls
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz
mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-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]# ls
apr-1.6.3              httpd-2.4.33
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz
apr-util-1.5.4         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-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]# ls
apr-config.in  build-outputs.mk  helpers       misc           strings
apr.dep        CHANGES           include       mmap           support
apr.dsp        CMakeLists.txt    libapr.dep    network_io     tables
apr.dsw        config.layout     libapr.dsp    NOTICE         test
apr.mak        configure         libapr.mak    NWGNUmakefile  threadproc
apr.pc.in      configure.in      libapr.rc     passwd         time
apr.spec       docs              LICENSE       poll           tools
atomic         dso               locks         random         user
build          emacs-mode        Makefile.in   README
buildconf      encoding          Makefile.win  README.cmake
build.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]# ls
aprutil.dep       CHANGES            include         NWGNUmakefile
aprutil.dsp       CMakeLists.txt     ldap            README
aprutil.dsw       config.layout      libaprutil.dep  README.cmake
aprutil.mak       configure          libaprutil.dsp  renames_pending
apr-util.pc.in    configure.in       libaprutil.mak  strmatch
apr-util.spec     crypto             libaprutil.rc   test
apu-config.in     dbd                LICENSE         uri
buckets           dbm                Makefile.in     xlate
build             docs               Makefile.win    xml
buildconf         encoding           memcache
build.conf        export_vars.sh.in  misc
build-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 install

xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄
 #include <expat.h>
 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]# ls
apr-1.6.3              httpd-2.4.33
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz
apr-util-1.5.4         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-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]# 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@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]# ls
bin  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 -M
AH00558: 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
Loaded 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 start
AH00558: 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 httpd
root      53115  0.0  0.1  95580  2528 ?        Ss   23:21   0:00 /usr/local/apache2/bin/httpd -k start
daemon    53116  0.4  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k start
daemon    53117  0.0  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k start
daemon    53118  0.2  0.2 382408  4432 ?        Sl   23:21   0:00 /usr/local/apache2/bin/httpd -k start
root      53201  0.0  0.0 112720   972 pts/0    R+   23:22   0:00 grep --color=auto httpd
[root@xuexi-001 apache2]# 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      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/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.3
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/apr-1.6.3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
······// 沒有安裝gcc語言編譯器須要安裝gcc

[root@xuexi-001 apr-1.6.3]# yum install -y gcc
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] 錯誤 1
make[2]: 離開目錄「/usr/local/src/httpd-2.4.33/support」
make[1]: *** [all-recursive] 錯誤 1
make[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 http://cn2.php.net/distributions/php-5.6.36.tar.gz
  • 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]# ls
apr-1.6.3         apr-util-1.6.1.tar.gz  mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-1.6.3.tar.gz  httpd-2.4.33           mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
apr-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]# ls
apr-1.6.3              httpd-2.4.33                                  php-5.6.36
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gz
apr-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
 [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 http://cn2.php.net/distributions/php-7.1.6.tar.bz2
  • 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]# ls
apr-1.6.3              httpd-2.4.33                                  php-5.6.36
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gz
apr-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]# ls
apr-1.6.3              httpd-2.4.33                                  php-5.6.36
apr-1.6.3.tar.gz       httpd-2.4.33.tar.gz                           php-5.6.36.tar.gz
apr-util-1.6.1         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  php-7.1.6
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]# 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]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]
[root@xuexi-001 php-7.1.6]# vi /usr/local/apache2/conf/httpd.conf
······//若是不想用哪一個就在配置文件前面加# 註釋掉

LoadModule php5_module        modules/libphp5.so
LoadModule 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 restart
AH00558: 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 restart
httpd 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.conf
LoadModule php5_module        modules/libphp5.so
#LoadModule php7_module        modules/libphp7.so
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl start
httpd (pid 1591) already running
[root@xuexi-001 ~]# ps aux |grep httpd
root       1591  0.0  0.4 255720  8868 ?        Ss   16:09   0:00 /usr/local/apache2/bin/httpd -k restart
daemon     1592  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restart
daemon     1593  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restart
daemon     1594  0.0  0.4 542548  8980 ?        Sl   16:09   0:00 /usr/local/apache2/bin/httpd -k restart
root       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=64

192.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.conf

Require all denied······// 將此處 denied 修改成 granted

[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t
Syntax 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 
<IfModule dir_module>
    DirectoryIndex index.html index.php

[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl graceful
······// 檢查配置文件,並從新加載配置文件

驗證Apache 支持不支持解析PHP

先寫一個PHP的腳本

[root@xuexi-001 ~]# vi /usr/local/apache2/htdocs/1.php
<?php
phpinfo();
?>
~

訪問 : 192.168.5.130/1.php

若是PHP 沒有被解析,須要從如下幾點排查問題

1.查看PHP模塊有沒有加載

[root@xuexi-001 ~]# /usr/local/apache2/bin/apachectl -M
Loaded 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.conf
LoadModule php5_module        modules/libphp5.so

2.查看配置文件中有沒有添加 「AddType application/x-httpd-php .php」 .php前面有空格

3.在配置文件內容找到DirectoryIndex index.html ,這後面加入 index.php ,改成 DirectoryIndex index.html index.php

相關文章
相關標籤/搜索