centos7环境下使用yum搭建lamp环境(编译安装版)

安装的顺序:

1
Apache --> Mysql(MariaDB) --> PHP

1.配置SELinux,防火墙

1
2
3
4
5
6
7
8
9
10
禁用SELinux,否则可能造成编译失败或者出现其他意料不到的问题
# vim /etc/selinux/config
SELINUX=disabled

# setenforce 0

配置防火墙放行http和https
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

2.配置aliyun Yum源

1
2
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum makecache

3.安装开发工具组和依赖包

1
2
# yum -y groupinstall "development tools" 
# yum -y install gcc gcc-c++ zlib-devel pcre pcre-devel openssl openssl-devel expat-devel

4.编译安装apr-1.4和apr-1.5

最新版的httpd2.4需要依赖apr-1.4以上版本和apr-1.5以上版本

1
2
3
4
5
6
7
8
9
10
11
12
13
# wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz
# tar vxf apr-1.6.3.tar.gz
# cd apr-1.6.3
# ./configure --prefix=/usr/local/apr
# make
# make install

# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.gz #或者下载: wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz
# tar vxf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install

5.编译安装httpd2.4.33

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
# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2
# tar vxf httpd-2.4.33.tar.bz2
编译httpd之前把上一步解压出来的apr和apr-util文件复制到httpd-2.4.33/srclib/文件夹下,再进行httpd编译
# mv apr-1.6.3 httpd-2.4.33/srclib/apr
# mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util
# cd httpd-2.4.33
# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
# make
# make install


