一、系統以及軟件的准備
系統及編譯安裝包的下載地址:http://pan.baidu.com/s/1jIjqinc 密碼:ghc2
說明:由於centos6.5是分卷壓縮的,且壓縮為三個壓縮包,所以請下載三個壓縮包,並放於同一文件夾中,解壓CentOS-6.5-x86_64-bin-DVD.zip即可。
lamp安裝包文件夾中有19個安裝包,均為必要的環境安裝包或依賴包;下載完成之後將lamp安裝包壓縮為.zip格式壓縮包。
本次環境安裝已以上系統和安裝包為實驗安裝,為確保安裝正確,請嚴格按照以上系統和安裝包。
二、系統的安裝和網絡的配置。
centos6.5 ×86_64的安裝,在此省略安裝步驟。
vim /etc/sysconfig/network-scripts/ifcfg-eth0 配置好網絡。
分區時注意給/usr 分區空間大點,至少10G。因為安裝包是放於/usr/local/src/下,且安裝的位置都是在/usr/local 下。
三、就緒工作
1. 查看系統是否已經默認安裝了httpd、mysql、php。
[root@localhost ~]# rpm -qa | grep httpd* httpd-tools-2.2.15-29.el6.centos.x86_64 httpd-2.2.15-29.el6.centos.x86_64 [root@localhost ~]# rpm -qa | grep mysql* mysql-libs-5.1.71-1.el6.x86_64 [root@localhost ~]# rpm -qa | grep php* redhat-lsb-graphics-4.0-7.el6.centos.x86_64 sane-backends-libs-gphoto2-1.0.21-3.el6.x86_64 gvfs-gphoto2-1.4.3-15.el6.x86_64 phonon-backend-gstreamer-4.6.2-26.el6_4.x86_64 plymouth-graphics-libs-0.8.3-27.el6.centos.x86_64 hyphen-en-2.4-5.1.el6.noarch libreoffice-graphicfilter-4.0.4.2-9.el6.x86_64 hyphen-2.4-5.1.el6.x86_64 libgphoto2-2.4.7-4.el6.x86_64 xorg-x11-drv-elographics-1.4.1-2.el6.x86_64
以上可以看出系統已經默認安裝 了相關軟件,使用以下命令卸載:
yum –y remove htppd *
yum –y remove mysql*
yum –y remove php*
2. 配置防火牆
Vim /etc/sysconfig/iptables ,在以下相應位置,加入 紅色 的兩行
A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited
/etc/init.d/iptables restart 重啟生效。
3. 關閉selinux
vim /etc/selinux/config
在 SELINUX=enforcing SELINUXTYPE=targeted 兩句前面加#號注釋 增加一句 SELINUX=disabled 保存完畢後,shutdown –r now 重啟系統。如下:
#SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. #SELINUXTYPE=targeted SELINUX=disabled
4. 上傳安裝包到指定的位置。
使用rz命令上傳到本機。此時得先安裝rz命令,使用命令 yum –y install lrzsz 命令。切換到指定目錄:cd /usr/local/src ,使用 rz 命令上傳安裝包,上傳完畢後如下:
[root@localhost src]# pwd /usr/local/src [root@localhost src]# ls lamp安裝包.zip
解壓 lamp安裝包.zip, unzip lamp安裝包.zip ;修改名稱為lamp mv lamp安裝包 lamp ,刪除lamp安裝包.zip rm -rf lamp安裝包.zip
四、安裝相關源碼包
2. 編譯安裝libxml2 先yum安裝python-devel
yum –y install python-devel
cd /usr/local/src/lamp
tar zxvf libxml2-2.9.4.tar.gz
cd libxml2-2.9.4
配置安裝目錄,命令如下:
[root@localhost libxml2-2.9.4]# ./configure --prefix=/usr/local/libxml2/
編譯以及安裝 make && make install
此時推薦make 和make install 分兩步操作,以便查看錯誤。且原則上,如果沒有報 eorro錯誤,而只是 leving drictory 是不算錯誤的。
3. 編譯安裝libmcrypt
cd/usr/local/src/lamp
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
配置安裝目錄,命令如下:
[root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt/
make make install
4. 編譯安裝zlib
cd/usr/local/src/lamp
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
配置安裝目錄,命令如下
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib/
make make install
5. 編譯安裝libpng
cd /usr/local/src/lamp
tar zxvf libpng-1.6.23.tar.gz
cd libpng-1.6.23
配置安裝目錄,命令如下
[root@localhost libpng-1.6.23]# ./configure --prefix=/usr/local/libpng/ --enable-shared
make make install
6. 編譯安裝jpeg
cd /usr/local/src/lamp
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a/
mkdir /usr/local/jpeg/
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib/
mkdir /usr/local/jpeg/include/
mkdir -p /usr/local/jpeg/man/man1
配置安裝目錄,命令如下
[root@localhost jpeg-9a]# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
make make install
7. 編譯安裝freeetype
cd /usr/local/src/lamp
tar zxvf freetype-2.6.3.tar.gz
cd freetype-2.6.3
配置安裝目錄,命令如下
[root@localhost freetype-2.6.3]# ./configure --prefix=/usr/local/freetype/ --enable-shared
make make install
8. 編譯安裝autoconf
cd /usr/local/src/lamp
tar zxvf autoconf-2.69.tar.gz
cd autoconf-2.69
autoconf直接在當前目錄配置
./configure
make make install
9. 編譯安裝GD
cd/usr/local/src/lamp
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
vim gd_png.c
找到#include "png.h"改成#include "/usr/local/libpng/include/png.h" ,如下:
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */ #ifdef HAVE_LIBPNG #include "gdhelpers.h" #include "/usr/local/libpng/include/png.h" /* includes zlib.h and setjmp.h */ #define TRUE 1 #define FALSE 0
配置安裝目錄,命令如下
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-zlib=/usr/local/zlib --with-freetype=/usr/local/freetype
make make install
五、安裝apache
1. 編譯安裝apr-1.5.2
先查看是否安裝apr 、apr-util 使用命令 rpm -q apr apr-util,如果已經安裝則yum –y remove apr apr-util
cd /usr/local/src/lamp
tar zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
配置安裝目錄,命令如下
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr-httpd/
make make install
2. 編譯安裝apr-util
cd /usr/local/src/lamp
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
配置安裝目錄,命令如下
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd
make make install
3. 編譯安裝pcre
cd/usr/local/src/lamp
tar zxvf pcre-8.34.tar.gz
cd pcre-8.34
配置安裝目錄,命令如下
[root@localhost pcre-8.34]# ./configure --prefix=/usr/local/pcre
make make install
4. 編譯安裝apache
cd /usr/local/src/lamp
tar zxvf httpd-2.4.20.tar.gz
cd httpd-2.4.20
配置安裝目錄,命令如下
[root@localhost httpd-2.4.20]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-rewrite=shared --enable-static-support --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-apr=/usr/local/apr-httpd --with-apr-util=/usr/local/apr-util-httpd --with-pcre=/usr/local/pcre --disable-userdir
make make install
修改配置,vim /etc/httpd/httpd.conf
在配置文件增加一行 ServerName localhost:80
#ServerName www.example.com:80 ServerName localhost:80
啟動apache /usr/local/apache2/bin/apachectl start
打開浏覽器測試,輸入192.168.0.225 (本機ip地址為192.168.0.225)發現 it works 證明 apache安裝成功
設置apahce開機啟動,使用命令 echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
將apache啟動加入服務, cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd ,給予執行權限 chmod +x /etc/init.d/httpd
vi /etc/rc.d/init.d/httpd 在第二行加入以下兩行 #chkconfig:2345 10 90 #description:Activates/Deactivates Apache Web Server,保存後退出
#!/bin/sh #chkconfig:2345 10 90 #description:Activates/Deactivates Apache Web Server # Licensed to the Apache Software Foundation (ASF) under one or more
chkconfig --add httpd
chkconfig --level 2345 httpd on
service httpd restart
六、安裝mysql
1. 編譯安裝cmake
cd /usr/local/src/lamp
tar zxvf cmake-3.4.3.tar.gz
cd cmake-3.4.3
./bootstrap
gmake
make make install
2. 安裝ncurses-devel
yum -y install ncurses-devel
3. 創建用戶、組和目錄
groupadd mysql
useradd mysql -g mysql
passwd mysql 設置密碼為123
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql
4. 編譯安裝msql
cd/usr/local/src/lamp
tar zxvf mysql-5.5.23.tar.gz
cd mysql-5.5.23
配置安裝目錄,命令如下
[root@localhost mysql-5.5.23]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql-DMYSQL_TCP_PORT=3306
make make install
cd /usr/local/mysql/
給當前安裝目錄設置權限
chown -R root.mysql .
chown -R mysql.mysql ./data
初始化數據庫 /usr/local/mysql/scripts/mysql_install_db --user=mysql
拷貝mysql配置文件 cp support-files/my-medium.cnf /etc/my.cnf
啟動mysql服務 /usr/local/mysql/bin/mysqld_safe --user=mysql &
給sock文件設置mysql權限 chown mysql.mysql /tmp/mysql.sock
追加開機啟動 echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local
設置密碼為123 /usr/local/mysql/bin/mysqladmin -uroot password 123
測試連接mysql /usr/local/mysql/bin/mysql -uroot -p ,連接成功,則整個mysql安裝成功。
為mysql配置環境變量 export PATH=/usr/local/mysql/bin:$PATH
將mysql加入服務 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
設置遠程登錄root用戶權限,密碼為 123 登錄錄進mysql
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
flush privileges;
重啟mysql服務 service mysqld restart
七、安裝php
1. 安裝libXpm-devel
yum -y install libXpm-devel
2. 編譯安裝php
cd /usr/local/src/lamp
tar zxvf php-5.6.22.tar.gz
cd php-5.6.22
配置安裝目錄,命令如下
[root@localhost php-5.6.22]# ./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-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-gd --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-xpm-dir=/usr/lib64 --enable-soap --enable-mbstring=all -enable-sockets
make make install
cp php.ini-development /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
修改php.ini 把;date.timezone 前面的分號去掉,改成date.timezone ="PRC"
vim /etc/httpd/httpd.conf
在AddType application/x-gzip .gz .tgz後面添加兩行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
# # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this.
將下面一行DirectoryIndex index.html 更改為:DirectoryIndex index.php index.html index.htm 修改完後,退出。
# # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.php index.html index.htm </IfModule>
Service httpd restart
八、安裝PDO擴展
cd /usr/local/src/lamp
tar zxvf PDO_MYSQL-1.0.2.tgz.1
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
ln -s /usr/local/mysql/include/* /usr/local/include/
配置安裝目錄,命令如下
[root@localhost PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make make install
vim /usr/local/php/etc/php.ini
在php.ini裡面配置加載pdo 擴展
extension=pdo.so extension=pdo_mysql.so
; For example, on Windows: ; ; extension=msql.dll ; ; ... or under UNIX: ; ; extension=msql.so extension=pdo.so extension=pdo_mysql.so ;
加入一行命令 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226"
; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226" ; On windows: ; extension_dir = "ext"
重啟apache service httpd restart
vim /usr/local/apache/htdocs/index.php phpinfo()檢測是否安裝成。如圖:
參考鏈接:http://wenku.baidu.com/view/98299b48c5da50e2524d7fd3.html?re=view
http://xxxxxx/Linuxjc/1171551.html TechArticle