LAMP环境编译安装

2016-09-13 05:12:05   服务器

  lamp   apache   php   mysql  

卸载旧版本

#检测是否已经安装rpm包 
rpm -qa | grep httpd 
rpm -qa | grep mysql 
rpm -qa | grep php  

#如果存在卸载(已mysql为例) 
rpm -e --nodeps mysql

安装Mysql

#安装编译依赖包 
yum -y install make gcc-c++ cmake bison-devel ncurses-devel  

#下载并解压 wget http://mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz 
tar -zxvf mysql-5.6.14.tar.gz 
cd mysql-5.6.14  

#编译安装 
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  

#修改权限 
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  

#复制配置文件 
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf  

#复制mysql服务启动脚本及加入PATH路径  
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld  
vim /etc/profile  PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH  export PATH   

#修改后让profile立即生效  
source /etc/profile   

#启动mysql服务并加入开机自启动 
service mysqld start 
chkconfig --level 35 mysqld on  

#检查mysql服务是否启动 
netstat -tulnp | grep 3306   

#修改Mysql的root密码 
set password=password('moell'); #方法1  

#方法二
use mysql  
update user set password=password('moell') where user='root' AND host='localhost'; 
flush privileges;  

#允许远程连接 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 

#方法一,密码可以与本地root密码不一样 

FLUSH PRIVILEGES # 刷新缓存区

Apache安装

#下载解压 wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.2.31.tar.gz 
tar -zxv -f httpd-2.2.32.tar.gz 
cd httpd-2.2.32  #

编译安装 ./configure --prefix=/usr/local/apache/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support  
make & make install  

#创建用户,组 
groupadd apache 
useradd -g apache apache  

#修改配置 
vi /etc/httpd/httpd.conf 
User apache 
Group apache  
chown -R apache.apache /usr/local/apache  
vi /usr/local/apache/bin/apachectl 
#在第二行添加 
# chkconfig: 2345 10 90 
# description: Activates/Deactivates Apache Web Server   

#设置apache的自启动及运行等级 
cd /etc/rc.d/init.d 
cp /usr/local/apache/bin/apachectl httpd 
chmod 755 httpd  
chkconfig --add httpd 
chkconfig --level 345 httpd on 
chkconfig --level 0126 httpd off  

#启动 
service httpd start

编译安装PHP

#yum安装所需要的依赖包 
yum install libxml2 libxml2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel libtool-ltdl-devel gd openssl openssl-devel  

#安装freetype  
tar -zxvf freetype-2.3.5.tar.gz  
cd freetype-2.3.5 
./configure --prefix=/usr/local/freetype/ 
make & make install  

#解压缩php源码包 
tar -zxvf php-5.3.10.tar.gz cd php-5.3.10  

#编译 
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml --with-png --with-jpeg-dir=/usr/lib --with-curl --with-mcrypt --enable-mbstring --with-freetype-dir=/usr/local/freetype --with-gd --with-mcrypt --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-sockets   
make & make install  

#复制配置文件 
cp php.ini-production /usr/local/php/etc/php.ini  

#配置apache支持php解析 
#AddType text/html .shtml 后添加 
AddType application/x-httpd-php .php .phtml 

#index.html 前添加index.php 
<IfModule dir_module> 
DirectoryIndex index.php index.html 
</IfModule>