9.6云计算课程 基于lamp和apache搭建web网站
1.1 安装数据库
网上找到MySQL数据库安装包下载然后解压存放到/usr/local/src/
cd /usr/local/src/
# 1.切换到软件包目录
tar zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
# 2.解压
mkdir /usr/local/mysql
# 3.查看是否有 /usr/local/mysql这个文件夹,如果有那就重命名(mv) mysqlold。
# 然后创建(mkdir)/usr/local/mysql这个文件夹
cd mysql-5.6.43-linux-glibc2.12-x86_64
mv * /usr/local/mysql
# 4.将解压出来的文件移到/usr/local/mysql文件夹内
mkdir -p /data/mysql
# 5.创建数据库存放位置的文件夹
useradd -s /sbin/nologin mysql
# 6.创建mysql用户
chown -R mysql:mysql /data/mysql
# 7.更改文件夹权限
yum -y install perl-Module-Install
# 8.安装依赖包
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
# 9.安装mysql,如果成功/data/mysql目录下将会有文件和目录
1.2数据库配置
cd /usr/local/mysql
cp support-files/my-default.cnf /etc/my.cnf
# 1.将mysql源码包内的默认配置文件放入并命名 /etc/my.cnf
vim /etc/my.cnf
basedir = /usr/local/mysql # 源码存放目录
datadir = /data/mysql # 上文数据库存放目录
port = 3306 # 端口
server_id = 128 # 服务id
socket = /tmp/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
# 2.进入并修改/etc/my.cnf文件
# 开始设置自启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
vim /etc/init.d/mysqld
修改:
datadir=/data/mysql
# 3.复制文件,修改权限,修改配置
chkconfig --add mysqld
chkconfig mysqld on
service mysqld on
# 4.设置开机自启和启动服务
2.Apache
软件包存放目录:/usr/local/src/
2.1安装apache
cd /usr/local/src
wget http://...httpd-2.4.54.tar.gz
wget http://...apr-1.7.0.tar.gz
wget http://...apr-util-1.6.1.tar.gz
tar zxvf httpd-2.4.54.tar.gz
tar zxvf apr-1.7.0.tar.gz
tar zxvf apr-util-1.6.1.tar.gz
# 1.获取并解压源码包
yum -y install expat-devel libxml2-devel pcre pcre-devel
# 2.安装依赖包
cd /usr/local/src/apr-1.7.0
./configure --prefix=/usr/local/apr
make && make install
# 3.编译并安装apr
cd /usr/local/src/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
# 4.编译并安装apr-util
cd /usr/local/src/httpd-2.4.54
./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
# 5.编译并安装apache,如果安装成功那么/usr/local/apache2.4目录下将会有文件和目录
#如果需要重新编译,需要使用
make clean
#清除之前的缓存
配置虚拟主机
vim /usr/local/apache2.4/conf/httpd.conf
# 修改
#Include conf/extra/httpd-vhosts.conf
->
Include conf/extra/httpd-vhosts.conf
# 1.让配置文件生效
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# 修改
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com # 管理员邮箱 可忽略
DocumentRoot "/usr/local/apache2.4/docs/dummy-host.example.com" # 网站根目录
ServerName dummy-host.example.com # 网站web站点名
ServerAlias www.dummy-host.example.com # 站点别名 可忽略
ErrorLog "logs/dummy-host.example.com-error_log" # 错误访问日志
CustomLog "logs/dummy-host.example.com-access_log" common # 成功访问日志
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/usr/local/apache2.4/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
->
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache2.4/test.com"
ServerName test.com
ServerAlias www.test.com
ErrorLog "logs/dummy-host.example.com-err