目录
1.安装MySQL
把软件包移动到/usr/local/src/下
-
- 初始化
#tar -xzvf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz //解压
#[ -d /usr/local/mysql ] && mv /usr/local/mysql mysql/usr/local/mysql_old
#mv mysql-5.6.45-linux-glibc2.12-x86_64 /usr/local/mysql
#useradd -s /sbin/nologin mysql //建立MySQL用户,启动时需要该用户
#cd usr/local/mysql
#mkdir -p /data/mysql //创建datadir,数据库文件会放到这里面
#chown -R mysql:mysql /data/mysql //更改权限
# ./scripts/mtsql_install_db --user=mysql --datadir=/data/mysql
出现问题
解决
# yum -y per-Module-Install
-
- 配置MySQL
#cp support-files/my-default.cnf /etc/my.cnf
2.安装Apache
2.1下载httpd-2.4.39.tar、apr-1.6.5.tar和apr-util-1.6.1.tar。
2.2 解压
#tar -zxvf httpd-2.4.39.tar
#tar -zxvf apr-1.6.5.tar
#tar -zxvf apr-util-1.6.1.tar
(3)安装和配置
# cd /usr/local/src/apr-1.5.2
# yum install -y expat-devel
# yum install -y libtool*
# ./configure --prefix=/usr/local/apr
# make &&make install //安装Make
# cd /usr/local/src/apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make &&make install
# cd httpd-2.4.49
# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
# make &&make install
# cd ..
# cp -r apr-1.5.2 httpd-2.4.49/srclib/apr
# cp -r apr-util-1.5.4 httpd-2.4.49/srclib/apr-util
# make &&make install
# /usr/local/apache2.4/bin/apachectl -M
(4)安装成功
3. 安装PHP
3.1下载 php-5.6.30.tar
3.2解压
#cd /usr/local/src
#tar -zxvf php-5.6.30.tar.gz
3.3安装和配置
#yum install -y libxml2-devel
#yum installl -y openssl openssl -devel
#yum install -y bzip2 bzip2-devel
#yum install -y libpng libpng-devel
#yum install -y freetype freetype-devel
#yum install -y epel-release
#yum install -y libmcrypt-devel
#cd php-5.6.30
#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir--with-gd --with-jpeg-dir --with-png-dir--with-freetype-dir --with-iconv-dir--with-zlib-dir --with-bz2 --with-openssl--with-mcrypt --enable-soap--enable-gd-native-ttf --enable-mbstring--enable-sockets --enable-exif
#make -j4 && make install
#vi ../conf/httpd.conf
安装成功
4.httpd解析PHP
4.1配置
#vim /usr/local/apache2.4/conf/httpd.conf //编辑httpd的主配置文件
搜索ServerName,把ServerName www.example.com:80前#去掉;
<Directory />
AllowOverride none
Require all denied
</Directory>
改为:
<Directory />
AllowOverride none
Require all granted
</Directory>
搜索AddType application/x-gzip .gz .tgz,在下面添加一行 AddType application/x-httpd-php .php;
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
改成:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
4.2测试安装
- 测试配置文件是否正确
#/usr/local/apache2.4/bin/apachectl -t //检验配置文件是否正确:Syntax OK
#/usr/local/apache2.4/bin/apachectl start //启动httpd命令
#netstat -lnp |grep httpd //查看是否启动
#curl localhost
<html><body><h1>It works!<h1><body><html> //使用curl命令简单测试,,显示了就是成功
- 检测是否正确解析PHP
#vi /usr/localapache2.4/htdocs/1.php
<?php
echo “php解析正确”
?> //编写一个测试脚本
#curl localhost/1.php
php解析正确 //PHP解析正确
4.3 安装成功
出现错误
解决
#yum install net-tools
二.任务2 Apache配置
1. 默认虚拟主机
# cd /usr/local/apache2.4/conf/
# vim httpd.conf //修改主配置文件
搜索vhosts,把Include conf/extra/httpd-vhosts.conf前#去掉
# cd /usr/local/apache2.4/conf/extra/
# cp httpd-vhosts.conf httpd-vhosts.conf-bak //备份配置文件
# vim httpd-vhosts.conf //修改配置内容如下:
<VirtualHost *:80>