Linux下编译安装LAMP并分离为多台服务器

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写:

1、Linux;操作系统;

2、Apache;网页服务器;

3、MariaDB或MySQL,数据库管理系统(或者数据库服务器);

4、PHP、Perl或Python,脚本语言;

在编译安装之前我们需要先了解下它们之间分开的工作模式:wKiom1MuQdrDjWkNAAFpEesxLW0472.jpg



上图大致的标出Apache、php和mysql分离各自为单独服务器时的工作模式;下面就直接进行编译安装;首先准备好三个虚拟机。测试机版本:

1
2
3
4
5
6
[Linux86] #lsb_release -a
LSB Version:    :base - 4.0 - amd64:base - 4.0 - noarch:core - 4.0 - amd64:core - 4.0 - noarch:graphics - 4.0 - amd64:graphics - 4.0 - noarch:printing - 4.0 - amd64:printing - 4.0 - noarch
Distributor  ID : CentOS
Description:    CentOS release  6.5  (Final)
Release:     6.5
Codename:   Final


由于其中操作都是插入代码的;所以命令执行过程并没有把代码都贴出来,只贴出最后几行;


一、编译安装Apache2.4.9

1、解决依赖关系:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[Linux86] #yum grouplist
#
Installed Groups:
    Additional Development
    Base
    Console internet tools
    Desktop
    Desktop Platform
    Development tools  #查看包组是否安装
    Server Platform Development  #查看包组是否安装
如未安装;请先安装这两个包组
#
[Linux86] #rpm -qa pcre-devel
pcre - devel - 7.8 - 6.el6 .x86_64
#
查看是否安装;未安装需事先安装
[Linux86] #ls
apr - 1.5 . 0.tar .bz2  apr - util - 1.5 . 3.tar .bz2  httpd - 2.4 . 9.tar .bz2
[Linux86] #
#先安装apr包;解压后进入该目录
[Linux86] #pwd
/ root / program / apr - 1.5 . 0
[Linux86] #./configure --prefix=/usr/local/apr
config.status: executing default commands
config.status: include / apr.h  is  unchanged
config.status: include / arch / unix / apr_private.h  is  unchanged  #没有报错就继续
[Linux86] #make && make install
/ usr / bin / install  - - 644  build / apr_rules.out  / usr / local / apr / build - 1 / apr_rules.mk
/ usr / bin / install  - - 755  apr - config.out  / usr / local / apr / bin / apr - 1 - config #没有报错就继续安装apr-util包
[Linux86] #
#解压进入目录
[Linux86] #./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
config.status: creating test / Makefile
config.status: creating include / private / apu_config.h
config.status: executing default commands
[Linux86] #make && make install
/ usr / bin / install  - - 644  aprutil.exp  / usr / local / apr - util / lib
/ usr / bin / install  - - 755  apu - config.out  / usr / local / apr - util / bin / apu - 1 - config
[Linux86] #都以安装成功

