天天看點

搭建LAMP架構

環境:linux、httpd-2.2、mysql-5.5、php-5.3

1、源碼包編譯安裝需要的包:

[root@VM_158_68_centoshttpd-2.2.17]# yum -y install gcc gcc-c++ make zlib-devel

2、檢查系統有沒有裝httpd  rpm包:

[root@VM_158_68_centos ~]# rpm -qa|grep httpd

[root@VM_158_68_centos ~]# 

3、源碼編譯安裝apache:

....下載下傳httpd源碼包:

....解壓、配置、編譯、安裝:

[root@VM_158_68_centos~]# tar xf httpd-2.2.17.tar.gz -C /usr/src

[root@VM_158_68_centos ~]# cd /usr/src/httpd-2.2.17/

[root@VM_158_68_centoshttpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-cgi --enable-so--enable-charset-lite  --enable-deflate--enable-expires --enable-rewrite

[root@VM_158_68_centos httpd-2.2.17]# make && make install

4、檢視有沒有安裝成功:

[root@VM_158_68_centos httpd-2.2.17]# ls /usr/local/httpd/

bin  build  cgi-bin  conf  error  htdocs  icons  include  lib  logs  man  manual  modules

5、建立軟連接配接、并檢視:

[root@VM_158_68_centoshttpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

[root@VM_158_68_centos httpd-2.2.17]# ll /usr/local/bin

6、建立配置檔案

[root@VM_158_68_centos httpd-2.2.17]# cp  /usr/local/httpd/bin/apachectl   /etc/init.d/httpd

[root@VM_158_68_centoshttpd-2.2.17]# chmod +x /etc/init.d/httpd

[root@VM_158_68_centos httpd-2.2.17]# sed -i -e '1a#chkconfig: 35 85 21'   /etc/init.d/httpd

[root@VM_158_68_centos httpd-2.2.17]# chkconfig --add  httpd

[root@VM_158_68_centos httpd-2.2.17]# chkconfig --list  httpd

7、啟動http服務

[root@VM_158_68_centoshttpd-2.2.17]# service httpd start

8、檢視是否開啟80端口

[root@VM_158_68_centoshttpd-2.2.17]# netstat -atnpl|grep httpd

9、編譯安裝cmake

[root@VM_158_68_centos~]# tar xf cmake-2.8.6.tar.gz -C /usr/src

[root@VM_158_68_centos~]# cd /usr/src/cmake-2.8.6/

[root@VM_158_68_centos~]# ./configure && make && make install

10、編譯安裝MySQL

.......先安裝ncurses-devel 庫:[root@VM_158_68_centos~]# yum -y  install   ncurses-devel

[root@VM_158_68_centos ~]#useradd -M -s /sbin/nologin mysql

[root@VM_158_68_centos ~]# tar xf mysql-5.5.22.tar.gz -C /usr/src/

[root@VM_158_68_centos ~]#cd  /usr/src/mysql-5.5.22/

[root@VM_158_68_centos mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DDEFAULT_CHARSET=utf8 \

>  -DDEFAULT_COLLATION=utf8_general_ci-DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc

[root@VM_158_68_centos mysql-5.5.22]#make  && make install

......更改屬主屬組:

[root@VM_158_68_centosmysql-5.5.22]# chown -R mysql:mysql /usr/local/mysql/

.....建立配置檔案:

[root@VM_158_68_centosmysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf

.....初始化資料庫:

[root@VM_158_68_centosmysql-5.5.22]# /usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql/ \

>  --datadir=/usr/local/mysql/data --user=mysql

[root@VM_158_68_centosmysql-5.5.22]# ls /usr/local/mysql/data/

[root@VM_158_68_centosmysql-5.5.22]# ln -s /usr/local/mysql/bin/* /usr/local/bin

.....添加為系統:

 [root@VM_158_68_centos mysql-5.5.22]# cp  support-files/mysql.server   /etc/init.d/mysqld

[root@VM_158_68_centosmysql-5.5.22]# chmod +x /etc/init.d/mysqld

[root@VM_158_68_centosmysql-5.5.22]# chkconfig  --add mysqld

[root@VM_158_68_centosmysql-5.5.22]# chkconfig --list mysqld

.....啟動資料庫:

[root@VM_158_68_centosmysql-5.5.22]# /etc/init.d/mysqld start

[root@VM_158_68_centosmysql-5.5.22]# netstat -atnpl|grep mysqld

.....登入資料庫:

[root@VM_158_68_centosmysql-5.5.22]# mysql -u root

....建立資料庫賬戶和密碼:

[root@VM_158_68_centosmysql-5.5.22]# mysqladmin -u root password '123123'

.....驗證登入:

[root@VM_158_68_centosmysql-5.5.22]# mysql -uroot -p'123123'

11、編譯安裝php(mcrypt加密、支援gif、png、gd、jpeg類型檔案、):

[root@VM_158_68_centos libmcrypt-2.5.8]# yum -y  install libxml2-devel 

[root@VM_158_68_centos ~]# tar xflibmcrypt-2.5.8.tar.gz -C /usr/src

[root@VM_158_68_centos ~]# cd/usr/src/libmcrypt-2.5.8

[root@VM_158_68_centos libmcrypt-2.5.8]#./configure && make && make install

[root@VM_158_68_centoslibmcrypt-2.5.8]# ln -s /usr/local/lib/libmcrypt* /usr/lib

......mhash安裝:

[root@VM_158_68_centos ~]# tar xfmhash-0.9.9.9.tar.gz -C /usr/src

[root@VM_158_68_centos ~]# cd/usr/src/mhash-0.9.9.9/

[root@VM_158_68_centos mhash-0.9.9.9]#./configure &&  make &&make install

[root@VM_158_68_centos mhash-0.9.9.9]#ln -s /usr/local/lib/libmhash.* /usr/lib

Mcrypt安裝:

[root@VM_158_68_centos ~]# tar xfmcrypt-2.6.8.tar.gz -C /usr/src/

[root@VM_158_68_centos ~]# cd /usr/src/mcrypt-2.6.8/

[root@VM_158_68_centos  libmcrypt-2.5.8]# export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

[root@VM_158_68_centos mcrypt-2.6.8]#./configure && make && make install

[root@VM_158_68_centos ~]# tar xf php-5.3.28.tar.gz -C /usr/src

[root@VM_158_68_centos ~]# cd /usr/src/php-5.3.28/

[root@VM_158_68_centos php-5.3.28]# ./configure --prefix=/usr/local/php5  --with-apxs2=/usr/local/httpd/bin/apxs  --with-mcrypt  --with-mysql=/usr/local/mysql  --with-config-file-path=/usr/local/php5  --enable-mbstring  --with-gd   --with-jpeg-dir=/usr/local/jpeg/  --with-png-dir=/usr/local/png/

[root@VM_158_68_centos php-5.3.28]#make && make install

[root@VM_158_68_centos php-5.3.28]# cpphp.ini-development /usr/local/php5/php.ini

[root@VM_158_68_centos php-5.3.28]# awk'/^short_open_tag/{print NR,$0}' /usr/local/php5/php.ini

[root@VM_158_68_centos php-5.3.28]# sed-i '226 s/Off/On/' /usr/local/php5/php.ini

[root@VM_158_68_centos php-5.3.28]# awk'  /default_charset/{print NR,$0}' /usr/local/php5/php.ini

[root@VM_158_68_centos php-5.3.28]# sed -i  -e  '784 s/;// ; s/iso-8859-1/utf-8/' /usr/local/php5/php.ini

php優化子產品:

[root@VM_158_68_centos ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz  –C  /usr/src

[root@VM_158_68_centos~]#cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/

[root@VM_158_68_centos php-5.3.x]# cpZendGuardLoader.so /usr/local/php5/lib/php/

[root@VM_158_68_centos php-5.3.x]# echo -e 'zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so\nzend_loader.enable=1'  >> /usr/local/php5/php.ini

修改Apache配置檔案讓支援php。

[root@VM_158_68_centos ~]# awk '/LoadModule  php5_module/{print NR,$0}' /usr/local/httpd/conf/httpd.conf

[root@VM_158_68_centos ~]# sed  -i '53aAddType application/x-httpd-php .php' /usr/local/httpd/conf/httpd.conf

[root@VM_158_68_centos ~]# awk '/DirectoryIndex/{print NR,$0}' /usr/local/httpd/conf/httpd.conf

[root@VM_158_68_centos ~]# sed -i  '168s/$/ index.php/' /usr/local/httpd/conf/httpd.conf

[root@VM_158_68_centos ~]# httpd –t

[root@VM_158_68_centos ~]#/etc/init.d/httpd restart

LAMP架構搭建完成:

Php源碼包下載下傳連結:   

安裝png、jpeg報錯的解決方法:

<a href="http://ixdba.blog.51cto.com/2895551/526435" target="_blank">http://ixdba.blog.51cto.com/2895551/526435</a>

安裝gd報錯解決方法(打開連接配接最下面是)

本文轉自liujing0751CTO部落格,原文連結: http://blog.51cto.com/13281352/1967292如需轉載請自行聯系原作者