设为首页 收藏本站
查看: 930|回复: 0

LAMP平台的部署

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-8 08:49:47 | 显示全部楼层 |阅读模式
LAMP平台的搭建
1. 系统环境:

1)软件包版本:

httpd-2.2.9

mysql-5.1.56

php-

2)系统:CentOSrelease 6.4 (Final)- 2.6.32-358.el6.x86_64

3)系统关闭防火墙,禁用selinux

servicesiptables stop

chkconfigiptables off

sed -i‘s/enforcing/disabled/g’ /etc/selinux/config

setenforce0
2. 部署
2.1 部署apache
2.1.1 安装apache

快速执行命令:

cd /usr/src/

wget http://down1.chinaunix.net/distfiles/httpd-2.2.9.tar.bz2

tar jxf httpd-2.2.9.tar.bz2

cd httpd-2.2.9

./configure --prefix=/usr/local/httpd-2.2.9--enable-so --enable-rewrite --enable-cgi --enable-cgid--enable-mpms-shared=all --with-zlib --with-pcre

make && make install



演示步骤:
1
2
3
4
5
6
   
[iyunv@LAMP~]# cd /usr/src/
[iyunv@LAMPsrc]# wget http://down1.chinaunix.net/distfiles/httpd-2.2.9.tar.bz2
[iyunv@LAMPsrc]# tar jxf httpd-2.2.9.tar.bz2
[iyunv@LAMPsrc]# cd httpd-2.2.9
[root@LAMPhttpd-2.2.9]#  ./configure--prefix=/usr/local/httpd-2.2.9 --enable-so --enable-rewrite --enable-cgi--enable-cgid--enable-mpms-shared=all  --with-zlib --with-pcre
[root@LAMPhttpd-2.2.9]# make && make install


2.1.2 配置apache

1) 优化执行路径

快速执行命令:

cd /usr/local/

ln -s httpd-2.2.9/ httpd

