一聚教程网:一个值得你收藏的教程网站

热门教程

CentOS 6.5 64位指定版本编译安装LAMP步骤

时间:2022-06-30 21:09:10 编辑:袖梨 来源:一聚教程网

说明:

操作系统:CentOS 6.5 64位

需求:

编译安装LAMP运行环境

各软件版本如下:

MySQL:mysql-5.1.73

Apache:httpd-2.2.31

PHP:php-5.2.17

具体操作:

准备篇

一、配置防火墙,开启80端口、3306端口

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

service iptables restart #最后重启防火墙使配置生效

二、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

三 、系统约定

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字

四、下载软件包

1、下载Apache

http://www.apache.org/dist/httpd/httpd-2.2.31.tar.gz

2、下载MySQL

http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73.tar.gz

3、下载php

http://museum.php.net/php5/php-5.2.17.tar.gz

4、下载libmcrypt(php扩展)

http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

5、下载yasm(php扩展)

http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

6、t1lib(php扩展)

ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz

7、下载gd库安装包

https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

8、libvpx(gd库需要)

https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2

9、tiff(gd库需要)

http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

10、libpng(gd库需要)

ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.15.tar.gz

11、freetype(gd库需要)

http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/freetype-2.5.4.tar.gz

12、jpegsrc(gd库需要)

http://www.ijg.org/files/jpegsrc.v9a.tar.gz

以上软件包上传到/usr/local/src目录

五、安装编译工具及库文件(使用yum命令安装)

yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel

安装篇

一、安装MySQL

cd /usr/local/src

tar zxvf mysql-5.1.73.tar.gz

cd mysql-5.1.73

./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data/ --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-unix-socket-path=/tmp/mysql.sock --without-debug --with-extra-charsets=all --without-embedded-server --enable-profiling --enable-assembler --enable-thread-safe-client --enable-shared --with-server-suffix=-community --with-plugins=innobase --with-extra-charsets=all

make

make install

注意:在执行make install编译的过程中,如果你看到屏幕上出现下面这一行,卡在那里,很久都过不去,千万别以为是编译错误了,或者服务器卡住了,只需要坚持,耐心的等待几分钟,就会编译成功!