2、编译Apache:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Linux86] #rpm -qa httpd
httpd - 2.2 . 15 - 29.el6 .centos.x86_64
#
#系统自己本身已安装了httpd2.2版本的;这里编译2.4的;但是老版本不需要卸载;
#因为卸载后会造成依赖关系不稳定;且后续安装模块时还是会自动安装上的;
#编译是只要不指定到默认路径即可;确保安装前原来的是停止的;且关闭开启自动启动
#
#
[Linux86] #./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-fcgi
参数可以通过. / configure  - - help 查看;开启自己需要的即可
#如没有报错直接下一步安装
[Linux86] #make && make install
mkdir  / usr / local / apache / build
Installing man pages  and  online manual
mkdir  / usr / local / apache / man
mkdir  / usr / local / apache / man / man1
mkdir  / usr / local / apache / man / man8
mkdir  / usr / local / apache / manual
make[ 1 ]: Leaving directory ` / root / program / httpd - 2.4 . 9 ' #安装完成
[Linux86] #

3、配置Apache:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#由于之前的httpd没有卸载;那么可以cp一个启动脚本当目前的httpd脚本;更改下里面的参数
#
[Linux86] #cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24
[Linux86] #vi /etc/rc.d/init.d/httpd24
# Path to the apachectl script, server binary, and short-form for messages.
#以下几个变量定义为目前的路径;并在主配置文件中更改对应的值
achectl = / usr / local / apache / bin / apachectl
httpd = ${HTTPD - / usr / local / apache / bin / httpd}
prog = httpd
pidfile = ${PIDFILE - / var / run / httpd / httpd.pid}
lockfile = ${LOCKFILE - / var / lock / subsys / httpd24}
RETVAL = 0
STOP_TIMEOUT = ${STOP_TIMEOUT - 10 }
#修改主配置文件
[Linux86] #vi /etc/httpd24/httpd.conf
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot  "/usr/local/apache"
pifile  "/var/run/httpd/httpd.pid"  #加一行pid文件路径;与脚本文件对应
#保存退出
[Linux86] #service httpd24 start
Starting httpd:                                            [  OK  ]
[Linux86] #ss -tnl
State       Recv - Q Send - Q                  Local Address:Port                    Peer Address:Port
LISTEN       0       128                                 ::: 111                                ::: *
LISTEN       0       128                                  * : 111                                 * : *
LISTEN       0       128                                 ::: 80                                 ::: *
#80端口已监听

到这里Apache已编译安装完成了;也可以在浏览器输入IP地址测试下。


二、编译安装PHP

编译之前都是需要检查开发环境;需要安装的包是否都已安装

1
2
3
4
5
6
[Linux87] #rpm -qa bzip2-devel libmcrypt-devel libxml2-devel
libxml2 - devel - 2.7 . 6 - 14.el6 .x86_64
bzip2 - devel - 1.0 . 5 - 7.el6_0 .x86_64
libmcrypt - devel - 2.5 . 8 - 9.el6 .x86_64
[Linux87] #
#如未安装;需要先用yum安装上


1、这边是每个服务单独作为一个服务器;所以编译时与放在一台机器上是有分别的;而且也不需要先安装mysql;下面来直接编译PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[Linux87] #ls
php - 5.4 . 26.tar .bz2  xcache - 3.1 . 0.tar .bz2
[Linux87] #tar xf php-5.4.26.tar.bz2
[Linux87] #./configure --prefix=/usr/local/php --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-libxml-dir=/usr --with-openssl  --with-zlib --with-bz2 --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-mcrypt --enable-sockets --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
#注意:--with-mysql几个选项都要为mysqlnd;因为mysql服务器单独为另一台机器
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| License:                                                           |
| This software  is  subject to the PHP License, available  in  this     |
| distribution  in  the  file  LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do  not  agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
Thank you  for  using PHP.
出现上述字符就说明可以继续安装了;
[Linux87] #make && make install
Installing PEAR environment:       / usr / local / php / lib / php /
[PEAR] Archive_Tar     -  installed:  1.3 . 11
[PEAR] Console_Getopt  -  installed:  1.3 . 1
warning: pear / PEAR requires package  "pear/Structures_Graph"  (recommended version  1.0 . 4 )
warning: pear / PEAR requires package  "pear/XML_Util"  (recommended version  1.2 . 1 )
[PEAR] PEAR            -  installed:  1.9 . 4
Wrote PEAR system config  file  at:  / usr / local / php / etc / pear.conf
You may want to add:  / usr / local / php / lib / php to your php.ini include_path
[PEAR] Structures_Graph -  installed:  1.0 . 4
[PEAR] XML_Util        -  installed:  1.2 . 1
/ root / program / php - 5.4 . 26 / build / shtool install  - c ext / phar / phar.phar  / usr / local / php / bin
ln  - - / usr / local / php / bin / phar.phar  / usr / local / php / bin / phar
Installing PDO headers:           / usr / local / php / include / php / ext / pdo /
[Linux87] #
#到这里说明安装成功了;可能会有些报错说某些软件版本太低


2、下面配置PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
配置php的配置文件
[Linux87] #cp php.ini-production /etc/php.ini
配置一个启动脚本
[Linux87] #cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
给执行权限
[Linux87] #chmod +x /etc/rc.d/init.d/php-fpm
加入chkconfig
[Linux87] #chkconfig --add php-fpm
[Linux87] #chkconfig php-fpm on
[Linux87] #chkconfig --list php-fpm
php - fpm          0 :off    1 :off    2 :on     3 :on     4 :on     5 :on     6 :off
[Linux87] #cd /usr/local/php/etc/
配置php - fpm配置文件
[Linux87] #cp php-fpm.conf.default php-fpm.conf
更改配置文件
[Linux87] #vi php-fpm.conf
[ global ]
; Pid  file
; Note: the default prefix  is  / usr / local / php / var
; Default Value: none
pid  =  run / php - fpm.pid  #这项启用;下面几项对应的改为相应的值即可
;
pm.max_children  =  50
; The number of child processes created on startup.
; Note: Used only when pm  is  set  to  'dynamic'
; Default Value: min_spare_servers  +  (max_spare_servers  -  min_spare_servers)  /  2
pm.start_servers  =  5
; The desired minimum number of idle server processes.
; Note: Used only when pm  is  set  to  'dynamic'
; Note: Mandatory when pm  is  set  to  'dynamic'
pm.min_spare_servers  =  3
; The desired maximum number of idle server processes.
; Note: Used only when pm  is  set  to  'dynamic'
; Note: Mandatory when pm  is  set  to  'dynamic'
pm.max_spare_servers  =  8
#更改完成后启动:
[Linux87] #service php-fpm start
Starting php - fpm  done
[Linux87] #ss -tunl | grep 9000
tcp    LISTEN      0       128             127.0 . 0.1 : 9000                   * : *
#由于php-rpm是监听在9000端口,查看启动正常


3、与Apache整合到一起

1
2
3
4
5
6
7
8
9
10
11
12
[Linux87] #vi /usr/local/php/etc/php-fpm.conf
定位到listen;IP地址更改为别人可用访问进来的IP地址
;    '/path/to/unix/socket'  -  to listen on a unix socket.
; Note: This value  is  mandatory.
listen  =  172.16 . 251.87 : 9000
[Linux87] #service php-fpm restart
[Linux87] #ss -tnul | grep 9000
tcp    LISTEN      0       128         172.16 . 251.87 : 9000                   * : *
[Linux87] #
[Linux87] #cd /var/www/
[Linux87] #mkdir pipi soul dark mydamin
#建立几个目录作为虚拟主机目录


4、配置Apache虚拟主机来使用PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
到Apache主机上;找一个目录下面建立几个不同的目录作为虚拟主机目录;
[Linux86] #cd /usr/local/apache/
[Linux86] #mkdir -pv www/{pipi,soul,dark,myadmin}
编辑主配置文件;开启虚拟主机;关闭中心主机
[Linux86] #vi /etc/httpd24/httpd.conf
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
#DocumentRoot "/usr/local/apache/htdocs" 注释掉
# Virtual hosts
Include  / etc / httpd24 / extra / httpd - vhosts.conf  #开启这项
#定位AddType;添加下面两行
AddType application / x - httpd - php .php
AddType application / x - httpd - php - source .phps
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
定位至DirectoryIndex
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
     DirectoryIndex index.php index.html  #添加index.php
< / IfModule>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
定位到LoadModule
LoadModule proxy_module modules / mod_proxy.so  #开启
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules / mod_proxy_fcgi.so  #开启
#
[Linux86] #vi /etc/httpd24/extra/httpd-vhosts.conf  编辑虚拟主机
<VirtualHost  * : 80 >
     ServerAdmin  admin@pipi.com
     DocumentRoot  "/usr/local/apache/www/pipi"  #指定Apache主机的站点目录
     ServerName www.pipi.com  #指定主机名
     ServerAlias pipi.com  #主机别名
     ErrorLog  "/usr/local/apache/logs/pipi.error_log"  #错误日志路径及名称
     CustomLog  "/usr/local/apache/logs/pipi.access_log"  combined   #访问日志路径及名称
     ProxyRequests Off  #关闭正向代理
     ProxyPassMatch ^ / (. * \.php)$ fcgi: / / 172.16 . 251.87 : 9000 / var / www / pipi / $ 1  #反向代理到PHP主机的站点目录
     <Directory  "/usr/local/apache/www/pipi" #目录的访问权限配置
         Options none
         AllowOverride none
         Require  all  granted
     < / Directory>
< / VirtualHost>
<VirtualHost  * : 80 >
     ServerAdmin  admin@soul.org
     DocumentRoot  "/usr/local/apache/www/soul"
     ServerName www.soul.org
     ServerAlias soul.org
     ErrorLog  "/usr/local/apache/logs/soul.error_log"
     CustomLog  "/usr/local/apache/logs/soul.access_log"  combined
     ProxyRequests Off
     ProxyPassMatch ^ / (. * \.php)$ fcgi: / / 172.16 . 251.87 : 9000 / var / www / soul / $ 1
     <Directory  "/usr/local/apache/www/soul" >
         Options none
         AllowOverride none
         Require  all  granted
     < / Directory>
< / VirtualHost>

5、测试

1
2
3
4
5
6
[Linux87] #cd /var/www/pipi/
[Linux87] #vi index.php
<?php
         phpinfo();
?>
#保存退出;

在浏览器输入虚拟主机中的主机名;

wKioL1MukXCyrX7jAAExTG0_j9g139.jpg

如上显示;就说明Apache和PHP已成功整合在一起了;在为PHP安装xcache加速器以提高性能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[Linux87] #ls
php - 5.4 . 26   php - 5.4 . 26.tar .bz2  xcache - 3.1 . 0.tar .bz2
[Linux87] #tar xf xcache-3.1.0.tar.bz2
[Linux87] #cd xcache-3.1.0
[Linux87] #/usr/local/php/bin/phpize
Configuring  for :
PHP Api Version:          20100412
Zend Module Api No:       20100525
Zend Extension Api No:    220100525
[Linux87] #
[Linux87] #./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[Linux87] #make && make install
#要复制/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/这行内容
如之前没有 / etc / php.d目录需先创建
[Linux87] #cp xcache.ini /etc/php.d/
[xcache - common]
;; non - Windows example:
extension  =  / usr / local / php / lib / php / extensions / no - debug - non - zts - 20100525 / xcache.so 把前面路径加上
重启下php - fpmzaic

在此访问之前的测试页面

wKioL1MuxRCzttawAAFLfTKd-g4352.jpg

可以看到红色区域内已出现xcache和版本信息了。


三、配置MySQL

1、这里使用的是解压包;解压完成后直接配置即可使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
配置前先准备已下工作
[Linux88] #groupadd -r mysql
[Linux88] #useradd -r -g mysql -s /sbin/nologin mysql
#先创建一个逻辑卷;这里就不演示创建逻辑卷的过程了;逻辑卷也不是实验必须创建的;实验时可以不用创建
[Linux88] #df -Th
Filesystem               Type    Size  Used Avail Use %  Mounted on
/ dev / mapper / sqlvg - lvsql ext4    9.9G   151M   9.2G    2 %  / Mysql / data
#
配置mysql
#解压到指定路径
[Linux88] #tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[Linux88] #cd /usr/local/
[Linux88] #ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64/ /usr/local/mysql
` / usr / local / mysql ' -> `/usr/local/mysql-5.5.33-linux2.6-x86_64/'
[Linux88] #cd mysql
[Linux88] #chown -R root.mysql *
#初始化数据库;并指定其用户和data目录
[Linux88] #scripts/mysql_install_db --user=mysql --datadir=/Mysql/data
[Linux88] #ls /Mysql/data/
lost + found  mysql  mysql - bin . 000001   mysql - bin . 000002   mysql - bin .index  performance_schema  test
#没有报错并生成以上文件即可
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
[Linux88] #cp support-files/my-large.cnf /etc/my.cnf 配置一个配置文件
[Linux88] #vi /etc/my.cnf   更改已下配置选项;具体选项根据自己需要配置
# The MySQL server
[mysqld]
port             =  3306
socket           =  / tmp / mysql.sock
skip - external - locking
key_buffer_size  =  256M
max_allowed_packet  =  1M
table_open_cache  =  256
sort_buffer_size  =  1M
read_buffer_size  =  1M
read_rnd_buffer_size  =  4M
myisam_sort_buffer_size  =  64M
thread_cache_size  =  8
query_cache_size =  16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency  =  4
datadir  =  / Mysql / data  新增一行
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
提供一个服务脚本
[Linux88] #cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[Linux88] #chmod +x /etc/rc.d/init.d/mysqld
[Linux88] #chkconfig --add mysqld
[Linux88] #chkconfig mysqld on
[Linux88] #chkconfig --list mysqld
mysqld           0 :off    1 :off    2 :on     3 :on     4 :on     5 :on     6 :off
[Linux88] #service mysqld start
Starting MySQL...                                          [  OK  ]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
#启动成功后导出其他信息
[Linux88] #vi /etc/profile.d/mysql.sh
export PATH = / usr / local / mysql / bin :$PATH
[Linux88] #ln -sv /usr/local/mysql/include/ /usr/include/mysql
` / usr / include / mysql ' -> `/usr/local/mysql/include/'
[Linux88] #
[Linux88] #vi /etc/man.config
定位到MANPATH
#
MANPATH  / usr / man
MANPATH  / usr / share / man
MANPATH  / usr / local / man
MANPATH  / usr / local / share / man
MANPATH  / usr / X11R6 / man
MANPATH  / usr / local / mysql / man  #添加一行
#
[Linux88] #echo /usr/local/mysql/lib/ > /etc/ld.so.conf.d/mysql.conf

