一、编译安装mysql
安装依赖包与工具
# yum install -y gcc gcc-c++ ncurses-devel perl
# yum install -y cmake
下载mysql安装包
# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.62.tar.gz
安装前准备
# groupadd mysql
# useradd -g mysql mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
编译安装mysql
# tar -zxv -f mysql-5.5.62.tar.gz
#cd mysql-5.5.62
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
#make && make install
修改权限
# chown -R mysql.mysql /usr/local/mysql
初始化mysql数据库
# cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
复制mysql服务启动配置文件和脚本
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
启动mysql服务
# service mysqld start
或者
#systemctl start mysqld (完成上述配置后重载系统管理器# systemctl daemon-reload 可直接使用systemctl命令)
检查登录
# ln -s /usr/local/mysql/bin/mysql /usr/bin
# mysql -uroot -p
附:自定义服务启动文件
# cat /usr/lib/systemd/system/mysqld.service
[unit]
# 定义启动顺序与依赖关系
Description=MySQL Server
After=network.target
After=syslog.target
[Install]
# 定义开机启动模块,用于设置enable/disable
WantedBy=multi-user.target
[Service]
# 定义启动行为,start/stop/restart
User=mysql
Group=mysql
PIDFile=/data/mysql/localhost.localdomain.pid
PermissionsStartOnly=true
ExecStart=/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
二、编译安装httpd
准备安装包
# wget http://mirrors.sohu.com/apache/httpd-2.4.37.tar.gz
# tar -xzf httpd-2.4.37.tar.gz
# cd httpd-2.4.37
安装依赖包
# yum install -y pcre* apr*
编译安装httpd
# ./configure --prefix=/usr/local/httpd
# make && make install
编辑启动文件
# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
重载系统管理器
# systemctl daemon-reload
启动服务
# systemctl start httpd
编辑配置文件
# vi /usr/local/httpd/conf/httpd.conf
# ln -s /usr/local/httpd/conf/httpd.conf /etc/ (配置文件软连接映射到/etc下面)
测试
# vim /usr/local/httpd/htdocs/index.html
<html><body>It works!</body></html>
<html><head>Good boy!</head></html>
# systemctl start httpd
三、编译安装PHP
准备安装包
# wget http://mirrors.sohu.com/php/php-7.2.5.tar.gz
# tar -xzf php-7.2.5.tar.gz
# cd php-7.2.5
安装依赖包
# yum install bzip2-devel.x86_64 openssl* libxml2*
编译安装PHP
# ./configure
--prefix=/usr/local/php
--with-mysqli=mysqlnd ##mysql支持
--with-pdo-mysql=mysqlnd
--with-openssl
--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/httpd/bin/apxs ##httpd支持
--with-config-file-path=/etc ##php.ini 配置文件路径
--with-config-file-scan-dir=/etc/php.d
--with-bz2
--enable-maintainer-zts
拷贝配置文件(位于解压的包)
# cp /wh_k/php-7.2.5/php.ini-production /etc/php.ini
配置文件httpd.conf支持php
# vim /etc/httpd.conf
在 LoadModule php7_module modules/libphp7.so后面添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改DirectoryIndex index.html为:
DirectoryIndex index.php index.html
添加测试页面
# vim /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>
重启httpd服务测试
# systemctl restart httpd
http://192.168.61.130/index.php
测试mysql支持
添加mysql用户
mysql> grant all on mysql.* to 'mysql'@'localhost' identified by 'redhat';
mysql> flush privileges;
配置测试页面
# vim /usr/local/httpd/htdocs/test.php
<?php
$log_in = mysqli_connect('127.0.0.1','mysql','redhat');
if ($log_in)
echo "Success.You are so good!";
else
echo "Failure.You are so bad!";
?>
重启httpd服务测试
# systemctl restart httpd
http://192.168.61.130/test.php