LAMP:
linux+Apache+Mysql+PHP

1apache的安装与使用经验


可以通过源码(推荐)和yum安装,源码可以使用最新的安装,并且可以指定安装的路径, 方便以后维护。

(1apache需要的相关库文件

[root@localhost ~]#cd apr-1.4.5

[root@localhost ~]#./configure  --prefix=/usr/local/apr

[root@localhost ~]#make && make install


[root@localhost ~]#cd apr-util-1.3.12

[root@localhost ~]#./configure --prefix=/usr/local/apr-util  \

--with-apr=/usr/local/apr/bin/apr-1-config

[root@localhost ~]#make && make install

 

[root@localhost ~]#cd pcre-8.10  

[root@localhost ~]#./configure --prefix=/usr/local/pcre  

[root@localhost pcre-8.10]#make && make install 



2)安装libxml2

# cd /app/libxml2-2.7.6

# ./configure --prefix=/usr/local/libxml2

# make && make install


3)安装libmcrypt

# cd /app/libmcrypt-2.5.8

# ./configure --prefix=/usr/local/libmcrypt

# make && make install

 

4)安装zlib

# cd /app/zlib-1.2.3

# ./configure

# make && make install


5)安装libpng

# cd /app/libpng-1.2.31

# ./configure --prefix=/usr/local/libpng

# make && make install

6)安装jpeg6

这个软件包安装有些特殊,其它软件包安装时如果目录不存在,会自动创建,但这个软件包安装时需要手动创建。

 

# mkdir /usr/local/jpeg6

# mkdir /usr/local/jpeg6/bin

# mkdir /usr/local/jpeg6/lib

# mkdir /usr/local/jpeg6/include

# mkdir -p /usr/local/jpeg6/man/man1

 

# cd /usr/local/src/jpeg-6b

# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static

# make && make install

 

出错make: ./libtool: Command not found

 

#wget:http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz

#./configure

#make

#make install

 

#cd jpeg-6b 的源码目录

#cp /usr/share/libtool/config/config.sub .

#cp /usr/share/libtool/config/config.guess .


7)安装freetype

# cd /usr/local/src/freetype-2.3.5

# ./configure --prefix=/usr/local/freetype

# make

# make install

8)安装autoconf

# cd /usr/local/src/autoconf-2.61

# ./configurefr

# make && make install

9)安装GD

# cd /app/libgd-2.1.1

# ./configure \

--prefix=/usr/local/gd2/ \

--enable-m4_pattern_allow \

--with-zlib=/usr/local/zlib/ \

--with-jpeg=/usr/local/jpeg6/ \

--with-png=/usr/local/libpng/ \

--with-freetype=/usr/local/freetype/

# make && make install

 

 

configure: error: Unable to find libgd.(a|so) >= 2.1.0 anywhere under /usr/local/gd2/

 

需要安装libgd-2.1.1或者更高版本。


10)安装apache

[root@localhost ~]#cd  httpd-2.4.18 

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

--enable-mods-shared=all 

--enable-so

--enable-proxy-ajp

--enable-rewrite

--with-apr=/usr/local/apr

--with-apr-util=/usr/local/apr-util/

--with-pcre=/usr/local/pcre

# make && make install

 

 

启动Apache

# /usr/local/apache2/bin/apachectl start

启动时报错:httpd: Could not reliably determine the server's fully qualified domain name

解决方法:

vim /usr/local/apache/conf/httpd.conf
找到#ServerName www.example.com:80   把#去掉,再重启apache即可没事了。 


关闭Apache

# /usr/local/apache2/bin/apachectl stop



2Mysql的安装与配置

Mysql5.6版本之后,编译mysql方式变为cmake

 

安装cmake

#yum install cmake

 

#cd mysql-5.6.17

#cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

 

make && make install

 

如果没有就创建用户就创建如下用户:

#groupadd mysql

#useradd -g mysql mysql

修改/usr/local/mysql权限:

#chown -R mysql:mysql /usr/local/mysql

 

#cd /usr/local/mysql

进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表

#scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

 

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!如果发现/etc下存在my.cof文件,直接删掉,这样启动mysql时才会去/usr/local/mysql/my.cnf目录下下去找自己安装的文件

启动MySQL

 

添加服务,拷贝服务脚本到init.d目录,并设置开机启动

#cd /usr/local/mysql

#cp support-files/mysql.server /etc/init.d/mysql

#chkconfig mysql on

#service mysql start  --启动MySQL

 

 

3Php的编译与配置思路

动态编译与静态编译

 

编译安装php5.6.18

cd php-5.6.18

./ 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-png-dir=/usr/local/libpng/ \

--with-jpeg-dir=/usr/local/jpeg6/ \

--with-freetype-dir=/usr/local/freetype/ \

--with-gd=/usr/local/gd2/ \

--with-zlib-dir=/usr/local/zlib/ \

--with-mcrypt=/usr/local/libmcrypt/ \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-xpm-dir=/usr/lib64/\

--enable-soap  \

--enable-mbstring=all \

--enable-sockets

 

 

/php-5.5.5/ext/gd/gd.c -o ext/gd/gd.lo

/usr/local/src/php-5.5.5/ext/gd/gd.c:57:22: 错误:X11/xpm.h:没有那个文件或目录

make: *** [ext/gd/gd.lo] 错误 1

 

yum install libXpm-devel

 

make && make install

 

 

如何新增一个模块

 

#cd /app/lamp/php-5.6.18/ext/mbstring   进入到源目录

#/usr/local/php/bin/phpize (假设php安装在/usr/local/php目录下)

#./configure --with-php-config=/usr/local/php/bin/php-config

#make&&make install

[root@localhost mbstring]# make install

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/

Installing header files:          /usr/local/php/include/php/

4、测试php安装正确性以及数据库连通性

mysql相关的三个模块

 

mysqlmysqlimysqlndpdo-mysql

 

关于php.ini生效路径问题

PHP将按照如下顺序依次查找该文件:

1. 当前工作目录;

2. 环境变量PHPRC指明的路径;

3. 编译时指定的路径。

 

上传文件关注如下几个参数:

 

post_max_size = 128M

upload_max_filesize = 128M

#这两个设置一样即可,可以更大但要注意超时

max_execution_time = 30

max_input_time = 600

memory_limit = 32M