Centos-6搭建LAMP架构
创新互联是一家专注于成都网站设计、网站建设和四川雅安电信机房的网络公司,有着丰富的建站经验和案例。
编译安装apache
1,搭建网络YUM源
Wget http://mirrors.aliyun.com/repo/Centos-6.repo
Yum -y install epel-release
2,删除自带httpd程序并安装httpd的依赖库程序和安装环境、编译工具
Yum -y remove httpd
Yum -y install pcre-devel openssl-devel perl gcc gcc-c++
3,编译apr apr-util (先把三个包准备好,并把httpd脚本也放进来)
并把目前需要的三个包依次解压到指定路径
Cd /usr/src/apr-1.5.2
./configure --prefix=/usr/local/apr && make && make install #编译apr
Cd /usr/src/apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
#编译apr-util
4,创建程序用户并编辑httpd
Useradd -r httpd
Tail -1 /etc/passwd #可查看到用户是否创建成功
Cd /usr/src/httpd-2.4.10
Rm -rf /etc/httpd #删除之前的httpd配置文件
./configure --prefix=/usr/local/apache --sysconf=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-arp=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event && make && make install #编译httpd
5,优化执行路径(PATH路径),并重读配置路径
Cd /usr/local/apache/bin #进入
Vim /etc/profile.d/httpd.sh #配置环境变量
. /etc/profile.d/httpd.sh #执行脚本
Httpd -t #检查语法,可测试httpd的环境变量是否生效
Vim /etc/httpd/httpd.conf #开启中心主机并修改httpd域名
6,复制服务启停脚本并修改
Cd ~
Vim httpd
Mv httpd /etc/init.d/
Service httpd start #启动httpd服务
Ss -tnl #查看80端口是否监听
7,启用deflate和rewrite模块,并更改属主和属组
Vim /etc/httpd/httpd.conf
Ps aux #查看是否更改成功
8,检查语法并启动服务,在浏览器验证服务是否开启
Httpd -t
Service httpd restart
编译安装mariadb
1,安装依赖库
yum -y install ncurses-devel libevent-devel
2,安装编译工具,然后清除编译缓存文件
Cd /usr/src/cmake-2.8.12.2
./bootstrap && gmake && gmake install
rm -rf CMakeCache.txt
3,创建MySQL程序用户及数据库的data目录,并开始编译mariadb
Mkdir -pv /mydata/data
Useradd -r mysql
Cd /usr/src/mariadb-5.5.44
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && make && make install
4,修改mysql配置目录和data目录的属主属组
Chown -R root.mysql /mydata
Chown -R root.mysql /usr/local/mysql
5,复制和配置mysql主配置文件,然后复制服务启停脚本
Cat /usr/local/mysql/support-files/my-medium.cnf > /etc/my.cnf
Vim /etc/my.cnf
Cp -p /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
6,初始化mysql(在/etc/local/mysql路径下)
scripts/mysql_install_db --user=mysql --datadir=/mydata/data
7,将httpd和mysql开机自启
Chkconfig --add httpd
Chkconfig --add mysqld
Chkconfig httpd on
Chkconfig mysqld on
8,优化path路径,然后启动服务,验证效果并修改root用户密码
vim /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh #启动脚本
Service mysqld start
Ss -tnl #查看3306端口是否监听
Mysql #进入mysql命令行界面
Use mysql #进入mysql数据库
Delete from mysql.user where user=’’;
给root用户设置密码
update user set password=password('666666');
flush privileges;
Mysql -u root -p #进入mysql需要输入密码
安装PHP5.5.7
1,安装依赖库和相应环境
yum -y install bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel sqlite-devel jemalloc jemalloc-devel
2,开始编译php5.5.7
Cd ~
Tar xf php-5.5.7.tar.gz -C /usr/src
Cd /usr/src/php-5.5.7
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --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 --with-bz2 --enable-maintainer-zts && make && make install
3,打开httpd主配置文件,确定php模块是否加入,并修改配置信息支持php勾连
Vim /etc/httpd/httpd.conf
Httpd -t
Service httpd restart
4,拷贝php的主配置文件
cp -p /usr/src/php-5.5.7/php.ini-production /etc/php.ini
5,重启apache服务,编写测试页,验证LAMAP架构的勾连
Service httpd restart
Cd /usr/local/apache/htdocs
Mv index.html index.php
Vim index.php
在浏览器上验证即可
部署phpmyadmin
1,解压phpmyadmin并把文件移动到apache内
Tar xf phpMyAdmin-4.0.10.17-all-languages.tar.gz
Mv phpMyAdmin-4.0.10.17-all-languages phpmyadmin
Cp -rf phpmyadmin/ /usr/local/apache/htdocs/
2,复制主配置文件
cp config.sample.inc.php config.inc.php
Vim config.inc.php
3,在浏览器上验证即可