ln -sf /usr/local/httpd-2.2.9/bin/* /usr/bin/



操作演示
1
2
3
4
5
6
   
[root@LAMPhttpd-2.2.9]# cd /usr/local/
[iyunv@LAMPlocal]#  ln -s httpd-2.4.4/ httpd
[iyunv@LAMPlocal]#  ln -sf/usr/local/httpd-2.4.4/bin/* /usr/bin/
[iyunv@LAMPlocal]# httpd -v           //测试结果。可以看到apache的版本,路径优化成功
Serverversion: Apache/2.2.9 (Unix)
Serverbuilt:   Jan 17 2015 20:26:25


2) 设置开机自启动,并启动apache

快捷命令:

cp /usr/local/httpd-2.2.9/bin/apachectl/etc/init.d/httpd

chmod a+x /etc/init.d/httpd

sed -i '1a #description:Apache Controller Script'/etc/init.d/httpd

sed -i '2a #chkconfig:- 85 15'  /etc/init.d/httpd

chkconfig --add httpd

chkconfig httpd on

service httpd start

netstat -anput | grep httpd



操作演示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   
[iyunv@LAMP~]# cp /usr/local/httpd-2.4.4/bin/apachectl /etc/init.d/httpd   //创建控制脚本
[iyunv@LAMP~]#  sed -i '1a #description:Apache ControllerScript' /etc/init.d/httpd  [iyunv@LAMP ~]# sed -i '2a #chkconfig:- 85 15'  /etc/init.d/httpd     //在脚本中添加控制级别,若没有此两行,则无法正常加入系统服务。此操作也可以手动用vim编辑器添加
[iyunv@LAMP~]#  chmod a+x /etc/init.d/httpd    //给控制脚本赋予执行权限,否则无法用server命令控制
[iyunv@LAMP~]#  head -3 /etc/init.d/httpd   //查看添加是否成功   
#!/bin/sh
#description:Apache ControllerScript
#chkconfig:-85 15
[iyunv@LAMP~]#  ll /etc/init.d/httpd    //查看权限是否赋予正确
-rwxr-xr-x1 root root 3512 12月 16 12:38 /etc/init.d/httpd
[iyunv@LAMP~]# chkconfig --add httpd
[iyunv@LAMP~]# chkconfig httpd on
[iyunv@LAMP~]# chkconfig --list | grep httpd
httpd           0:off   1:off  2:on    3:on    4:on   5:on    6:off
[iyunv@LAMP ~]# service httpd start
httpd: apr_sockaddr_info_get() failed for LAMP
httpd: Could not reliably determine the server's fullyqualified domain name, using 127.0.0.1 for ServerName
提示:该两条信息是由于没有定义网站域名造成的,使用下面的命令。即可解决
[iyunv@LAMP ~]# egrep "ServerName"/usr/local/httpd/conf/httpd.conf | tail -1
#ServerName www.example.com:80
[iyunv@LAMP ~]# sed -i"s/#ServerName/ServerName/g" /usr/local/httpd/conf/httpd.conf
[iyunv@LAMP ~]# sed -i"s/www.example.com/127.0.0.1/g" /usr/local/httpd/conf/httpd.conf
[iyunv@LAMP ~]# egrep "ServerName"/usr/local/httpd/conf/httpd.conf | tail -1         
ServerName 127.0.0.1:80


2.1.3 客户端测试:

wKiom1UjyneTbqCcAACVCB2GC6M346.jpg

测试成功,apache安装已经OK了


2.2部署MySQL
2.2.1安装MySQL

1)创建mysql帐号

useradd-M -s /sbin/nologin -u 49 mysql

执行过程:

[iyunv@LAMP~]# useradd -M -s /sbin/nologin -u 49 mysql

[iyunv@LAMP~]# cat /etc/passwd | grep mysql

mysql:x:49:500::/home/mysql:/sbin/nologin

参数说明:

-M 不创建mysql家目录

-s 指定mysql登录的shell环境,nologin表示不登录shell

-u 指定mysql用户的uid

2) 检查系统是否存在mysql,存在则卸载。此外还要安装ncurses ncurses-devel

[iyunv@LAMP~]# rpm -q mysqld

package mysqld isnot installed

[iyunv@LAMP~]# yum installncurses ncurses-devel -y

3)下载mysql软件包,编译安装

cd /usr/src/   

wget http://down1.chinaunix.net/distfiles/mysql-5.1.56.tar.gz

tar zxf mysql-5.1.56.tar.gz

cd mysql-5.1.56

./configure--prefix=/usr/local/mysql-5.1.56 --with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  --with-charset=utf8--with-collation=utf8_general_ci   --with-extra-charsets=gbk,gb2312--localstatedir=/usr/local/mysql-5.1.56/data --enable-assembler--with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --enable-thread-safe-client--with-mysqld-user=mysql --with-big-table --without-debug  --with-pthread

make&& make install

执行过程:
1
2
3
4
   
[iyunv@LAMPsrc]#  tar zxf  mysql-5.1.56.tar.gz
[iyunv@LAMPsrc]#  cd mysql-5.1.56
[root@LAMPmysql-5.1.56]# ./configure --prefix=/usr/local/mysql-5.1.56--with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  --with-charset=utf8--with-collation=utf8_general_ci   --with-extra-charsets=gbk,gb2312--localstatedir=/usr/local/mysql-5.1.56/data --enable-assembler --with-mysqld-ldflags=-all-static  --with-client-ldflags=-all-static--enable-thread-safe-client --with-mysqld-user=mysql --with-big-table--without-debug  --with-pthread
[root@LAMPmysql-5.1.56]# make && make install


参数解释:

     ./configure --prefix=/usr/local/mysql-5.1.56       #指定安装路径

      --with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  \ #指定mysql.sock位置

      --with-charset=utf8          #指定mysql默认的字符集

       --with-collation=utf8_general_ci     

       --with-extra-charsets=gbk,gb2312    #指定mysql可扩展的字符集

      --localstatedir=/usr/local/mysql-5.1.56/data     #指定mysql 数据库文件存放的位置

      --enable-assembler     #允许使用汇编模式(优化性能)

      --with-mysqld-ldflags=-all-static   #服务器使用静态库(优化性能)

      --with-client-ldflags=-all-static   #客户端使用静态库(优化性能)

      --enable-thread-safe-client      #以线程方式编译mysql

     --with-mysqld-user=mysql        #指定mysql运行的用户

      --with-big-tables     #支持大表格式

      --without-debug     #使用非debug模式

      --with-pthread        #强制使用pthread线程序库编译

      配置完成之后,没有error提示,出现thanke you for choosemysql即可执行make 编译安装,最后make install 安装到系统

Thank you for choosing MySQL!

Remember to check the platform specific part of thereference manual

for hints about installing MySQL on your platform.

Also have a look at the files in the Docs directory.


2.2.2配置MySQL

1)生成mysql 的主配置文件 my.cnf
1
2
   
[root@LAMPmysql-5.1.56]# cp -f /usr/src/mysql-5.1.56/support-files/my-medium.cnf/etc/my.cnf
cp:overwrite `/etc/my.cnf'? y           #覆盖掉原来的即可

2)生成mysql的启动文件,便于管理
1
2
3
4
   
[root@LAMPmysql-5.1.56]# cp -f/usr/src/mysql-5.1.56/support-files/mysql.server/etc/init.d/mysqld
[root@LAMPmysql-5.1.56]# chmod a+x /etc/init.d/mysqld
[root@LAMPmysql-5.1.56]# chkconfig --add mysqld
[root@LAMPmysql-5.1.56]# chkconfig mysqld on

3)链接mysql执行路径
1
2
3
4
   
[iyunv@LAMP~]# ln -sf /usr/local/mysql-5.1.56/bin/* /usr/local/bin/
[iyunv@LAMP~]# ln -sf /usr/local/mysql-5.1.56/lib/mysql/* /usr/lib
[iyunv@LAMP~]# ln -sf /usr/local/mysql-5.1.56/include/mysql/* /usr/include/
[iyunv@LAMP~]# ln -sf /usr/local/mysql-5.1.56/ /usr/local/mysql

5)初始化数据库
1
2
3
   
[iyunv@LAMP~]# cd /usr/local/mysql/bin/
[iyunv@LAMPbin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.1.56/--datadir=/usr/local/mysql-5.1.56/data
当出现两个OK时,表示初始化成功

6)设置权限
1
2
   
[iyunv@LAMPbin]# chown -R root:mysql /usr/local/mysql-5.1.56/
[iyunv@LAMPbin]# chown -R mysql /usr/local/mysql-5.1.56/data/

7)启动mysql
1
2
3
4
   
[iyunv@LAMPbin]# service mysqld start   
StartingMySQL SUCCESS!
[iyunv@LAMPbin]# netstat -anput | grep mysql
tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      42386/mysqld




2.3部署PHP
2.3.1安装php所需的组件(libiconv,libmcrypt,mhash,mcrypt-install)

1) 安装libiconv

cd /usr/src

wget http://down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

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

make && make install

2) 安装libmcrypt

cd /usr/src

wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz

tar zxf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure
make
make install

2) 安装mhash

cd /usr/src

wget http://down1.chinaunix.net/distfiles/mhash-0.9.3.tar.gz

tar zxf mhash-0.9.3.tar.gz

cd mhash-0.9.3

./configure

make
make install

4)安装mcrypt

cd /usr/src

wget http://down1.chinaunix.net/distfiles/mcrypt-2.6.4.tar.gz

tar zxf mcrypt-2.6.4.tar.gz

cd mcrypt-2.6.4

echo "/usr/local/lib">>/etc/ld.so.conf

/sbin/ldconfig

./configure

make
make install


2.3.2安装PHP

1)安装所需组件包

yum install zlib libxml2 libjpeg freetype libpnggd  curl   zlib-devel libxml2-devel libjpeg-develfreetype-devel libpng-devel gd-devel openssl openssl-devel curl-devel –y

2)下载PHP包进行编译安装

cd /usr/src

wget http://down1.chinaunix.net/distfiles/php-5.3.6.tar.bz2

tar jxf php-5.3.6.tar.bz2

cd php-5.3.6

./configure --prefix=/usr/local/php --with-mcrypt--with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql--with-config-file-path=/usr/local/php --enable-mbstring -with-iconv=/usr/local/libiconv--enable-static  --with-xmlrpc --with-openssl--with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --enable-short-tags --enable-sockets--enable-zend-multibyte --enable-soap --enable-gd-native-ttf --enable-curl --enable-xsl--with-libxml-dir

make

make install



补充:

报错:configure: error: libpng.(a|so)not found.

原因:在/usr/lib下没有libpng.so这个文件,需要从/usr/lib64/下做软连接

解决:ln -s /usr/lib64/libpng.so/usr/lib/libpng.so




2.3.3配置PHP.整合LAMP

1)创建php的配置文件php.ini

cp -f /usr/src/php-5.3.6/php.ini-production  /usr/local/php/php.ini

2)修改php.ini中的参数

sed -i 's/short_open_tag = Off/short_open_tag = On/g'  /usr/local/php/php.ini

3)修改httpd.conf,使与php整合到一块

sed -i  "54iAddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf

sed -i 's/DirectoryIndex/DirectoryIndex index.php/g'  /usr/local/httpd/conf/httpd.conf

service httpd reload



测试:

创建测试网页tesx.php

<?php

Phpinfo()

?>

echo "<?php phpinfo() ?>"> /usr/local/httpd/htdocs/test.php

打开浏览器访问测试出现php相关信息表示LAMP安装成功
百度云附件:脚本.zip   


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-54833-1-1.html 上篇帖子: Cent OS 中LNMP 环境源码搭建 下篇帖子: 在ubuntu14.04 LTS下当完成lamp的安装后如何添加多个虚拟主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表