布置实验环境
关闭防火墙 iptables -F
禁用selinux setenforce 0
配置yum源(包括本地源和epel源) :
[base]
name=kbq
baseurl=file:///mnt
gpgcheck=0
[epel]
name=kbqe
baseurl=http://172.16.0.1/fedora-epel/7/x86_64/
gpgcheck=0
准备软件包
将准备的软件包上传至/src中
[root@centos7 src]# ls
apr-1.5.2.tar.bz2 php-7.1.7.tar.bz2
apr-util-1.5.4.tar.bz2 wordpress-4.8-zh_CN.tar.gz
httpd-2.4.27.tar.bz2 xcache-3.2.0.tar.gz
mariadb-10.2.7-linux-x86_64.tar.gz
编译安装http
先将3个软件包解压
tar xvf apr-1.5.2.tar.bz2
tar xvf apr-util-1.5.4.tar.bz2
tar xvf httpd-2.4.27.tar.bz2
将apr的2个包移入httpd-2.4.27下的srclib中并改名
[root@centos7 src]# mv apr-1.5.2 httpd-2.4.27/srclib/apr
[root@centos7 src]# mv apr-util-1.5.4 httpd-2.4.27/srclib/apr-util
进入httpd-2.4.27目录中进行编译
./configure --prefix=/app/httpd24 --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
若为最小化安装系统,在首次编译时会提示缺少一些包组;
yum -y install openssl-devel pcre-devel
再尝试安装即可。
make && make install
编译成功后可将二进制程序的路径添加至默认路径中。
export PATH=/app/httpd24/bin:usr/local/mysql/bin:$PATH
查看端口是否打开并打开网站。
[root@centos7 httpd-2.4.27]# apachectl
[root@centos7 httpd-2.4.27]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
安装mariadb
先用rpm -qa "mariadb*"查看有无安装过该包组,若有需使用yum -remove 该包组防止与我们编译安装的mariadb冲突。
将mariadb压缩包解压到/usr/local下并创建一个软连接
tar xvf mariadb-10.2.7-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -s mariadb-10.2.7-linux-x86_64/ mysql
查看有无mysql用户若不存在则创建这个用户
[root@centos7 local]# getent passwd mysql
[root@centos7 local]# useradd -r mysql -s /sbin/nologin -d /app/mysqldb -m
[root@centos7 local]# getent passwd mysql
mysql:x:997:995::/app/mysqldb:/sbin/nologin
生成数据库
cd mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
在本次实验中采用的是最小化安装系统,缺少了libaio-0.3.107- 10.el6.x86_64这个rpm包,所以在生成数据库时会报错。所以需要先安装这个包即可。rpm -ivh libaio-0.3.107-10.el6.x86_64
此时查看/app/mysql目录下已生成数据库
[root@centos7 mysql]# ls /app/mysqldb/
aria_log.00000001 ibdata1 mysql
aria_log_control ib_logfile0 performance_schema
ib_buffer_pool ib_logfile1 test
复制对应的配置文件到/etc/mysql下
[root@centos7 mysql]# mkdir /etc/mysql
[root@centos7 mysql]# cp support-files/my-huge.cnf /etc/mysql/my.cnf
[root@centos7 mysql]# vim /etc/mysql/my.cnf
在【mysql】中加入三行
datadir =/app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
###复制服务脚本并添加服务
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
将路径添加至PATH变量中
vim /etc/profile.d/app.sh
export PATH=/usr/local/mysql/bin:/app/httpd24/bin:$PATH
. /etc/profile.d/app.sh
service mysqld start
安全初始化
mysql_secure_installation
mysql -uroot -pmagedu
MariaDB [(none)]> create database blogdb;
MariaDB [(none)]>grant all on blogdb.* to wpuser@'192.168.8.%' identified by "magedu";
编译安装php
tar xvf php-7.1.7.tar.bz2
cd /root/src/php-7.1.7/
yum -y install libxml2-devel bzip2-devel libmcrypt-devel
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
make && make install
cp php.ini-production /etc/php.ini
vim /app/httpd24/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
apachectl stop
apachectl start
5
tar xf wordpress-4.8-zh_CN.tar.gz
mv wordpress /app/httpd24/htdocs/blog
setfacl -m u:daemon:rwx blog/