1 ++++++++++++++++++++++++++++++++++++++++++++++
2 linux下LAMP环境搭建
3 ++++++++++++++++++++++++++++++++++++++++++++++
4 操作系统 : [CentOS6.
0]
5 服务器 : [httpd-
2.2.
9]
6 PHP : [php-
5.2.
6]
7 数据库 : [mysql-
5.1.
59]
8 ++++++++++++++++++++++++++++++++++++++++++++++
9 准备安装软件(download)
10 1> [httpd-
2.2.
9]
11 http:
//sunsite.bilkent.edu.tr/pub/apache/httpd/httpd-2.2.9.tar.gz
12 2> [php-
5.2.
6]
13 http:
//museum.php.net/php5/php-5.2.6.tar.gz
14 3> [mysql-
5.1.
59]
15 http:
//downloads.mysql.com/archives/mysql-5.1/mysql-5.1.59.tar.gz
16 4> [libxml2-
2.6.
30]
17 http:
//download.chinaunix.net/down.php?id=28491&ResourceID=6095&site=1
18 5> [libmcrypt-
2.5.
8]
19 http:
//sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
20 6> [zlib-
1.2.
3]
21 http:
//sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib-1.2.3.tar.gz/download
22 7.>[libpng-
1.2.
31] 23 http:
//files.directadmin.com/services/custombuild/libpng-1.2.31.tar.gz
24 8.>
[jpegsrc.v6b]
25 http:
//download.chinaunix.net/down.php?id=10021&ResourceID=5095&site=1
26 9.>[freetype-
2.3.
5]
27 http:
//nongnu.askapache.com/freetype/freetype-2.3.5.tar.gz
28 10.>[autoconf-
2.61]
29 http:
//ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
30 11.>[gd-
2.0.
35]
31 http:
//code.google.com/p/google-desktop-for-linux-mirror/downloads/detail?name=gd-2.0.35.tar.gz&can=2&q=
32 12.>[ncurses-
5.6]
33 http:
//ftp.gnu.org/gnu/ncurses/ncurses-5.6.tar.gz
34 ++++++++++++++++++++++++++++++++++++++++++++++
35 1>
【卸载系统自带的apache】
36 [html] view plaincopy
37 #查看apache是否己安装
38 rpm -
qa httpd
39 #卸载
40 rpm -e httpd --
nodeps
41 2>【安装gcc, gcc-c++
】
42 [html] view plaincopy
43 yum install gcc
44 yum install gcc-c++
45 3>【开放80、
3306、22端口】
46 [html] view plaincopy
47 #关闭防火墙
48 service iptables stop
49 vi /etc/sysconfig/
iptables
50 #添加
51 -A INPUT -m state --state NEW -m tcp -p tcp --dport
80 -
j ACCEPT
52 -A INPUT -m state --state NEW -m tcp -p tcp --dport
3306 -
j ACCEPT
53 -A INPUT -m state --state NEW -m tcp -p tcp --dport
22 -
j ACCEPT
54 #重启防火墙
55 service iptables restart
56 4>【建立lamp/
src目录, 将源码包上传】
57 5>
【安装libxml2】
58 [html] view plaincopy
59 tar -zxvf libxml2-
2.6.
30.tar.gz
60 cd libxml2-
2.6.
30
61 ./configure --prefix=/usr/local/libxml2/
62 make
63 make install
64 6>
【安装libmcrypt】
65 [html] view plaincopy
66 tar -zxvf libmcrypt-
2.5.
8.tar.gz
67 cd libmcrypt-
2.5.
8
68 ./configure --enable-ltdl-
install
69 make
70 make install
71 7>
【安装zlib】
72 [html] view plaincopy
73 tar -zxvf zlib-
1.2.
3.tar.gz
74 cd zlib-
1.2.
3
75 ./
configure
76 make
77 make install
78 8>
【安装libpng】
79 [html] view plaincopy
80 tar -zxvf libpng-
1.2.
31.tar.gz
81 cd libpng-
1.2.
31
82 ./configure --prefix=/usr/local/libpng/
83 make
84 make install
85 9>
【安装jpegsrc.v6b】
86 [html] view plaincopy
87 mkdir /usr/local/
jpeg6
88 mkdir /usr/local/jpeg6/
bin
89 mkdir /usr/local/jpeg6/
lib
90 mkdir /usr/local/jpeg6/
include
91 mkdir -p /usr/local/jpeg6/man/
man1
92
93 tar -
zxvf jpegsrc.v6b.tar.gz
94 cd jpeg-
6b
95 ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-
static
96 make
97 make install
98 10>
【安装freetype】
99 [html] view plaincopy
100 tar -zxvf freetype-
2.3.
5.tar.gz
101 cd freetype-
2.3.
5
102 ./configure --prefix=/usr/local/freetype/
103 make
104 make install
105 11>
【安装autoconf】
106 [html] view plaincopy
107 tar -zxvf autoconf-
2.61.tar.gz
108 cd autoconf-
2.61
109 ./
configure
110 make
111 make install
112 12>
【安装gd】
113 [html] view plaincopy
114 tar -zxvf gd-
2.0.
35.tar.gz
115 cd gd-
2.0.
35
116 ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
117 make
118 make install
119 13>
【安装apache】
120
121 [html] view plaincopy
122 tar -zxvf httpd-
2.2.
9.tar.gz
123 cd httpd-
2.2.
9
124 ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-
static-
support
125 make
126 make install
127 #启动apache
128 /usr/local/apache2/bin/
apachectl start
129 #如果出现下面的错误,
130 #httpd: Could not reliably determine the server
's fully qualified domain name, using ::1 for ServerName
131 #修改配置文件
132 vi /etc/httpd/
httpd.conf
133 #查找ServerName,将注释去掉
134 ServerName www.example.com:
80
135 #添加到自启动
136 echo
"/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/
rc.sysinit
137 #将apache添加到系统服务中
138 cp /usr/local/apache2/bin/apachectl /etc/init.d/
httpd
139 vi /etc/rc.d/init.d/
httpd
140 #在#!/bin/sh后添加下面两行(包含
"#")
141 # chkconfig:
2345 85 15
142 # description:Apache
143 #添加执行权限
144 chmod
755 /etc/init.d/
httpd
145 #添加到系统服务中
146 chkconfig --
add httpd
147 #开启apache
148 service httpd start
149 14>
【安装ncurses】
150 [html] view plaincopy
151 tar -zxvf ncurses-
5.6.tar.gz
152 cd ncurses-
5.6
153 ./configure --with-shared --without-debug --without-ada --enable-
overwrite
154 make
155 make install
156 15>
【安装mysql】
157 [html] view plaincopy
158 groupadd mysql
159 useradd -
g mysql mysql
160 tar -zxvf mysql-
5.1.
59.tar.gz
161 cd mysql-
5.1.
59
162 ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=
all
163 make
164 make install
165
166 [html] view plaincopy
167 cp support-files/my-medium.cnf /etc/
my.cnf
168 /usr/local/mysql/bin/mysql_install_db --user=
mysql
169 chown -R root /usr/local/
mysql
170 chown -R mysql /usr/local/mysql/
var
171 chgrp -R mysql /usr/local/
mysql
172
173 /usr/local/mysql/bin/mysqld_safe --user=mysql &
174 cp /lamp/src/mysql-
5.1.
59/support-files/mysql.server /etc/rc.d/init.d/
mysqld
175 chown root.root /etc/rc.d/init.d/
mysqld
176 chmod
755 /etc/rc.d/init.d/
mysqld
177 chkconfig --
add mysqld
178 chkconfig --
list mysqld
179 chkconfig --levels
245 mysqld off
180
181 [html] view plaincopy
182 #配置mysql
183 cd /usr/local/
mysql
184 bin/mysqladmin version
//简单的测试
185 bin/mysqladmin Variables
//查看所有mysql参数
186 bin/mysql -uroot
//没有密码可以直接登录本机服务器
187 DELETE FROM mysql.user WHERE Host=
'localhost' AND User=
'';
188 FLUSH PRIVILEGES;
189 #设置root密码为123456
190 SET PASSWORD FOR
'root'@
'localhost' = PASSWORD(
'123456');
191 #配置可远程连接mysql
192 use mysql
193 SELECT user,password,host FROM user;
194 DELETE FROM user WHERE host=
'localhsot.localdomain'
195 DELETE FROM user WHERE host=
'127.0.0.1';
196 UPDATE user SET host=
'%' WHERE user=
'root';
197 #重启mysql
198 service mysqld restart
199 16>
【安装php】
200 [html] view plaincopy
201 tar -zxvf php-
5.2.
6.tar.gz
202 cd php-
5.2.
6
203 ./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
204 make
205 make install
206 cp php.ini-dist /usr/local/php/etc/
php.ini
207 17>
【apache配置】
208 [html] view plaincopy
209 #建立工作目录
210 mkdir -p /
var/www/
html
211 #修改httpd.conf
212 vi /etc/httpd/
httpd.conf
213 #功能: 设置工作目录
214 #说明: 搜索DocumentRoot, 修改为
215 DocumentRoot
"/var/www/html"
216
217 #功能: 设置目录选项
218 #说明: 搜索<Directory
"/usr/local/apache2//htdocs">
, 修改为
219 <Directory
"/var/www/html">
220
221 #功能: 设置默认文档
222 #说明: 搜索<IfModule dir_module>
, 修改为
223 DirectoryIndex index.html index.php
224
225 #功能: 增加php类型
226 #说明: 搜索 AddType application/x-
gzip .gz .tgz在后面添加
227 AddType application/x-httpd-
php .html .php
228
229 功能: 不允许访问目录
230 说明: 搜索Options Indexes FollowSymLinks项并注释
231 #Options Indexes FollowSymLinks
232
233 #注意: 修改配置文件后, 重启apache才能生效
234 #重启apache
235 service httpd restart
236 18>
【添加PDO_MYSQL扩展】
237 [html] view plaincopy
238 cd /lamp/src/php-
5.2.
6/ext/
pdo_mysql
239 /usr/local/php/bin/
phpize
240 ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/
mysql
241 make
242 make install
243 [html] view plaincopy
244 #执行完make install后会生成
245 #Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-
20060613/
246 #修改php.ini
247 vi /usr/local/php/etc/
php.ini
248 #查找extension_dir,修改为
249 extension_dir =
"/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
250 #添加pdo_mysql
251 extension =
pdo_mysql.so
252 #重启apache
253 service httpd restart
254 19>
【apache虚拟主机配置】
255 [html] view plaincopy
256 #建立dev目录
257 mkdir -p /
var/www/html/
dev
258 cd /
var/www/html/
dev
259 vi index.php
260 #添加
261 <?
php
262 phpinfo();
263 ?>
264 #保存,退出
265 #打开httpd.conf
266 vi /etc/httpd/
httpd.conf
267 #查找Include /etc/httpd
//extra/httpd-vhosts.conf并取消注释
268 Include /etc/httpd
//extra/httpd-vhosts.conf
269 #打开httpd-
vhosts.conf
270 vi /etc/httpd
//extra/httpd-vhosts.conf
271 #将下面几行注释
272 #<VirtualHost *:
80>
273 # ServerAdmin webmaster@dummy-
host.example.com
274 # DocumentRoot
"/usr/local/apache2//docs/dummy-host.example.com"
275 # ServerName dummy-
host.example.com
276 # ServerAlias www.dummy-
host.example.com
277 # ErrorLog
"logs/dummy-host.example.com-error_log"
278 # CustomLog
"logs/dummy-host.example.com-access_log" common
279 #</VirtualHost>
280
281
282 #<VirtualHost *:
80>
283 # ServerAdmin webmaster@dummy-
host2.example.com
284 # DocumentRoot
"/usr/local/apache2//docs/dummy-host2.example.com"
285 # ServerName dummy-
host2.example.com
286 # ErrorLog
"logs/dummy-host2.example.com-error_log"
287 # CustomLog
"logs/dummy-host2.example.com-access_log" common
288 #</VirtualHost>
289 #添加
290 <VirtualHost *:
80>
291 ServerName dev.dev
292 DocumentRoot
"/var/www/html/dev"
293 <Directory
"/var/www/html/dev/">
294 AllowOverride All
295 </Directory>
296 </VirtualHost>
297 #保存, 退出
298 #重启apache
299 service httpd restart
300 #修改hosts文件
301 vi /etc/
hosts
302 #添加
303 127.0.
0.1 dev.dev localhost
304 #保存, 退出
305 #在浏览器输入http:
//dev.dev访问,查看能否输出php信息 原文地址:http://blog.csdn.net/ihelloworld/article/details/7003394
转载于:https://www.cnblogs.com/hgj123/p/4220645.html