标签:lamp
LAMP 是Linux Apache MySQL PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言。Apache是最常用的WEB服务软件,而MySQL是比较小型的数据库软件,这两个软件以及PHP都可以安装到windows的机器上。
安装mysql
1. 下载mysql到/usr/local/src/
cd /usr/local/src
wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
注意:上面的地址是32位机器用的,如果你的机器是64位,下载这个包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安装方法是一样的。
2. 解压
tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
3. 把解压完的数据移动到/usr/local/mysql
mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql //这一步是把前一个目录的内容放入后一个目录内,不是把前一个目录移动到后一个目录下这样做是无法搭建LAMP环境的。
4. 建立mysql用户
useradd -s /sbin/nologin mysql
5. 初始化数据库
cd /usr/local/mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
--user定义数据库的所属主,--datadir定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。
6. 拷贝配置文件
cp support-files/my-large.cnf /etc/my.cnf
模板配置文件在/mysql/support-files/目录下;
根据内存大小选择:
my-small.cnf (内存 <= 64M)
my-medium.cnf (内存 128M )
my-large.cnf (内存 512M)
my-huge.cnf (内存 1G-2G)
my-innodb-heavy-4G.cnf (内存 4GB)
7. 拷贝启动脚本文件并修改其属性
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
8. 修改启动脚本
vim /etc/init.d/mysqld #修改datadir=/data/mysql(前面初始化数据库时定义的目录)
9. 把启动脚本加入系统服务项,并设定开机启动,启动mysql
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
如果启动不了,请到/data/mysql/ 下查看错误日志,这个日志通常是主机名.err。
安装apache
cd /usr/local/src/
wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
tar zvxf httpd-2.2.16.tar.gz
cd httpd-2.2.16
./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so
make && make install
安装过程中出现的问题:
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/httpd-2.2.16/srclib/apr‘:
configure: error: no acceptable C compiler found in $PATH
See `config.log‘ for more details.
configure failed for srclib/apr
**************************
[root@localhost httpd-2.2.16]# yum install -y gcc
***************************
[root@localhost httpd-2.2.16]# echo $?
0
[root@localhost httpd-2.2.16]# make
******************************************
[root@localhost httpd-2.2.16]# echo $?
0
[root@localhost httpd-2.2.16]# make install
*************************************
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/usr/local/src/httpd-2.2.16‘
[root@localhost httpd-2.2.16]# echo $?
0
************************************************************************
[root@localhost apache2]# /usr/local/apache2/bin/httpd -t //检测配置文件是否有误
httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK //出现则说明没问题
[root@localhost apache2]# /usr/local/apache2/bin/httpd -l //检测静态加载的模块和功能
Compiled in modules:
core.c
prefork.c //关于apache的工作模式常见的有三种event|worker|prefork,2.4之前版本默认为prefork, 2.4已经变为event模式。
http_core.c
mod_so.c
[root@localhost htdocs]# /usr/local/src/httpd-2.2.16/configure --help |less
*****************************************************
--with-mpm=MPM Choose the process model for Apache to use.
MPM={beos|event|worker|prefork|mpmt_os2}
*****************************************************
以上为查看apache有几种工作模式,如果你想要worker模式,那么请指定吧 ./configure --prefix=/usr/local/apache2 --with-mpm=worker
[root@localhost apache2]# /usr/local/apache2/bin/httpd -M //将apache动态加载的模块列出来
httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
Loaded Modules:
core_module (static)
**********************
userdir_module (shared)
alias_module (shared)
rewrite_module (shared)
Syntax OK
[root@localhost apache2]# cat /usr/local/apache2/build/config.nice //查看安装apache的编译选项
#! /bin/sh
#
# Created by configure
"./configure" \
"--prefix=/usr/local/apache2" \
"--enable-mods-shared=most" \
"--enable-so" \
"$@"
[root@localhost apache2]# /usr/local/apache2/bin/apachectl start //启动apache服务
httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName//不是提示报错
[root@localhost apache2]# echo $?
0
[root@localhost apache2]# ps aux |grep httpd //查看apache是否启动
root 26316 0.0 0.2 5280 2200 ? Ss 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26317 0.0 0.1 5280 1536 ? S 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26318 0.0 0.1 5280 1536 ? S 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26319 0.0 0.1 5280 1536 ? S 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26320 0.0 0.1 5280 1536 ? S 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26321 0.0 0.1 5280 1536 ? S 18:48 0:00 /usr/local/apache2/bin/httpd -k start
root 26323 0.0 0.0 5980 736 pts/0 S+ 18:49 0:00 grep httpd
[root@localhost apache2]# vi conf/httpd.conf
*********************************************
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn‘t have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80 //取消注释
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
********************************************
[root@localhost apache2]# ./bin/apachectl -t //不在显示提示信息
Syntax OK
[root@localhost apache2]# ./bin/httpd -t //和上面的用法一样
Syntax OK
[root@localhost apache2]# pwd
/usr/local/apache2
[root@localhost apache2]# ./bin/apachectl graceful //不杀死进程的情况下重启apache服务
[root@localhost apache2]# ps aux |grep httpd
root 26316 0.0 0.2 5280 2540 ? Ss 18:48 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26332 0.0 0.1 5280 1548 ? S 18:55 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26333 0.0 0.1 5280 1548 ? S 18:55 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26334 0.0 0.1 5280 1548 ? S 18:55 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26335 0.0 0.1 5280 1548 ? S 18:55 0:00 /usr/local/apache2/bin/httpd -k start
daemon 26336 0.0 0.1 5280 1548 ? S 18:55 0:00 /usr/local/apache2/bin/httpd -k start
root 26338 0.0 0.0 5980 736 pts/0 S+ 18:55 0:00 grep httpd
[root@localhost apache2]# date
2015年 04月 28日 星期二 18:55:43 CST
[root@localhost apache2]# curl localhost
<html><body><h1>It works!</h1></body></html>
[root@localhost apache2]# curl localhost -I //查看状态信息
HTTP/1.1 200 OK
Date: Tue, 28 Apr 2015 10:58:27 GMT
Server: Apache/2.2.16 (Unix) DAV/2
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "82ad8-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html
安装PHP
下载:
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz
解压:
tar zxf php-5.3.28.tar.gz
进入解压后的目录:
cd /usr/local/src/php-5.3.28
安装php:
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
出现的错误及解决方法:
[root@localhost php-5.3.28]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
**********************************************************************
Configuring SAPI modules
checking for AOLserver support... no
checking for Apache 1.x module support via DSO through APXS... no
checking for Apache 1.x module support... no
checking whether to enable Apache charset compatibility option... no
checking for Apache 2.0 filter-module support via DSO through APXS... no
checking for Apache 2.0 handler-module support via DSO through APXS...
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
The output of /usr/local/apache2/bin/apxs follows:
./configure: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
configure: error: Aborting
[root@localhost php-5.3.28]# yum -y install httpd-devel
[root@localhost php-5.3.28]# yum -y install prel* //汗,继续报错,中间字母写反
[root@localhost php-5.3.28]# yum -y install perl*
安装后仍然报错,在百度上找到问题,链接为:http://www.j3j5.com/post-285.html
继续安装后又报错为:
******************************************************************
checking libxml2 install dir... yes
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@localhost php-5.3.28]# yum list |grep -i xml2
libxml2.i686 2.7.6-14.el6_5.2 @anaconda-CentOS-201410241409.i386/6.6
libxml2.i686 2.7.6-17.el6_6.1 updates
libxml2-devel.i686 2.7.6-17.el6_6.1 updates
libxml2-python.i686 2.7.6-17.el6_6.1 updates
libxml2-static.i686 2.7.6-17.el6_6.1 updates
[root@localhost php-5.3.28]# yum install -y libxml2-devel.i686
继续安装接着报错为:
checking for DSA_get_default_method in -lssl... no
checking for X509_free in -lcrypto... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL‘s <evp.h>
[root@localhost php-5.3.28]# yum list |grep -i OpenSSL
openssl.i686 1.0.1e-30.el6 @anaconda-CentOS-201410241409.i386/6.6
perl-Crypt-OpenSSL-Bignum.i686 0.04-8.1.el6 @base
perl-Crypt-OpenSSL-RSA.i686 0.25-10.1.el6 @base
perl-Crypt-OpenSSL-Random.i686 0.04-9.1.el6 @base
krb5-pkinit-openssl.i686 1.10.3-37.el6_6 updates
openssl.i686 1.0.1e-30.el6.8 updates
openssl-devel.i686 1.0.1e-30.el6.8 updates
openssl-perl.i686 1.0.1e-30.el6.8 updates
openssl-static.i686 1.0.1e-30.el6.8 updates
openssl098e.i686 0.9.8e-18.el6_5.2 base
pyOpenSSL.i686 0.10-2.el6 base
xmlsec1-openssl.i686 1.2.20-4.el6 base
xmlsec1-openssl-devel.i686 1.2.20-4.el6 base
[root@localhost php-5.3.28]# yum install -y openssl-devel.i686
***************************************************
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
[root@localhost php-5.3.28]# yum list |grep -i BZip2
bzip2.i686 1.0.5-7.el6_0 @anaconda-CentOS-201410241409.i386/6.6
bzip2-libs.i686 1.0.5-7.el6_0 @anaconda-CentOS-201410241409.i386/6.6
perl-Compress-Raw-Bzip2.i686 2.021-136.el6_6.1 @updates
perl-IO-Compress-Bzip2.i686 2.021-136.el6_6.1 @updates
bzip2-devel.i686 1.0.5-7.el6_0 base
[root@localhost php-5.3.28]# yum install -y bzip2-devel.i686
***********************************************
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for fabsf... yes
checking for floorf... yes
configure: error: jpeglib.h not found.
[root@localhost php-5.3.28]# yum list | grep -i *jpeg* //发现没有相关的包
[root@localhost php-5.3.28]# yum install -y libjpeg-turbo-devel.i686 //用这个包解决问题
****************************************************
checking for floorf... yes
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
[root@localhost php-5.3.28]# yum list | grep png
libpng.i686 2:1.2.49-1.el6_2 @anaconda-CentOS-201410241409.i386/6.6
dvipng.i686 1.11-3.2.el6 base
libpng-devel.i686 2:1.2.49-1.el6_2 base
libpng-static.i686 2:1.2.49-1.el6_2 base
[root@localhost php-5.3.28]# yum install -y libpng-devel.i686
***************************************************************
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype.h not found.
[root@localhost php-5.3.28]# yum list | grep freetype
freetype.i686 2.3.11-14.el6_3.1 @anaconda-CentOS-201410241409.i386/6.6
freetype.i686 2.3.11-15.el6_6.1 updates
freetype-demos.i686 2.3.11-15.el6_6.1 updates
freetype-devel.i686 2.3.11-15.el6_6.1 updates
[root@localhost php-5.3.28]# yum install -y freetype-devel.i686
*****************************************************************
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
原因:因为centos6.x 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源。
[root@localhost php-5.3.28]# rpm -ivh "http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"
********************************************************
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
还是不行,原因是由于自己未从新安装libmcrypt导致的。
[root@localhost php-5.3.28]# yum install -y libmcrypt-devel.i686
******************************************************************************
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[root@localhost php-5.3.28]# echo $?
0
./configure 已经运行好了。
[root@localhost php-5.3.28]# make
******************************************************************
[root@localhost php-5.3.28]# echo $?
0
[root@localhost php-5.3.28]# make install
****************************************************************
[root@localhost php-5.3.28]# echo $?
0
[root@localhost bin]# curl localhost/1.php
<? php
echo "php解析正常";
?>
[root@localhost bin]# /usr/local/apache2/bin/apachectl restart
[root@localhost bin]# ps aux |grep httpd
daemon 759 0.0 0.7 23864 7832 ? S 20:59 0:00 /usr/local/apache2/bin/httpd -k start
daemon 760 0.0 0.7 23864 7832 ? S 20:59 0:00 /usr/local/apache2/bin/httpd -k start
daemon 761 0.0 0.7 23864 7832 ? S 20:59 0:00 /usr/local/apache2/bin/httpd -k start
daemon 762 0.0 0.7 23864 7832 ? S 20:59 0:00 /usr/local/apache2/bin/httpd -k start
daemon 763 0.0 0.7 23864 7832 ? S 20:59 0:00 /usr/local/apache2/bin/httpd -k start
root 765 0.0 0.0 5980 736 pts/1 S+ 21:00 0:00 grep httpd
root 26316 0.0 0.9 23732 9612 ? Ss 18:48 0:05 /usr/local/apache2/bin/httpd -k start
[root@localhost bin]# date
2015年 04月 28日 星期二 21:00:22 CST
make && make install
[root@localhost htdocs]# /usr/local/php/bin/php -m //将加载的模块列印出来
[PHP Modules]
bz2
Core
ctype
***********
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@localhost htdocs]# /usr/local/php/bin/php -i //查看php的参数=phpinfo(),前几行为php的编译选项
phpinfo()
PHP Version => 5.3.28
System => Linux localhost.localdomain 2.6.32-504.el6.i686 #1 SMP Wed Oct 15 03:02:07 UTC 2014 i686
Build Date => Apr 28 2015 20:42:43
Configure Command => ‘./configure‘ ‘--prefix=/usr/local/php‘ ‘--with-apxs2=/usr/local/apache2/bin/apxs‘ ‘--with-config-file-path=/usr/local/php/etc‘ ‘--with-mysql=/usr/local/mysql‘ ‘--with-libxml-dir‘ ‘--with-gd‘ ‘--with-jpeg-dir‘ ‘--with-png-dir‘ ‘--with-freetype-dir‘ ‘--with-iconv-dir‘ ‘--with-zlib-dir‘ ‘--with-bz2‘ ‘--with-openssl‘ ‘--with-mcrypt‘ ‘--enable-soap‘ ‘--enable-gd-native-ttf‘ ‘--enable-mbstring‘ ‘--enable-sockets‘ ‘--enable-exif‘ ‘--disable-ipv6‘
**********************************************************
[root@localhost etc]# cp /usr/local/src/php-5.3.28/php.ini- //两种环境,一个开发一个生产
php.ini-development php.ini-production
[root@localhost etc]# cp /usr/local/src/php-5.3.28/php.ini-development /usr/local/php/etc/php.ini
[root@localhost etc]# /usr/local/php/bin/php -i |grep Configuration //查看是否加载
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini
Configuration
PHP Warning: Unknown: It is not safe to rely on the system‘s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Chongqing‘ for ‘CST/8.0/no DST‘ instead in Unknown on line 0
配置apache结合php
vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
5. 测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:
<?php
echo "php解析正常";
?>
保存后,继续测试:
curl localhost/1.php
[root@localhost etc]# curl 192.168.1.110/1.php //apache未开启
curl: (7) couldn‘t connect to host
[root@localhost etc]# /usr/local/apache2/bin/apachectl start
[root@localhost etc]# curl 192.168.1.110/1.php
aminglinux
若执行curl命令后apache未解析php,则需要做以下:
[root@localhost etc]# /usr/local/apache2/bin/apachectl -M|grep php //查看php模块是否加载
php5_module (shared)
Syntax OK
[root@localhost etc]# getenforce //查看selinux是否关闭
Disabled
[root@localhost etc]# /usr/local/apache2/bin/apachectl restart //重启apache服务,由于修改httpd.conf必须重启服务
php解析排错:
[root@localhost etc]# ls /usr/local/apache2/modules/libphp5.so
/usr/local/apache2/modules/libphp5.so
[root@localhost etc]# ldd !$
ldd /usr/local/apache2/modules/libphp5.so
linux-gate.so.1 => (0x009d6000)
*************************
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x001ae000)
*********************************
libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x002d4000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00457000)
[root@localhost etc]# mv /usr/lib/libpng12.so.0 /usr/lib/libpng12.so.0.bak
[root@localhost etc]# ldd /usr/local/apache2/modules/libphp5.so
linux-gate.so.1 => (0x00414000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x005e7000)
*********************************
libpng12.so.0 => not found
**********************************
libpthread.so.0 => /lib/libpthread.so.0 (0x00509000)
/lib/ld-linux.so.2 (0x006e7000)
[root@localhost etc]# /usr/local/apache2/bin/apachectl -t
httpd: Syntax error on line 99 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: libpng12.so.0: cannot open shared object file: No such file or directory
[root@localhost etc]# /usr/local/apache2/bin/apachectl restart
httpd: Syntax error on line 99 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: libpng12.so.0: cannot open shared object file: No such file or directory
[root@localhost etc]# mv /usr/lib/libpng12.so.0.bak /usr/lib/libpng12.so.0
[root@localhost etc]# ldd /usr/local/apache2/modules/libphp5.so
linux-gate.so.1 => (0x00f4b000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0x00200000)
************************************
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00e91000)
*************************************
libkeyutils.so.1 => /lib/libkeyutils.so.1 (0x002ac000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00472000)
[root@localhost etc]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[root@localhost etc]# /usr/local/apache2/bin/apachectl restart
[root@localhost etc]#
[root@localhost etc]# grep -i "addtype" /usr/local/apache2/conf/httpd.conf //查看是否支持php文件
# AddType allows you to add to or override the MIME configuration
#AddType application/x-gzip .tgz
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
#AddType text/html .shtml
[root@localhost etc]# /usr/local/apache2/bin/apachectl restart
最后还不行就需要看httpd的错误日志。
标签:lamp
原文地址:http://9950284.blog.51cto.com/9940284/1640282