make[4]: Entering directory `/usr/local/src/mysql-5.1.73/mysql-test'

groupadd mysql #添加mysql组

useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统

chown -R root /usr/local/mysql/ #允许root访问

chgrp -R mysql /usr/local/mysql/ #允许mysql组访问

cd /usr/local/mysql/ #进入mysql安装目录

cp share/mysql/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有my.cnf,直接覆盖即可)

cp share/mysql/mysql.server /etc/init.d/mysqld #把Mysql加入系统启动

chmod 755 /etc/init.d/mysqld #执行权限

vi /etc/profile #把mysql服务加入系统环境变量:

在最后添加下面这一行

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile #使配置立刻生效

下面这两行把myslq的库文件链接到系统默认的位置,在编译类似PHP等软件时可以不用指定mysql的库文件地址。

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql

ln -s /usr/local/mysql/include/mysql /usr/include/mysql

/usr/local/mysql/bin/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data #生成mysql系统数据库

/usr/local/mysql/bin/mysqld_safe --user=mysql & --datadir=/usr/local/mysql/data #启动mysql

/etc/rc.d/init.d/mysqld start #启动

chkconfig mysqld on #加入开机启动

mysql_secure_installation #设置Mysql密码

根据提示按Y 回车输入2次密码

或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码

service mysqld restart #重启

到此,mysql安装完成!

二、安装Apache

cd /usr/local/src

tar zxvf httpd-2.2.31.tar.gz

cd httpd-2.2.31

./configure --prefix=/usr/local/apache --with-included-apr --enable-module=so --enable-deflate --enable-expires --enable-ssl --enable-headers --enable-module=rewrite --enable-static-support --enable-mods-shared=all

make #编译

make install #安装

/usr/local/apache/bin/apachectl -k start #启动

vi /usr/local/apache/conf/httpd.conf #编辑配置文件

找到:#ServerName www.example.com:80

修改为:ServerName www.osyunwei.com:80

找到:DirectoryIndex index.html

修改为:DirectoryIndex index.html index.php

找到:Options Indexes FollowSymLinks

修改为:Options FollowSymLinks #不显示目录结构

找到AllowOverride None

修改为:AllowOverride All #开启apache支持伪静态,有三处都做修改

LoadModule rewrite_module modules/mod_rewrite.so #取消前面的注释,开启apache支持伪静态

vi /etc/profile #添加apache服务系统环境变量,在最后添加下面这一行

export PATH=$PATH:/usr/local/apache/bin

:wq! #保存退出

cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系统启动

vi /etc/init.d/httpd #编辑文件,在#!/bin/sh下面添加以下两行

#chkconfig:2345 10 90

#description:Activates/Deactivates Apache Web Server

:wq! #保存退出

chown daemon.daemon -R /usr/local/apache/htdocs #更改目录所有者

chmod 700 /usr/local/apache/htdocs -R #更改apache网站目录权限

chkconfig httpd on #设置开机启动

/etc/init.d/httpd start

service httpd restart

系统运维 www.osyunwei.com 温馨提醒:系统运维原创内容©版权所有,转载请注明出处及原文链接

三、安装PHP

1、安装yasm

cd /usr/local/src

tar zxvf yasm-1.3.0.tar.gz

cd yasm-1.3.0

./configure

make

make install

2、安装libmcrypt

cd /usr/local/src

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

3、安装libvpx

cd /usr/local/src

tar xvf libvpx-v1.3.0.tar.bz2

cd libvpx-v1.3.0

./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

make

make install

4、安装tiff

cd /usr/local/src

tar zxvf tiff-4.0.3.tar.gz

cd tiff-4.0.3

./configure --prefix=/usr/local/tiff --enable-shared

make

make install

5、安装libpng

cd /usr/local/src

tar zxvf libpng-1.6.15.tar.gz

cd libpng-1.6.15

./configure --prefix=/usr/local/libpng --enable-shared

make

make install

6、安装freetype

cd /usr/local/src

tar zxvf freetype-2.5.4.tar.gz

cd freetype-2.5.4

./configure --prefix=/usr/local/freetype --enable-shared

make #编译

make install #安装

7、安装jpeg

cd /usr/local/src

tar zxvf jpegsrc.v9a.tar.gz

cd jpeg-9a

./configure --prefix=/usr/local/jpeg --enable-shared

make #编译

make install #安装

8、安装libgd

cd /usr/local/src

tar zxvf libgd-2.1.0.tar.gz #解压

cd libgd-2.1.0 #进入目录

./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx #配置

make #编译

make install #安装

9、安装t1lib

cd /usr/local/src

tar zxvf t1lib-5.1.2.tar.gz

cd t1lib-5.1.2

./configure --prefix=/usr/local/t1lib --enable-shared

make without_doc

make install

10、安装php

注意:如果系统是64位,请执行以下两条命令,否则安装php会出错(32位系统不需要执行)

cp -frp /usr/lib64/libltdl.so* /usr/lib/

cp -frp /usr/lib64/libXpm.so* /usr/lib/

cd /usr/local/src

tar -zvxf php-5.2.17.tar.gz

cd php-5.2.17

export LD_LIBRARY_PATH=/usr/local/libgd/lib

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib --with-t1lib=/usr/local/t1lib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype

make #编译

make install #安装

cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录

rm -rf /etc/php.ini #删除系统自带配置文件

ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加软链接到 /etc目录

vi /usr/local/php/etc/php.ini #编辑

找到:;open_basedir =

修改为:open_basedir = .:/tmp/ #防止php木马跨站,重要!

找到:disable_functions =

修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

找到:;date.timezone =

修改为:date.timezone = PRC

找到:expose_php = On

修改为:expose_php = OFF #禁止显示php版本的信息

找到:display_errors = On

修改为:display_errors = OFF #关闭错误提示

:wq! #保存退出

四、配置apache支持php

vi /usr/local/apache/conf/httpd.conf #编辑apache配置文件,在AddType application/x-gzip .gz .tgz这一行下面添加

AddType application/x-httpd-php .php (注意:php .php这个点前面有一个空格)

:wq! #保存退出

service httpd restart #重启apache

service mysqld restart #重启mysql

五、测试

cd /usr/local/apache/htdocs

vi index.php #输入下面内容

phpinfo();

?>

:wq! #保存

在客户端浏览器输入服务器IP地址,可以看到相关的配置信息!

网站程序上传到/usr/local/apache/htdocs目录里面,如果安装有问题,请检查目录权限,确保目录为以下权限

chown daemon.daemon -R /usr/local/apache/htdocs

chmod -R 700 /usr/local/apache/htdocs

热门栏目