2、配置MySQL整合PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[Linux88] #mysql
Welcome to the MySQL monitor.  Commands end with ;  or  \g.
Your MySQL connection  id  is  1
Server version:  5.5 . 33 - log MySQL Community Server (GPL)
Copyright (c)  2000 2013 , 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>use mysql 授权表
                                                                                                                                           
mysql> select user,host,password  from  user;
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - +
| user | host                  | password |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - +
| root | localhost             |          |
| root | localhost.localdomain |          |
| root |  127.0 . 0.1              |          |
| root | :: 1                    |          |
|      | localhost             |          |
|      | localhost.localdomain |          |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - +
6  rows  in  set  ( 0.00  sec)
                                                                                                                                           
mysql> update user  set  password  =  password ( 'you_passwd' ) where user = 'root' ;
#更改user表中所有用户为root的密码
                                                                                                                                           
mysql> drop user ' '@' localhost.localdomain'; 删除一些无用的账户;以保证安全性
Query OK,  0  rows affected ( 0.00  sec)
Rows matched:  4   Changed:  0   Warnings:  0
                                                                                                                                           
mysql> select user,host,password  from  user; 显示user的信息;
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| user | host                  | password                                  |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| root | localhost             |  * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
| root | localhost.localdomain |  * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
| root |  127.0 . 0.1              * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
3  rows  in  set  ( 0.00  sec)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  #下面的较为重要;这是授权PHP主机可以访问的
mysql> grant  all  privileges on  * . *  to  'root' @ '172.16.251.87'  identified by  'you passwd' ;
Query OK,  0  rows affected ( 0.00  sec)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
mysql> select user,host,password  from  user;
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| user | host                  | password                                  |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| root | localhost             |  * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
| root | localhost.localdomain |  * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
| root |  127.0 . 0.1              * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
| root |  172.16 . 251.87          * 4B78DCD8C21610F21CBEA871E687A33647CF8EE4  |
+ - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
4  rows  in  set  ( 0.00  sec)
mysql> flush privileges;  更新
Query OK,  0  rows affected ( 0.00  sec)
mysql>