配置以支持chkconfig控制
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
# vim /etc/rc.d/init.d/httpd
在第二行加入如下三行(前面的#号不能省略)
# Comments to support chkconfig on RedHat Linux
# chkconfig: 35 85 15
# description: Apache is a World Wide Web server.

# chkconfig --add httpd
# chkconfig httpd on
# systemctl restart httpd
# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
# source /etc/profile.d/httpd.sh

在启动之前,需要查看/usr/local/apache/conf/httpd.conf中的ServerName有没有配置,如果没有,则需要配置,如我的虚拟机是192.168.100.254,那ServerName为192.168.100.254:80。

可选操作

1
2
3
4
5
6
7
# groupadd -r apache 
# useradd -r -g apache apache
# vim /usr/local/apache/conf/httpd.conf
#User daemon
#Group daemon
User apache
Group apache

打开 http://192.168.10.10/ 可以看到httpd已经工作

6. 编译安装MariaDB10.2.6

(1) 删除CentOS7.3默认数据库配置文件

  • 查看默认数据库配置文件
1
2
3
4
5
6
[root@localhost ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf
/etc/my.cnf
  • 删除默认数据库配置文件
1
[root@localhost ~]# rm -rf /etc/my.cnf /etc/my.cnf.d/
  • 再次查看默认数据库配置文件
1
2
3
[root@localhost ~]# find -H /etc/ | grep my.c
/etc/pki/tls/certs/make-dummy-cert
/etc/pki/tls/certs/renew-dummy-cert

到目前为止, 系统最小化安装自带的数据库配置文件已经删除干净了!

(2)卸载系统自带mariadb-libs

  • 查询
1
2
[root@localhost ~]# rpm -qa|grep mariadb-libs
mariadb-libs-5.5.52-1.el7.x86_64
  • 卸载
1
[root@localhost ~]# rpm -e mariadb-libs-5.5.52-1.el7.x86_64 --nodeps

(4)安装相关包

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# yum -y install libaio libaio-devel 
[root@localhost ~]# yum -y install bison bison-devel
[root@localhost ~]# yum -y install zlib-devel
[root@localhost ~]# yum -y install openssl openssl-devel
[root@localhost ~]# yum -y install ncurses ncurses-devel
[root@localhost ~]# yum -y install libcurl-devel libarchive-devel
[root@localhost ~]# yum -y install boost boost-devel
[root@localhost ~]# yum -y install lsof
[root@localhost ~]# yum -y install wget
[root@localhost ~]# yum -y install gcc gcc-c++ make cmake
[root@localhost ~]# yum -y install perl
[root@localhost ~]# yum -y install kernel-headers kernel-devel
[root@localhost ~]# yum -y install pcre-devel

(5) 创建家目录存放软件包目录

1
2
[root@localhost ~]# mkdir soft
[root@localhost ~]# cd soft

(6)MariaDB官网复制源码包链接地址并下载解压

1
[root@localhost soft]# wget http://112.5.240.21:81/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.6/source/mariadb-10.2.6.tar.gz
  • 解压
1
[root@localhost soft]# tar -zxvf mariadb-10.2.6.tar.gz

(7)创建MariaDB安装目录、数据库存放目录、建立用户和目录

这里提前预定MariaDB的安装目录为/usr/local/mysql并且数据库目录为/data/mysql,这里要建立系统用户及组和数据库存放目录,并且将数据库存放目录赋予mysql用户及组权限,操作如下:

请注意特别说明一下:这里说的数据库目录是指的具体数据库存储文件, 而不是安装文件!

  • 创建mysql系统用户组
1
[root@localhost soft]# groupadd -r mysql
  • 创建系统用户mysql并加入到mysql系统用户组
1
[root@localhost soft]# useradd -r -g mysql -s /sbin/nologin -d /usr/local/mysql -M mysql

以下是上面创建系统用户mysql的各个参数说明:

-r: 添加系统用户( 这里指将要被创建的系统用户mysql )

-g: 指定要创建的用户所属组( 这里指添加到新系统用户mysql到mysql系统用户组 )

-s: 新系统帐户的登录shell( /sbin/nologin 这里设置为将要被创建系统用户mysql不能用来登录系统 )

-d: 新帐户的主目录( 这里指定将要被创建的系统用户mysql的家目录为 /usr/local/mysql )

-M: 不要创建用户的主目录( 也就是说将要被创建的系统用户mysql不会在 /home 目录下创建 mysql 家目录 )

  • 创建maria安装目录
1
[root@localhost soft]# mkdir -p /usr/local/mysql
  • 创建数据库存放目录
1
[root@localhost soft]# mkdir -p /data/mysql
  • 改变数据库存放目录所属用户及组为 mysql:mysql
1
[root@localhost soft]# chown -R mysql:mysql /data/mysql

(8)执行编译安装

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
> 进入到解压后的源码包文件夹

[root@localhost soft]# cd mariadb-10.2.6

> 输入编译参数

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DWITHOUT_TOKUDB=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STPRAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWIYH_READLINE=1 \
-DWIYH_SSL=system \
-DVITH_ZLIB=system \
-DWITH_LOBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

> 如果编译失败请删除CMakeCache.txt

[root@localhost soft]# rm -f CMakeCache.txt

> 让指令重新执行,否则每次读取这个文件,命令修改正确也是报错

> cmake没问题,可以编译并且安装了: make && make install 时间会有点长根据个人机器吧,你可以干别的事情去!

[root@localhost soft]# make && make install

> 执行完成也就是安装完成了, 不过请注意, 这只是安装了, 并没有启动, 启动不成功等于没安装, 不能用也是徒劳无功不是?

(9)配置MariaDB

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
> 进入到 MariaDB 安装目录

[root@localhost ~]# cd /usr/local/mysql/

> 使用 `mysql` 用户执行脚本, 安装数据库到数据库存放目录

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql

> 输出以下信息:
Installing MariaDB/MySQL system tables in '/data/mysql' ...
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:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain 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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/maria'

You can test the MariaDB daemon with mysql-test-run.pl
cd './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/

(10)复制MariaDB配置文件到/etc目录

1
2
3
4
5
6
7
> 进行到 MariaDB 安装目录

[root@localhost ~]# cd /usr/local/mysql/

> 拷贝support-files目录下的文件my-large.cnf到/etc目录并重命名为my.cnf

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf

(11)创建启动脚本

1
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

(12) 启动mysqld服务

1
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start

(13) 配置环境变量, 以便在任何目录下输入mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
> 打开并新建文件

[root@localhost mysql]# vim /etc/profile.d/mysql.sh

> 输入以下内容

export PATH=$PATH:/usr/local/mysql/bin/

> 保存并退出

:wq

> 为脚本赋于可执行权限

[root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh

> 进行mysql.sh脚本所在目录, 并执行脚本, 以立即生效环境变量

[root@localhost mysql]# source /etc/profile.d/mysql.sh

(14)初始化MariaDB

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
> 运行MariaDB初始化脚本

[root@localhost mysql]# ./bin/mysql_secure_installation

> 以下提示:

Enter current password for root (enter for none): 输入当前root密码(没有输入)

Set root password? [Y/n] 设置root密码?(是/否)

New password: 输入新root密码

Re-enter new password: 确认输入root密码

Password updated successfully! 密码更新成功

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

默认情况下,MariaDB安装有一个匿名用户,
允许任何人登录MariaDB而他们无需创建用户帐户。
这个目的是只用于测试,安装去更平缓一些。
你应该进入前删除它们生产环境。

Remove anonymous users? [Y/n] 删除匿名用户?(是/否)

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

通常情况下,root只应允许从localhost连接。
这确保其他用户无法从网络猜测root密码。

Disallow root login remotely? [Y/n] 不允许root登录远程?(是/否)

By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

默认情况下,MariaDB提供了一个名为“测试”的数据库,任何人都可以访问。
这也只用于测试,在进入生产环境之前应该被删除。

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

重新加载权限表将确保所有到目前为止所做的更改将立即生效。

Reload privilege tables now? [Y/n] 现在重新加载权限表(是/否)

All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.

全部完成!如果你已经完成了以上步骤,MariaDB安装现在应该安全。

Thanks for using MariaDB!

感谢使用MariaDB!

(15)进入MariaDB终端

小伙伴们, 经过以上努力, 终于是见到署光的时刻啦!

  • 如果说在 初始化MariaDB 中没有设置密码, 进入MariaDB终端, 直接输入 mysql 即可
1
[root@localhost ~]# mysql
  • 如果设置了密码则加入参数
    • -u: 用户名
    • -p: 密码
    • -P: 端口号
    • -h: 主机
    • 更多参数具体含义请参数 mysql --help 进行查看!
1
[root@localhost ~]# mysql -u u_setting_username -p

(16)编译安装后所有配置操作

注意: 这部分是对以上编译安装后mariadb配置所有操作的一个总结, 看客小伙伴们就不用再次执行了, 为此有不少小伙伴已入坑?, 博主深表歉意!不好意思让你入坑了, 实在是罪过哦!?

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

[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
Installing MariaDB/MySQL system tables in '/data/mysql/' ...
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:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain 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 MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql/'

You can test the MariaDB daemon with mysql-test-run.pl
cd './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@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# /etc/rc.d/init.d/mysqld start
Reloading systemd: [ OK ]
Starting mysqld (via systemctl): [ OK ]
[root@localhost mysql]# touch /etc/profile.d/mysql.sh
[root@localhost mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin/' > /etc/profile.d/mysql.sh
[root@localhost mysql]# chmod 0777 /etc/profile.d/mysql.sh
[root@localhost mysql]# source /etc/profile.d/mysql.sh
[root@localhost mysql]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.6-MariaDB-log Source distribution

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

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

MariaDB [(none)]>

7. 编译安装mysql

(1)安装依赖包

1
[root@vm ~] yum -y install gcc gcc-c++ ncurses ncurses-devel cmake

(2)下载相应源码包

1
2
[root@vm ~] mkdir -p /root/oneinstack/src
[root@vm ~] wget https://downloads.mysql.com/archives/get/file/mysql-boost-5.7.19.tar.gz

(3)添加mysql用户

1
[root@vm ~] useradd -M -s /sbin/nologin mysql

(4)预编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@vm ~] tar -zxvf mysql-boost-5.7.19.tar.gz
[root@vm ~] cd mysql-5.7.19/

[root@vm ~] mkdir -p /data/mysql

[root@vm ~] cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=~/mysql-5.7.19/boost \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1

[root@vm ~] make -j `grep processor /proc/cpuinfo | wc -l`

(5)编译安装

1
2
[root@vm ~] make -j `grep processor /proc/cpuinfo | wc -l` 
[root@vm ~] make install

编译很消耗系统资源,小内存可能编译通不过

启动脚本,设置开机自启动

1
2
3
4
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

(6)配置 /etc/my.cnf,仅供参考

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
70
71
72
73
74
75
76
77
78
cat > /etc/my.cnf << EOF
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF

(7)初始化数据库

1
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

注:

  1. 之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
  2. “–initialize"会生成一个随机密码(~/.mysql_secret),而”–initialize-insecure"不会生成密码
  3. –datadir目标目录下不能有数据文件

(8)启动数据库

1
service mysqld status
1
2
3
dbrootpwd=123456  #数据库root密码
/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"

8. mysql官网已编译二进制包安装

mysql和mariadb编译需要很长时间,而且在配置比较低的服务器上还可能编译失败,建议直接通过在线包管理工具(如yum或者apt)安装或者官网下载已经编译好的二进制程序进行安装,对于在线包管理工具这里就不介绍了。下面是就介绍已经编译好的二进制程序安装的方法。

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
# wget http://211.143.146.211/1Q2W3E4R5T6Y7U8I9O0P1Z2X3C4V5B/ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-10.2.14/bintar-linux-x86_64/mariadb-10.2.14-linux-x86_64.tar.gz
解压安装并指定解压路径/usr/local,创建软连接
# tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -s mariadb-10.2.14-linux-x86_64/ mysql
创建mysql用户,并指定家目录。
# mkdir /mysql
# useradd -r -m -s /sbin/nologin -d /mysql/data mysql
生成mysql数据库
# /usr/local/mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/usr/local/mysql --user=mysql

配置mysql的配置文件
# cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
# vim /etc/my.cnf ## 在[mysqld]节点下追加如下三行
[mysqld]
datadir = /mysql/data
innodb_file_per_table = ON
skip_name_resolve = ON

配置以支持chkconfig控制
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# systemctl restart mysqld
执行安全初始化数据库脚本
# /usr/local/mysql/bin/mysql_secure_installation

# vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin
# source /etc/profile.d/mysqld.sh

9.编译安装PHP7.1.17

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
解决依赖
# yum install -y epel-release
# yum -y install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel

编译安装
# wget http://cn2.php.net/distributions/php-7.1.17.tar.bz2
# tar xvf php-7.1.17.tar.bz2
# cd php-7.1.17
# ./configure --prefix=/usr/local/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支持
# make
# make install

提供php配置文件
# cp php.ini-production /etc/php.ini

编辑apache配置文件httpd.conf,以使apache支持php
# vim /usr/local/apache/conf/httpd.conf
添加如下两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
找到如下行并追加index.php 结果如下
DirectoryIndex index.html index.php

重启httpd服务以使配置生效
# systemctl restart httpd

测试httpd、mariadb、php是否能够协同工作
# rm -rf /usr/local/apache/htdocs/index.html
# vim /usr/local/apache/htdocs/index.php
<?php
$mysqli=new mysqli("localhost","root","123456");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
?>

打开http://192.168.10.10/ 能看到"连接数据库成功!"即可,否则请检查错误。

10.编译安装php-memcached扩展

最新版Xcache3.2最高只支持到PHP 5.6,所以PHP7不在支持列表里,我以这里我们使用php-memcached来提供缓存功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
编译安装libmemcached
# yum -y install cyrus-sasl-devel
# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
# tar -zxvf libmemcached-1.0.18.tar.gz
# cd libmemcached-1.0.18
# ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl
# make
# make install

编译安装php-memcached
# tar xvf memcached-3.0.4.tgz
# cd memcached-3.0.4
# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached
# make
# make install
# echo "extension=memcached.so" >> /etc/php.ini
# systemctl restart httpd


----------- 本文结束 -----------




如果你觉得我的文章对你有帮助,你可以打赏我哦~
0%