LAMP = Linux + Apache + Mysql + PHP
安装流程
[Apache]
1. 准备:环境库apr apr-util 包httpd-2.2.*.tar.gz
2. 过程:
#yum install -y apr apr-util
[/usr/local/src]# tar zvxf httpd-2.2.*.tar.gz
[/usr/local/src]# mv httpd-2.2.* ..
[/usr/local]# cd httpd-2.2.*
[/usr/local]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so(可扩展)
[/usr/local]# make && make install
3、初次使用
(1)vim /usr/local/apache2/conf/httpd.conf
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
(2)iptables开启80端口,selinux=disabled
[mysql]
1、 准备:mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
2、 安装过程
[~]# cd /usr/local/src
[/usr/local/src]# wget http://syslab.comsenz.com/downloads/linux
/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
[/usr/local/src]# tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc
-glibc23.tar.gz
[/usr/local/src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local
/mysql
[/usr/local/src]# useradd -M -s /sbin/nologin mysql
[/usr/local/src]# cd /usr/local/mysql
[/usr/local/mysql]# mkdir -p /data/mysql //自定义数据存放目录
[/usr/local/mysql]# chown -R mysql:mysql /data/mysql
[/usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
//这步可能会出一些错误,如mysql_install_db不是可执行文件,某些表不能生成
[/usr/local/mysql]# cp support-files/my-large.cnf /etc/my.cnf //直接覆盖,系统默认会寻找my.cnf
[/usr/local/mysql]# cp support-files/mysql.server /etc/init.d/mysqld
//将mysql数据库启动脚本放入系统运行启动控制目录
[/usr/local/mysql]# chmod 755 /etc/init.d/mysqld
[/usr/local/mysql]# vim /etc/init.d/mysqld
//修改basedir=安装目录,datadir=数据目录/data/mysql
[/usr/local/mysql]# chkconfig --add mysqld //添加到开机启动项
[/usr/local/mysql]# chkconfig mysqld on //设置开机启动
[/usr/local/mysql]# service mysqld start //启动数据库服务
3、 初次使用
(1) 系统路径使用
vim /etc/profile
MYSQL_HOME=/usr/local/mysql(安装目录)
$PATH=…:$MYSQL_HOME/bin
export …MYSQL_HOME
(2) 修改root密码
mysql -u root
mysql > use mysql;
mysql > update user set password='root password' where user='root';
mysql > flush privileges;
mysql > quit;
之后情况如下:
mysql -u root -p
Enter password:
(3)远程连接授权使用
mysql > grant all privileges on database.table to‘user’@’hostIP’
identified by ‘password’with grant option;
例如grant all privileges on *.* to 'user'@'%'identified by 'MYPASSWORD' with grant option;
mysql > flush privileges;
[php]
1、 准备:环境库bzip2-devel,libxml2-devel,glibc,libjpeg-devel,libtool*
libpng-devel,openssl-devel, freetype-devel, libmcrypt-devel(yum源或编译包),pcre-devel, libXpm-devel
包php-5.3.28.tar.gz
2、 安装过程
[/usr/local/src]# wget http://cn2.php.net/distributions/php-5.3.28.
tar.gz
[/usr/local/src]# tar zvxf php-5.3.28.tar.gz
[/usr/local/src]# mv php-5.3.28 /usr/local
[/usr/local]# cd php-5.3.28
[/usr/local/ 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
[/usr/local/php-5.3.28]# make && make install
漫长的等待编译……
3、 整合Apache
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>
4、测试解析php
vim /usr/local/apache2/htdocs/1.php
写入一个页面:
<?php
phpinfo();
?>
保存后,重启Apache:
/usr/local/apache2/bin/apachectl restart
测试访问:http://localhost/1.php //可以看到本机PHP安装及配置列表
安装流程
[Apache]
1. 准备:环境库apr apr-util 包httpd-2.2.*.tar.gz
2. 过程:
#yum install -y apr apr-util
[/usr/local/src]# tar zvxf httpd-2.2.*.tar.gz
[/usr/local/src]# mv httpd-2.2.* ..
[/usr/local]# cd httpd-2.2.*
[/usr/local]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most --enable-so(可扩展)
[/usr/local]# make && make install
3、初次使用
(1)vim /usr/local/apache2/conf/httpd.conf
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
(2)iptables开启80端口,selinux=disabled
启动:/usr/local/apache2/bin/apachectl start 可以看到"It works!"
4、添加到开机启动服务
Apache的启动脚本其实在源码包的build/rpm/中,文件httpd.init
cp **/httpd-*/build/rpm/httpd.init /etc/init.d/httpd
修改其中的
apachectl=/usr/local/apache/bin/apachectl(新版本这行可能没有了)
httpd=${HTTPD-/usr/local/apache2/bin/httpd} (执行路径自行定义)
CONFFILE=/usr/local/apache2/conf/httpd.conf
保存后,
chmod 700 /etc/init.d/httpd
chkconfig --add httpd ; chkconfig httpd on
就可以使用类似service httpd start 或 /etc/init.d/httpd stop方式启动
[mysql]
1、 准备:mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
2、 安装过程
[~]# cd /usr/local/src
[/usr/local/src]# wget http://syslab.comsenz.com/downloads/linux
/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
[/usr/local/src]# tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc
-glibc23.tar.gz
[/usr/local/src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local
/mysql
[/usr/local/src]# useradd -M -s /sbin/nologin mysql
[/usr/local/src]# cd /usr/local/mysql
[/usr/local/mysql]# mkdir -p /data/mysql //自定义数据存放目录
[/usr/local/mysql]# chown -R mysql:mysql /data/mysql
[/usr/local/mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
//这步可能会出一些错误,如mysql_install_db不是可执行文件,某些表不能生成
[/usr/local/mysql]# cp support-files/my-large.cnf /etc/my.cnf //直接覆盖,系统默认会寻找my.cnf
[/usr/local/mysql]# cp support-files/mysql.server /etc/init.d/mysqld
//将mysql数据库启动脚本放入系统运行启动控制目录
[/usr/local/mysql]# chmod 755 /etc/init.d/mysqld
[/usr/local/mysql]# vim /etc/init.d/mysqld
//修改basedir=安装目录,datadir=数据目录/data/mysql
[/usr/local/mysql]# chkconfig --add mysqld //添加到开机启动项
[/usr/local/mysql]# chkconfig mysqld on //设置开机启动
[/usr/local/mysql]# service mysqld start //启动数据库服务
3、 初次使用
(1) 系统路径使用
vim /etc/profile
MYSQL_HOME=/usr/local/mysql(安装目录)
$PATH=…:$MYSQL_HOME/bin
export …MYSQL_HOME
(2) 修改root密码
mysql -u root
mysql > use mysql;
mysql > update user set password='root password' where user='root';
mysql > flush privileges;
mysql > quit;
之后情况如下:
mysql -u root -p
Enter password:
(3)远程连接授权使用
mysql > grant all privileges on database.table to‘user’@’hostIP’
identified by ‘password’with grant option;
例如grant all privileges on *.* to 'user'@'%'identified by 'MYPASSWORD' with grant option;
mysql > flush privileges;
[php]
1、 准备:环境库bzip2-devel,libxml2-devel,glibc,libjpeg-devel,libtool*
libpng-devel,openssl-devel, freetype-devel, libmcrypt-devel(yum源或编译包),pcre-devel, libXpm-devel
包php-5.3.28.tar.gz
2、 安装过程
[/usr/local/src]# wget http://cn2.php.net/distributions/php-5.3.28.
tar.gz
[/usr/local/src]# tar zvxf php-5.3.28.tar.gz
[/usr/local/src]# mv php-5.3.28 /usr/local
[/usr/local]# cd php-5.3.28
[/usr/local/ 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
[/usr/local/php-5.3.28]# make && make install
漫长的等待编译……
3、 整合Apache
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>
4、测试解析php
vim /usr/local/apache2/htdocs/1.php
写入一个页面:
<?php
phpinfo();
?>
保存后,重启Apache:
/usr/local/apache2/bin/apachectl restart
测试访问:http://localhost/1.php //可以看到本机PHP安装及配置列表