环境介绍
- 虚拟机 : VMware Workstation 14 Pro
- 镜像 : CentOS Linux release 7.4.1708 (Core)
- 物理机 : windows 7 64位
防火墙设置
centos7.2系统默认开启了防火墙,需关闭外部才能访问到80端口
systemctl status firewalld.service # 查看防火墙服务状态
systemctl stop firewalld.service # 关闭防火墙
systemctl disable firewalld.service # 关闭防火墙开机自启动
安装EPEL软件源
yum install epel-release
编译安装apache
安装apache所需的软件包及相关依赖
yum install -y gcc gcc-c++ autoconf libtool
安装apr
cd /usr/local/src
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
tar zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make && make install
安装apr-util
cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
tar zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
安装pcre
cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz
tar zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure --prefix=/usr/local/pcre
make && make install
编译安装apache
cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz
tar zxvf httpd-2.4.23.tar.gz
cd httpd-2.4.23
./configure \
--prefix=/usr/local/apache --sysconfdir=/etc/httpd \
--enable-so --enable-cgi --enable-rewrite \
--with-zlib --with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most --enable-mpms-shared=all \
--with-mpm=event
make && make install
修改/etc/httpd/httpd.conf文件
将Require all denied改为Require all granted
# 在文件末尾添加
PidFile "/var/run/httpd.pid"
启动apache服务
/usr/local/apache/bin/apachectl start
访问IP地址
设置apache开机自启动
vim /etc/rc.d/rc.local
# 文件尾部添加如下一行指令
/usr/local/apache/bin/apachectl start
设置环境变量
vim /root/.bash_profile
# 在已有PATH的尾部追加apache bin目录
PATH=$PATH:$HOME/bin:/usr/local/apache/bin
编译安装mysql
检测系统中是否已存在mysql或mariadb
rpm -qa | grep mysql
rpm -qa | grep mariadb
若系统存在任何一个,则需要先进行删除再进行编译安装
安装mysql
yum install -y libaio-*#安装依赖
mkdir -p /usr/local/mysql
cd /usr/local/src
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64/* /usr/local/mysql/
建立mysql用户和组
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
初始化mysql数据库
/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/usr/local/mysql/data/--user=mysql
更改mysql目录的属主和属组
chown -R mysql:mysql /usr/local/mysql
设置开机启动
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
添加/etc/init.d/mysqld start到/etc/rc.d/rc.local中
启动并登录数据库
/etc/init.d/mysqld start
mysql -uroot -p # 默认密码为空
更改mysql密码
mysqladmin -uroot password '******'
编译安装php
依赖安装
yum install -y php-mcrypt libmcrypt libmcrypt-devel libxml2-devel openssl-devel libcurl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-turbo-devel libmcrypt-devel mysql-devel
安装php
cd /usr/local/src
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/php/php-5.4.45.tar.gz
tar zxvf php-5.4.45.tar.gz
cd php-5.4.45
./configure \
--prefix=/usr/local/php \
--with-mysql=mysqlnd --with-openssl \
--with-mysqli=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
make && make install
复制配置文件
cp /usr/local/src/php-5.4.45/php.ini-product /etc/php.ini
配置httpd.conf,使用apache支持php
vim /etc/httpd/httpd.conf
# 末尾增加如下两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
并修改DirectoryIndex index.html为DirectoryIndex index.php index.html
重启apache服务
/usr/local/apache/bin/apachectl restart
测试是否能正常解析php文件
vim /usr/local/apache/htdocs/phpinfo.php
<?php
phpinfo();
访问IP地址
显示可以正常解析