LAMP架构搭建

一.搭建准备:

安装包:apr-1.5.1.tar    httpd-2.4.33.tar       mysql-5.6.47-linux-glibc2.12-x86_64.tar       php-5.6.39.tar      redis-2.2.3     apr-util-1.5.4.tar        

操作系统: 使用centos7系统

二.搭建LAMP架构

1.安装mysql:本次解压后的文件都放在/usr/local/src下

yum -y install autoconf (安装autoconf)

tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar(解压MySQL安装包)

mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql(转移位置)

useradd -s /sbin/nologin mysql (创建MySQL用户)

mkdir -p /usr/local/mysql/data (创建数据仓库)

chown -R mysql:mysql /mysql/data (更改用户权限)

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql(运行)

cp support-file/my-default.cnf /etc/my.cnf(拷贝)

vim  my-default.cnf (修改配置文件)

Basedir=/usr/local/mysql(mysql包位置) 

Datadir=/data/mysql/datadir (数据存放位置)

Port=3306(端口号3306是默认端口号)

Server_id=10(服务ID我写的是主机地址)

socket = /tmp/mysql.sock 

cp  support-files/mysql.server  /etc/init.d/mysql(拷贝)

chmod  755  /etc/init.d/mysql(修改启动脚本文件的属性)

Vim /etc/init.d/mysql

定义basedir和datadir

chkconfig --add mysql(把服务添加到系统服务列表中)

chkconfig mysql on(设置开机自启)

 

 service mysql start(启动)

 

2.安装apache:

tar -zxvf httpd-2.4.33.tar

tar -zxvf apr-1.5.1.tar

tar -zxvf apr-util-1.5.4.tar

yum install -y expat-devel

yum install -y pcre pcre-devel

cd /usr/local/src/apr-1.5.1(到apr目录下)

./configure --prefix=/usr/local/apr

make &&make install

cd /usr/local/src/apr-util-1.5.4(到apr-util目录下)

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make &&make install

cd /usr/local/src/httpd-2.4.33(到httpd下)

./configure  --prefix=/usr/1ocal/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so 

--enable-mods-shared=most

make && make install

/usr/local/apache2.4/bin/apachectl -M(查看配置文件有哪些)

 

3.安装PHP:

tar -jxvf php-5.6.39.tar.bz2

yum install -y libxml2-devel

yum install -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.39

./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 && make install

 

4.httpd解析php:

vim /usr/local/apache2.4/conf/httpd.conf

修改ServerName www.example.com:80把他之前的#去掉

把<Directory />

    AllowOverride none

    Require all denied

</Directory>中denied改成granted   目的是允许请求访问

搜索AddType application/x-gzip .gz .tgz,在下面添加一行 AddType application/x-httpd-php .php;

把<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>中的DirectoryIndex index.html改成DirectoryIndex index.html index.php

/usr/local/apache2.4/bin/apachectl -t(测试文件是否正确如果出现Syntax OK则表示正确)

/usr/local/apache2.4/bin/apachectl start(启动httpd)

netstat -lnp |grep httpd(查看是否启动)

curl localhost(使用curl 命令)

<html><body><h1>It works!<h1><body><html>(使用curl命令的成功标志)

上一篇:Linux命令


下一篇:LAMP架构———源码编译安装