lamp环境搭建。
lamp环境搭建:
1.首先保证你的电脑里安装了gcc gcc-c++ make
2.如果你的服务器没有链接网络可以先挂载本地光盘。设置yum源。
2.1 挂在光盘
[root@localhost ~]# mkdir /opt/cdrom #新建挂载点
[root@localhost ~]# mount /dev/cdrom /opt/cdrom/ #挂载本地光盘
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]#
2.2配置yum源。
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo #Media就是本地yum源的配置文件。
[root@localhost yum.repos.d]# vi CentOS-Media.repo
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
# CentOS-6. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c6-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c6-media [command]
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///opt/cdrom #指定了三个光盘有可能挂载的路径。
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1 #enabled=0 这里的0代表缺省源不存在,1代表启用。
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# wq保存退出。
如果你的linux能够上互联网,那么备份Base这个配置文件。
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
2.3 安装gcc, gcc-c++
[root@localhost ~]# yum install gcc -y
[root@localhost ~]# yum install gcc-c++ -y
3.卸载apache php mysql rpm软件包。我的系统里没有装。方法很多,不一一罗列。
查看服务有没有启动:
[root@localhost ~]# service httpd status
httpd: 未被识别的服务
[root@localhost ~]# service mysqld status
mysqld: 未被识别的服务
[root@localhost ~]#
[root@localhost ~]# rpm -qa httpd
[root@localhost ~]# rpm -qa mysql
[root@localhost ~]# rpm -qa mysqld
[root@localhost ~]#
[root@localhost ~]# netstat -ntpl | grep 80
[root@localhost ~]# netstat -ntpl | grep 3306
[root@localhost ~]# rpm -qa | grep php
如果你的系统里有这些包,那么rpm -e packagename或者yum remove packagename(解决依赖卸载)。
4.关闭SElinux 允许iptables相关端口
4.1.1关闭selinux的两种方法。--永久关闭。(需要重启系统)
[root@localhost ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing # 把SELINUX=enforcing 更改为SELINUX更改为disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
4.1.2临时关闭(不需要重启系统)
[root@localhost ~]# setenforce 0
4.2源码部署需要安装的包很多:
[root@localhost ~]# cd packget/
[root@localhost packget]# ls
autoconf-2.61.tar.gz jpegsrc.v6b.tar.gz mysql-5.0.41.tar.gz freetype-2.3.5.tar.gz libmcrypt-2.5.8.tar.gz ncurses-5.6.tar.gz ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
gd-2.0.35.tar.gz libpng-1.2.31.tar.gz php-5.2.6.tar.gz zlib-1.2.3.tar.gz
httpd-2.2.9.tar.gz libxml2-2.6.30.tar.gz phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
这里写一个解压源码包的脚本。
cd /root/packget/
ls * > packget.list
for i in $(cat packget.list)
do
tar -zxf $i
done
运行脚本:
sh targz.sh
查看解压:
[root@localhost packget]# ls
autoconf-2.61 jpeg-6b mysql-5.0.41 phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
autoconf-2.61.tar.gz jpegsrc.v6b.tar.gz mysql-5.0.41.tar.gz freetype-2.3.5 libmcrypt-2.5.8 ncurses-5.6 freetype-2.3.5.tar.gz libmcrypt-2.5.8.tar.gz ncurses-5.6.tar.gz
gd-2.0.35 libpng-1.2.31 packget.list ZendOptimizer-3.2.6-linux-glibc21-i386
gd-2.0.35.tar.gz libpng-1.2.31.tar.gz php-5.2.6 ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
httpd-2.2.9 libxml2-2.6.30 php-5.2.6.tar.gz zlib-1.2.3
httpd-2.2.9.tar.gz libxml2-2.6.30.tar.gz phpMyAdmin-3.0.0-rc1-all-languages zlib-1.2.3.tar.gz
[root@localhost packget]#
4.3 安装三步走configure ---make ---make install
configure 检测系统配置,检测软件安装所需要的软件。
make 编译二进制文件为可执行文件。
make install 安装软件。
4.3.1编译安装xml2
[root@localhost packget]# cd libxml2-2.6.30
[root@localhost libxml2-2.6.30]#
[root@localhost packget]# cd libxml2-2.6.30
[root@localhost libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2/
checking build system type... x86_64-redhat-linux-gnu
checking host system type... x86_64-redhat-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
------------省略一部分过程----------
config.status: creating python/setup.py
config.status: creating config.h
config.status: executing depfiles commands
Done configuring
[root@localhost libxml2-2.6.30]#
检测完成,接下来make编译
[root@localhost libxml2-2.6.30]# make
make all-recursive
make[1]: Entering directory `/root/packget/libxml2-2.6.30'
Making all in include
make[2]: Entering directory `/root/packget/libxml2-2.6.30/include'
Making all in libxml
--------------省略编译过程-----------
make[2]: Entering directory `/root/packget/libxml2-2.6.30/xstc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/packget/libxml2-2.6.30/xstc'
make[1]: Leaving directory `/root/packget/libxml2-2.6.30'
[root@localhost libxml2-2.6.30]#
编译完成之后开始make install
[root@localhost libxml2-2.6.30]# make install
Making install in include
make[1]: Entering directory `/root/packget/libxml2-2.6.30/include'
Making install in libxml
make[2]: Entering directory `/root/packget/libxml2-2.6.30/include/libxml'
make[3]: Entering directory `/root/packget/libxml2-2.6.30/include/libxml'
make install-exec-hook
---------------省略步奏-----------
Making install in xstc
make[1]: Entering directory `/root/packget/libxml2-2.6.30/xstc'
make[2]: Entering directory `/root/packget/libxml2-2.6.30/xstc'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/packget/libxml2-2.6.30/xstc'
make[1]: Leaving directory `/root/packget/libxml2-2.6.30/xstc'
[root@localhost libxml2-2.6.30]#
libxml2安装完成。
同样的方法安装libmcrpyt
[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@localhost libmcrypt-2.5.8]#make
[root@localhost libmcrypt-2.5.8]#make install
并且安装libmcrypt下的libltdl
[root@localhost libmcrypt-2.5.8]# cd libltdl/
[root@localhost libltdl]# ls
acinclude.m4 aclocal.m4 config-h.in configure configure.in COPYING.LIB ltdl.c ltdl.h Makefile.am Makefile.in README
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make
[root@localhost libltdl]# make install
编译安装zlib (zlib是个库文件,这里为了防止后期出错,不用指定路径,如果是64位系统,请参见安装libpng排错的方法安装。)
[root@localhost zlib-1.2.3]# ./configure
Checking for gcc...
Building static library libz.a version 1.2.3 with gcc.
Checking for unistd.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for errno.h... Yes.
Checking for mmap support... Yes.
[root@localhost zlib-1.2.3]# make
gcc -O3 -DUSE_MMAP -c -o example.o example.c
gcc -O3 -DUSE_MMAP -c -o adler32.o adler32.c
gcc -O3 -DUSE_MMAP -c -o compress.o compress.c
gcc -O3 -DUSE_MMAP -c -o crc32.o crc32.c
gcc -O3 -DUSE_MMAP -c -o gzio.o gzio.c
gcc -O3 -DUSE_MMAP -c -o uncompr.o uncompr.c
gcc -O3 -DUSE_MMAP -c -o deflate.o deflate.c
gcc -O3 -DUSE_MMAP -c -o trees.o trees.c
gcc -O3 -DUSE_MMAP -c -o zutil.o zutil.c
gcc -O3 -DUSE_MMAP -c -o inflate.o inflate.c
gcc -O3 -DUSE_MMAP -c -o infback.o infback.c
gcc -O3 -DUSE_MMAP -c -o inftrees.o inftrees.c
gcc -O3 -DUSE_MMAP -c -o inffast.o inffast.c
ar rc libz.a adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
gcc -O3 -DUSE_MMAP -o example example.o -L. libz.a
gcc -O3 -DUSE_MMAP -c -o minigzip.o minigzip.c
gcc -O3 -DUSE_MMAP -o minigzip minigzip.o -L. libz.a
[root@localhost zlib-1.2.3]# make install
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h
cp libz.a /usr/local/lib
cd /usr/local/lib; chmod 755 libz.a
cd /usr/local/lib; if test -f libz.so.1.2.3; then \
rm -f libz.so libz.so.1; \
ln -s libz.so.1.2.3 libz.so; \
ln -s libz.so.1.2.3 libz.so.1; \
(ldconfig || true) >/dev/null 2>&1; \
fi
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
[root@localhost zlib-1.2.3]#
编译安装libpng如果出现如下错误,是应为你的环境是64位系统,匹配不了zlib库。
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libpng12.la] 错误 1
make[1]: Leaving directory `/root/packget/libpng-1.2.31'
make: *** [all] 错误 2
tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
接下面步骤
make
make install
编译安装libpng
[root@localhost libpng-1.2.31]# ./configure -prefix=/usr/local/libpng/
[root@localhost libpng-1.2.31]# make
[root@localhost libpng-1.2.31]# make install
libpng安装完成。
安装jpeg6
这源码包的安装相对复杂一点。
因为其不会自动创建对应的目录,首先我们自己手动建立目录
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/ #创建安装目录
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/bin/ #创建可执行文件目录
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/lib/ #创建库文件爱你存放目录
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/include #创建头文件存放目录
[root@localhost jpeg-6b]# mkdir -p /usr/local/jpeg6/man/man1 #创建man手册中的命令帮助,man1指的是命令帮助, man5配置文件的帮助。
开始检测环境:
[root@localhost jpeg-6b]# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
[root@localhost jpeg-6b]#make
[root@localhost jpeg-6b]# make
./libtool --mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool:命令未找到
make: *** [jcapimin.lo] 错误 127
出现以上错误的解决办法:
[root@localhost jpeg-6b]# cp /usr/share/libtool/config/config.sub /root/packget/jpeg-6b/
[root@localhost jpeg-6b]# cp /usr/share/libtool/config/config.guess /root/packget/jpeg-6b/
然后:
[root@localhost jpeg-6b]# make clean
再执行:
[root@localhost jpeg-6b]# make
[root@localhost jpeg-6b]# make install
编译安装freetype
[root@localhost freetype-2.3.5]# ./configure --prefix=/usr/local/freetype/ [root@localhost freetype-2.3.5]# make [root@localhost freetype-2.3.5]# make install
编译安装autoconf
[root@localhost autoconf-2.61]# ./configure
[root@localhost autoconf-2.61]#make
[root@localhost autoconf-2.61]#make install
编译安装gd库:
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/ 备注一下:这里如果你的zlib库是指定路径,那么可以--with-zlib=/$PATH
[root@localhost gd-2.0.35]# make
[root@localhost gd-2.0.35]# make install
5.编译安装apache:
[root@localhost httpd-2.2.9]# ./configure --prefix=/usr/local/apache2/ --with-sysconfdir=/etc/httpd/--with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
[root@localhost httpd-2.2.9]#make
[root@localhost httpd-2.2.9]#make install
启动apache:
[root@localhost ~]# /usr/local/apache2/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName httpd (pid 25663) already running
[root@localhost ~]#
如果没有禁止selinux
那么使用如下命令开启模块权限:
[root@localhost ~]# chcon -t texrel_shlib_t modulename
通过浏览器访问服务器,如果反回It‘s works ! 表示安装成功。
6.编译安装mysql之前需要安装编译nourses:
[root@localhost ncurses-5.6]# ./configure --with-shared --without-debug --without-ada --enable-overwrite
[root@localhost ncurses-5.6]# make
[root@localhost ncurses-5.6]# make install
编译安装mysql:
首先创建mysql用户以及用户组:
[root@localhost mysql-5.0.41]# groupadd mysql
[root@localhost mysql-5.0.41]# grep mysql /etc/group mysql:x:500:
[root@localhost mysql-5.0.41]# useradd -g mysql mysql
[root@localhost mysql-5.0.41]# ./configure --prefix=/usr/local/mysql --with-extra-charsets=all # extra 允许所有字符集
[root@localhost mysql-5.0.41]# make
[root@localhost mysql-5.0.41]# make install
配置mysql:
把源码包中的my-medium.cnf拷贝的/etc/下命名为my.cnf:
[root@localhost mysql-5.0.41]# cp support-files/my-medium.cnf /etc/my.cnf
启动用户的授权表:
[root@localhost ~]# /usr/local/mysql/bin/mysql_install_db --user=mysql
改变目录权限:
[root@localhost ~]# chown -R root /usr/local/mysql #改变mysql所属用户
[root@localhost ~]# chown -R mysql /usr/local/mysql/var #改变mysql下var这个目录所属用户。
[root@localhost ~]# chgrp -R mysql /usr/local/mysql #改变mysql的所属组,这里的-R是权限继承到子目录。
[root@localhost ~]#
启动:mysql
[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql & [1] 24065
[root@localhost ~]#Starting mysqld daemon with databases from /usr/local/mysql//var #表示数据存放路径。回车既可。
[root@localhost ~]#
查看mysql是否启动:
[root@localhost ~]# netstat -an | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@localhost ~]#
查看mysql的版本:
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin version
/usr/local/mysql/bin/mysqladmin Ver 8.41 Distrib 5.0.41, for unknown-linux-gnu on x86_64
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.0.41-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 3 min 56 sec
Threads: 1 Questions: 1 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 0.004
[root@localhost ~]#
查看版本的配置参数:
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin variables
+---------------------------------+-------------------------------------------------+
| Variable_name | Value |
+---------------------------------+-------------------------------------------------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
| automatic_sp_privileges | ON |
| back_log | 50 |
| basedir | /usr/local/mysql/ |
| binlog_cache_size | 32768 |
.............
设置mysql的用户密码:
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.41-log Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
mysql> set password for 'root'@'localhost'=PASSWORD('thinklinux');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
把apache和mysql 加入启动项:
[root@localhost ~]# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.d/rc.local
[root@localhost ~]# echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local
或者:
[root@localhost ~]# cd packget/mysql-5.0.41
[root@localhost mysql-5.0.41]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.41]# chown root.root /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.41]# chmod 755 /etc/rc.d/init.d/mysqld
[root@localhost mysql-5.0.41]# chkconfig --add mysqld
[root@localhost mysql-5.0.41]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost mysql-5.0.41]# chkconfig --levels 245 mysqld off #设置运行级别启动项的方法.
[root@localhost mysql-5.0.41]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:关闭 6:关闭
[root@localhost mysql-5.0.41]# chkconfig --levels 245 mysqld on #更改回原来的运行级别。
安装php:
[root@localhost php-5.2.6]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/--with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/--with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/--with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
[root@localhost php-5.2.6]# make
[root@localhost php-5.2.6]# make install
配置php:
[root@localhost php-5.2.6]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc \ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ \ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ \ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ \ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --enable-soap --enable-mbstring=all --enable-sockets [root@localhost php-5.2.6]# make [root@localhost php-5.2.6]# make install
配置php:
[root@localhost php-5.2.6]# cp php.ini-dist /usr/local/php/etc/php.ini
配置apache能够解析php:
前面安装时出现了警告没有把apache配置文件安装到/etc/下,所以在apache路径里面找吧。
[root@localhost ~]# cd /usr/local/apache2/conf/
[root@localhost conf]# vi httpd.conf
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Addtype application/x-httpd-php .php .phtml #理论上这个Addtype 中的t应该是大写,
#但是在有的版本的linux中不能解析网页文件。
/AddType #打开网站是空白,没有报错日志,跟这个有关系吧。所以可以尝试小写。
加入这个选项之后重启apache
[root@localhost ~]# cd /usr/local/apache2/htdocs/
[root@localhost htdocs]# vi info.php
写入如下代码:
<?php
phpinfo();
?>
php加速软件Zend安装:
Zend
出现如下错误:
[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# ./install.sh
./install.sh: ./php: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
通过yum找出库所依赖的软件包,并安装:
[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# yum provides "*/ld-linux.so.2"
[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]#
安装如下软件包:
[root@localhost packget]# yum install glibc.i686