LAMP环境搭建(源码包安装,仅测试)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP环境搭建(源码包安装,仅测试)相关的知识,希望对你有一定的参考价值。

linux系统+Apache服务+mysql数据库+php

安装顺序:PHP要在最后安装

首先将安装包上传到/root目录下

链接:http://pan.baidu.com/s/1nvbWEk5 密码:9r9w

********************************************************************************************************************************************************************************************************

安装配置Httpd

安装环境:

①httpd未安装,若已安装,先用rpm强制卸载

②防火墙关闭;或者防火墙开启80端口、22端口(远程控制)、3306端口(MySQL);selinux关闭

编译安装需要的make、 gcc、 gcc-c++在系统中是否已经安装

*******************************************************************************************************************************************************************************************************

 

编译安装

 [[email protected] ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src/  #解压

 [[email protected] ~]# cd /usr/src/httpd-2.2.17/  #进入解压目录

[[email protected] httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi && make && make install  #编译安装,启动模块支持

完成后进入/usr/local/httpd/查看安装结果

优化执行路径(加入到默认的搜索路径里)

[[email protected] httpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/  

也可以修改环境变量PATH。

添加http系统服务(添加到启动脚本,和开机启动控制)

[[email protected] httpd-2.2.17]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd  #添加启动脚本

[[email protected] httpd-2.2.17]# chmod +x /etc/init.d/httpd  #给脚本加执行权限

[[email protected] httpd-2.2.17]# sed -i -e ‘1a#chkconfig: 35 80 20\\n#description: Startup script for the Apache HTTP Server‘ /etc/init.d/httpd  #加入chkconfig管理文本

[[email protected] httpd-2.2.17]# chkconfig --add httpd  #设置开机启动

确定网站名称和IP地址

[[email protected] httpd-2.2.17]# cd

[[email protected] ~]# hostname www.amber.com

[[email protected] ~]# echo "192.168.108.111 www.amber.com">> /etc/hosts  

备份主配置文件

[[email protected] ~]# cd /usr/local/httpd/conf/

[[email protected] conf]# cp httpd.conf httpd.conf.bak

配置并启动httpd服务

[[email protected] conf]# sed -i -e ‘/#ServerName/ s/#//;s/example/amber/‘ httpd.conf

安装后发现这个版本默认不支持utf-8,所以我就加入了下面的命令:

echo "AddDefaultCharset UTF-8" >> /usr/local/httpd/conf/httpd.conf

[[email protected] conf]# httpd -t  #测试语法OK

Syntax OK

[[email protected] conf]# /etc/init.d/httpd start  #启动服务

[[email protected] conf]# netstat -anpt | grep :80  #查看服务详细的状态

tcp        0      0 :::80                       :::*                        LISTEN      110649/httpd

部署网页文档

vim /usr/local/httpd/htdocs/index.html

将It works! 改成  你的httpd服务配置成功啦!

用windows系统测试

在hosts文件中添加192.168.108.111 www.amber.com

打开浏览器,访问www.amber.com

弹出:你的httpd服务配置成功啦!

 

****************************************************************************

安装配置mysql

安装环境:

①先卸载rpm安装的mysql-server和mysql

②光盘自带的ncurses-devel安装(一般都安装上了)

****************************************************************************

准备工作:

[[email protected] ~]# rpm -q mysql-server mysql

package mysql-server is not installed

mysql-5.1.73-8.el6_8.x86_64

[[email protected] ~]# rpm -e mysql --nodeps

编译安装cmake包

[[email protected] ~]# tar xf cmake-2.8.12.tar.gz -C /usr/src/ #解压

[[email protected] ~]# cd /usr/src/cmake-2.8.12/  #进入解压目录

[[email protected] cmake-2.8.12]# ./configure && gmake && gmake install  #编译安装

等待……

[[email protected] cmake-2.8.12]# cd

创建MySQL用户和组

[[email protected] ~]# useradd -M -s /sbin/nologin mysql

编译安装MySQL

[[email protected] ~]# tar xf mysql-5.7.2-m12.tar.gz -C /usr/src/  #解压

[[email protected] ~]# cd /usr/src/mysql-5.7.2-m12/  #进入解压目录

[[email protected] mysql-5.7.2-m12]# cmake -DCMAK_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTTA_CHARSETS=all -DSYSCONFDIR=/etc && make && make install  #编译安装

安装后的调整

①目录权限设置

[[email protected] mysql-5.7.2-m12]# chown -R mysql:mysql /usr/local/mysql/

②建立配置文件

[[email protected] mysql-5.7.2-m12]# cp support-files/my-default.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

③初始化数据库

[[email protected] mysql-5.7.2-m12]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

④设置环境变量

[[email protected] mysql-5.7.2-m12]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

[[email protected] mysql-5.7.2-m12]# source /etc/profile

添加mysqld系统服务,实现chkconfig管理

[[email protected] mysql-5.7.2-m12]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql-5.7.2-m12]# chmod +x /etc/init.d/mysqld

[[email protected] mysql-5.7.2-m12]# chkconfig --add mysqld

[[email protected] mysql-5.7.2-m12]# chkconfig --list mysqld

mysqld            0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭

启动mysql服务

[[email protected] mysql-5.7.2-m12]# /etc/init.d/mysqld start

Starting MySQL...                                          [确定]

[[email protected] mysql-5.7.2-m12]# netstat -anpt | grep mysqld

tcp        0      0 :::3306                     :::*                        LISTEN      50913/mysqld

登录mysql

①无密码登录

mysql -u root     CTRL + D 键退出

②设置管理员登录密码

[[email protected] ~]# mysqladmin -u root password "123";history -c

[[email protected] ~]# mysql -u root -p

Enter password:

③修改管理员密码

[[email protected] ~]# mysqladmin -u root -p password "123456" #新的密码

Enter password: #输入旧的密码

****************************************************************************

安装配置php

****************************************************************************

准备安装环境

[[email protected] ~]# rpm -q php php-cli php-ldap php-common php-mysql  【查看系统有没有装PHP,如果有就先干掉】

package php is not installed

package php-cli is not installed

package php-ldap is not installed

package php-common is not installed

package php-mysql is not installed

[[email protected] ~]# rpm -q zlib-devel libxml2-devel  【以下两个需要安装到系统】

zlib-devel-1.2.3-29.el6.x86_64

libxml2-devel-2.7.6-21.el6_8.1.x86_64

安装数据加密工具 (libmcrypt; mhash; mcrypt)【最后一个要最后安装】

[[email protected] ~]# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/

[[email protected] ~]# cd /usr/src/libmcrypt-2.5.8/

[[email protected] libmcrypt-2.5.8]# ./configure && make && make install

[[email protected] libmcrypt-2.5.8]# ln -s /usr/local/lib/libmcrypt* /usr/lib

[[email protected] libmcrypt-2.5.8]# cd

-------------------------------------------

[[email protected] ~]# tar xf mhash-0.9.9.9.tar.gz -C /usr/src/

[[email protected] ~]# cd /usr/src/mhash-0.9.9.9/

[[email protected] mhash-0.9.9.9]# ./configure && make && make install

[[email protected] mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.* /usr/lib/

[[email protected] mhash-0.9.9.9]# cd

--------------------------------------------

[[email protected] ~]# tar xf mcrypt-2.6.8.tar.gz -C /usr/src/

[[email protected] ~]# cd /usr/src/mcrypt-2.6.8/

[[email protected] mcrypt-2.6.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

[[email protected] mcrypt-2.6.8]# ./configure && make && make install

[[email protected] mcrypt-2.6.8]# cd

编译安装PHP

[[email protected] ~]# tar xf php-5.3.28.tar.gz -C /usr/src/  #解压

[[email protected] ~]# cd /usr/src/php-5.3.28/  #进入解压目录

[[email protected] php-5.3.28]# ./configure --prefix=/usr/local/php5 --with-mcrypt --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql/ --with-config-file-path=/usr/local/php5 --enable-mbstring && make && make install  #编译

建立主配置文件php.ini 并进行调整

[[email protected] php-5.3.28]# cp php.ini-development /usr/local/php5/php.ini

[[email protected] php-5.3.28]# cd

[[email protected] ~]# sed -i ‘/^short_open_tag/ s/Off/On/‘ /usr/local/php5/php.ini  #开启此模块

[[email protected] ~]# sed -i ‘/^;default_charset/ s/;//;s/iso-8859-1/utf-8/‘ /usr/local/php5/php.ini  #默认字符集utf-8

添加ZendGuardLoader优化模块,提高PHP程序的执行效率

[[email protected] ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz -C /usr/src/

[[email protected] ~]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/

[[email protected] ZendGuardLoader-php-5.3-linux-glibc23-x86_64]# cd php-5.3.x/

[[email protected] php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php/

[[email protected] php-5.3.x]# echo -e "zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\\nzend_loader.enable=1" >>/usr/local/php5/php.ini

[[email protected] php-5.3.x]# cd

A M P 软件包都安装配置完成,接下来关联Apache和mysql

httpd.conf调整

[[email protected] ~]# sed -i ‘/LoadModule php5_module/a\\AddType application/x-httpd-php .php‘ /usr/local/httpd/conf/httpd.conf

[[email protected] conf]# sed -i ‘/DirectoryIndex index.html/ s/$/ index.php/‘ /usr/local/httpd/conf/httpd.conf

[[email protected] conf]# httpd -t

Syntax OK

[[email protected] conf]# cd

[[email protected] ~]# /etc/init.d/httpd stop

[[email protected] ~]# /etc/init.d/httpd start

 

测试LAMP协同工作

测试PHP网页是否能正常显示

[[email protected] ~]# cat << END >> /usr/local/httpd/htdocs/test.php

> <?php

> phpinfo();

> ?>

> END

访问192.168.108.111/test.php

 技术分享

 

测试PHP网页能否访问MySQL数据库

[[email protected] ~]# vim /usr/local/httpd/htdocs/test1.php

<?php

$link=mysql_connect(‘localhost‘,‘root‘,‘123‘);

if($link) echo "恭喜你,数据库连接成功啦!!";

mysql_close();

?>

 技术分享

 

 

LAMP环境搭建成功了!!

可以安装phpMyAdmin和bbs,运行一下

 

 

数据库客户端应用

[[email protected] ~]# mkdir /aaa

[[email protected] ~]# tar xf phpMyAdmin-4.2.5-all-languages.tar.gz -C /aaa

[[email protected] ~]# cd /aaa

[[email protected] aaa]# ls

phpMyAdmin-4.2.5-all-languages

[[email protected] aaa]# mv phpMyAdmin-4.2.5-all-languages/ /usr/local/httpd/htdocs/phpMyAdmin

 技术分享

 

 

BBS应用

[[email protected] ~]# unzip  Discuz_7.2_FULL_SC_UTF8.zip –C /aaa

[[email protected] aaa]# mv upload/ /usr/local/httpd/htdocs/bbs/

 技术分享

 

以上是关于LAMP环境搭建(源码包安装,仅测试)的主要内容,如果未能解决你的问题,请参考以下文章

源码包搭建LAMP环境

LAMP 环境搭建

Centos7.4源码搭建LAMP环境

2-24 源码编译搭建LAMP环境

源码编译安装LAMP

web应用之LAMP源码环境部署