到此以完成授权;下面就整合测试WordPress和phpmyadmin。


四、测试LAMP

1、先测试在php主机上是否可以连接mysql

1
2
3
4
5
6
7
8
9
10
11
[Linux87] #vim index.php
<?php
         $link  =  mysql_connect( '172.16.251.88' , 'root' , 'you_passwd' );
         if ($link)
                 echo  "Success..." ;
         else
                 echo  "Failed...." ;
         mysql_close;
         phpinfo();
?>
~

wKiom1MuuA_TgAI5AADhIet3UfM138.jpg

能看到左上角有Success说明连接成功;也可以停止mysql服务测试看下。


2、配置phpmyadmin

在Apache和php主机对应的目录下下载这两个软件包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[Linux87] #pwd
/ var / www / myadmin
[Linux87] #ls
phpMyAdmin - 4.0 . 5 - all - languages. zip
[Linux87] #
#这是两台不同主机;一个Apache;一个PHP
[Linux86] #pwd
/ usr / local / apache / www / myadmin
[Linux86] #ls
phpMyAdmin - 4.0 . 5 - all - languages. zip
[Linux86] #
[Linux87] #unzip phpMyAdmin-4.0.5-all-languages.zip
[Linux87] #mv phpMyAdmin-4.0.5-all-languages/* ./
       
       
上面的操作都是需要两台机器一样操作的;
#需要连接数据库的操作在PHP主机上操作即可
[Linux87] #cp config.sample.inc.php config.inc.php
$cfg[ 'Servers' ][$i][ 'auth_type' =  'cookie' ;
/ *  Server parameters  * /
$cfg[ 'Servers' ][$i][ 'host' =  '172.16.251.88' #这个更改为mysql服务地址
$cfg[ 'Servers' ][$i][ 'connect_type' =  'tcp' ;
$cfg[ 'Servers' ][$i][ 'compress' =  false;
/ *  Select mysql  if  your server does  not  have mysqli  * /
$cfg[ 'Servers' ][$i][ 'extension' =  'mysqli' ;
$cfg[ 'Servers' ][$i][ 'AllowNoPassword' =  false;


配置完成后登陆测试

wKiom1Muu33weBMIAAHJDycRFVA335.jpg

wKiom1Muu4-A6gMbAAC1htvnrXk155.jpg

测试登陆成功。


3、配置WordPress博客

同phpmyadmin配置一样;两台主机都需同样的代码存放于对应的目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[Linux86] #pwd
/ usr / local / apache / www / soul
[Linux86] #ls
wordpress - 3.8 . 1 - zh_CN.tar.gz
[Linux86] #
#
[Linux87] #pwd
/ var / www / soul
[Linux87] #ls
wordpress - 3.8 . 1 - zh_CN.tar.gz
[Linux87] #
[Linux87] #tar xf wordpress-3.8.1-zh_CN.tar.gz
[Linux87] #chmod -R 777 wordpress
[Linux87] #mv wordpress/* ./
[Linux87] #cp wp-config-sample.php wp-config.php
[Linux87] #vi wp-config.php 更改已下几项;
define( 'DB_NAME' 'wpdb' );   #数据库名称
define( 'DB_USER' 'wpuser' );  #用户名称
define( 'DB_PASSWORD' 'wppass' );  #密码
define( 'DB_HOST' '172.16.251.88' );  #数据库主机

上述配置了数据库的账户信息;需要在数据库进行授权;

1
2
3
4
5
6
7
8
9
10
11
[Linux88] #mysql -uroot -p
mysql> use mysql
Database changed
mysql> create database wpdb;  #创建wpdb数据库
Query OK,  1  row affected ( 0.01  sec)
                                                                                                   
mysql> grant  all  privileges on wpdb. *  to  'wpuser' @ '172.16.251.87'  identified by  'wppass' #授权wpdb数据库可以访问MySQL
Query OK,  0  rows affected ( 0.00  sec)
                                                                                                   
mysql> flush privileges;  #更新
Query OK,  0  rows affected ( 0.00  sec)


wKiom1MuwLrzBagsAAEEzdF2Bjc564.jpg

wKioL1MuwKnBa23iAADSx7AW8X8552.jpg

wKiom1MuwOGRKVrmAAB1CnxqiHA254.jpg

wKiom1MuwPzxvHW_AAD3SysagM4170.jpg

wKioL1MuwT6C7npzAAF654f0Rmo160.jpg

测试一切都是正常的;数据库也是更新正常的。到此LAMP以编译安装完成。虚拟主机还可以添加多个。这里就不一一测试;主要就是在数据库连接时需要指定主机;而且数据库上需要授权访问。



本文转自Mr_陈 51CTO博客,原文链接:http://blog.51cto.com/chenpipi/1381835,如需转载请自行联系原作者

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
存储 Linux Docker
docker在欧拉服务器上编译安装应该注意什么?如何操作?
【10月更文挑战第31天】docker在欧拉服务器上编译安装应该注意什么?如何操作?
84 2
|
1月前
|
缓存 Ubuntu Linux
Linux环境下测试服务器的DDR5内存性能
通过使用 `memtester`和 `sysbench`等工具,可以有效地测试Linux环境下服务器的DDR5内存性能。这些工具不仅可以评估内存的读写速度,还可以检测内存中的潜在问题,帮助确保系统的稳定性和性能。通过合理配置和使用这些工具,系统管理员可以深入了解服务器内存的性能状况,为系统优化提供数据支持。
38 4
|
1月前
|
NoSQL Linux PHP
如何在不同操作系统上安装 Redis 服务器,包括 Linux 和 Windows 的具体步骤
本文介绍了如何在不同操作系统上安装 Redis 服务器,包括 Linux 和 Windows 的具体步骤。接着,对比了两种常用的 PHP Redis 客户端扩展:PhpRedis 和 Predis,详细说明了它们的安装方法及优缺点。最后,提供了使用 PhpRedis 和 Predis 在 PHP 中连接 Redis 服务器及进行字符串、列表、集合和哈希等数据类型的基本操作示例。
64 4
|
1月前
|
运维 监控 安全
盘点Linux服务器运维管理面板
随着云计算和大数据技术的迅猛发展,Linux服务器在运维管理中扮演着越来越重要的角色。传统的Linux服务器管理方式已经无法满足现代企业的需求,因此,高效、安全、易用的运维管理面板应运而生。
|
1月前
|
运维 监控 Linux
服务器管理面板大盘点: 8款开源面板助你轻松管理Linux服务器
在数字化时代,服务器作为数据存储和计算的核心设备,其管理效率与安全性直接关系到业务的稳定性和可持续发展。随着技术的不断进步,开源社区涌现出众多服务器管理面板,这些工具以其强大的功能、灵活的配置和友好的用户界面,极大地简化了Linux服务器的管理工作。本文将详细介绍8款开源的服务器管理面板,包括Websoft9、宝塔、cPanel、1Panel等,旨在帮助运维人员更好地选择和使用这些工具,提升服务器管理效率。
|
20天前
|
存储 Oracle 安全
服务器数据恢复—LINUX系统删除/格式化的数据恢复流程
Linux操作系统是世界上流行的操作系统之一,被广泛用于服务器、个人电脑、移动设备和嵌入式系统。Linux系统下数据被误删除或者误格式化的问题非常普遍。下面北亚企安数据恢复工程师简单聊一下基于linux的文件系统(EXT2/EXT3/EXT4/Reiserfs/Xfs) 下删除或者格式化的数据恢复流程和可行性。
|
1月前
|
缓存 Unix Linux
服务器linux!!!
本文介绍了计算机的演变历史、硬件基础知识及服务器相关知识。从电子管时代的ENIAC到冯-诺伊曼架构,再到现代计算机系统组成,详细讲解了计算机的发展历程。此外,文章还介绍了服务器的分类、品牌、硬件组成以及IDC机房的上架流程,为读者提供了全面的技术背景知识。
54 0
服务器linux!!!
|
1月前
|
人工智能 安全 Linux
|
1月前
|
Linux 数据库
Linux服务如何实现服务器重启后的服务延迟自启动?
【10月更文挑战第25天】Linux服务如何实现服务器重启后的服务延迟自启动?
295 3
|
1月前
|
安全 Linux API
Linux服务器安全
人们常误认为服务器因存于数据中心且数据持续使用而无需加密。然而,当驱动器需维修或处理时,加密显得尤为重要,以防止数据泄露。Linux虽有dm-crypt和LUKS等内置加密技术,但在集中管理、根卷加密及合规性等方面仍存不足。企业应选择具备强大验证、简单加密擦除及集中管理等功能的解决方案,以弥补这些缺口。
26 0