天天看點

LAMP搭建

 LAMP環境可以運作php網站如discuz論壇,他是用php腳本寫的一套網站程式,可以用這個程式運作這個網站,當然還有其他用php腳本寫的流行網站,如wordpress(寫部落格)、phpwind(被阿裡收購)、discuz(被騰訊收購)  。這裡mysql-5.1.40包是免編譯的二進制包,因為mysql編譯很慢很複雜。

 源碼包的名字很簡單,就一個版本号然後就是.tag.gz  

二進制包都會帶 glibc

還有i686或者 x86字眼

  1. 安裝mysql

cd /usr/local/src/ 

wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

注意:上面的位址是32位機器用的,如果你的機器是64位,下載下傳這個包(http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz)安裝方法是一樣的。

[root@aming src]#tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 

[root@aming src]#mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql 

[root@aming src]#cd /usr/local/mysql

[root@aming mysql]#ls 會看到解壓完的檔案和目錄

[root@aming mysql]#mkdir -p /data/mysql 

[root@aming mysql]#useradd -s /sbin/nologin -M mysql (-M是不建立家目錄,家目錄下沒有mysql目錄)

[root@aming mysql]#chown -R mysql:mysql /data/mysql 

[root@aming mysql]#cp support-files/my-large.cnf /etc/my.cnf 

[root@aming mysql]#vi /etc/my.cnf,key_buffer_size=128M,#log-bin=mysql-bin,#binlog-format=mixed         #server-id=1

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

[root@aming mysql]#chmod 755 /etc/init.d/mysqld

[root@aming mysql]#vi /etc/init.d/mysql,basedir=/usr/local/mysql,datadir=/data/mysql

[root@aming mysql]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql (這一步是初始化,正常會看到兩個OK,并且初始化後ls /data/mysql會看到mysql和test兩個目錄)

[root@aming mysql]#chkconfig --add mysqld

[root@aming mysql]#chkconfig mysqld on

[root@aming mysql]#service mysqld start

2. 安裝apache

wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz

[root@aming src]#tar zvxf httpd-2.2.16.tar.gz  

[root@aming src]#cd httpd-2.2.16 

[root@aming httpd-2.2.16]#ls可以看到INSTALL和README

[root@aming httpd-2.2.16]#yum install gcc

[root@aming httpd-2.2.16]#./configure --prefix=/usr/local/apache2  --enable-mods-shared=most  --enable-so 

[root@aming httpd-2.2.16]#make

[root@aming httpd-2.2.16]#make install 

3.  安裝php

wget http://cn2.php.net/distributions/php-5.3.28.tar.gz

[root@aming src]#tar zxvf php-5.3.28.tar.gz 

[root@aming src]#cd php-5.3.28 

[root@aming 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 (報錯解決方法:1、xml2-config not found,[root@aming php-5.3.28]#yum list |grep -i ’xml2‘ [root@aming php-5.3.28]#yum install -y libxml2-devel。2、cannot find openssl [root@aming php-5.3.28]#yum list |grep -i openssl [root@aming php-5.3.28]#yum install -y openssl-devel 3、error:please reinstall the BZIP2 [root@aming php-5.3.28]#yum list |grep bzip2  [root@aming php-5.3.28]#yum install -y bzip2-devel 4、error:jpeglib not found  [root@aming php-5.3.28]#yum list |grep -i jpeg [root@aming php-5.3.28]#yum install libjpeg-turbo-devel openjpeg-devel

5、error:png not found [root@aming php-5.3.28]#yum list |grep png [root@aming php-5.3.28]#yum install -y libpng-devel 6、error:freetype not found  [root@aming php-5.3.28]#yum list|grep freetype [root@aming php-5.3.28]#yum install -y freetype-devel 7、error:mcrypt not found,please reinstall libmcrypt  32位epel yum源下載下傳位址: www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_32.noarch.rpm 

64位下載下傳位址: www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_64.noarch.rpm ,rpm -ivh  http://www.lishiming.net/data/p_w_upload/forum/epel-release-6-8_32.noarch.rpm,[root@aming php-5.3.28]#yum list |grep -i mcrypt [root@aming php-5.3.28]#yum install -y libmcrypt-devel)

[root@aming php-5.3.28]#make(make完之後需要檢測,echo $?  如果是0則是正常)

[root@aming php-5.3.28]# make install 

4、啟動apache

/usr/localapache2/bin/apachectl start(在啟動前,看看配置檔案有沒有錯,/usr/local/apache2/bin/apachectl -t,正常顯示OK)

5. 配置apache結合php

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>

将該行改為:

    DirectoryIndex index.html index.htm index.php

#ServerName www.example.com:80

修改為:

ServerName localhost:80

vim /usr/local/apache2/conf/httpd.conf找到:

<Directory />

    Options FollowSymLinks

    AllowOverride None

    Order deny,allow

    Deny from all

</Directory>

改為:

    Allow from all

6. 測試解析php

vim /usr/local/apache2/htdocs/1.php

寫入:

<?php

    echo "php解析正常";

?>

儲存後,繼續測試:

curl localhost/1.php

php不能解析的原因:

檢查apache有沒有調用php子產品,/usr/local/apache2/bin/apachectl -M,如果沒有php子產品,檢視:ls /usr/localapache2/modules/libphp5.so,如果有,則檢查vi /usr/localapache2/conf/httpd.cnf有沒有LoadModule php5-module modules/libphp5.so,這三個是編譯的時候通過apxs自動寫進去的。有沒有AddType application/x-httpd-php.php

如何開啟開機啟動apache:vi /etc/rc.local 加入/usr/local/apache2/bin/apachectl start

檢視php加載了哪些子產品:/usr/local/php -m

檢視php已經編譯的選項:/usr/local/php/bin/php |head

檢視php的配置檔案;/usr/local/php/bin/php -i

檢視mysql編譯參數:cat /usr/local/mysql/bin/mysqlbug |grep configure

檢視apache有哪些子產品:/usr/local/apache2/bin/apachectl(httpd) -M

參考資料:http://blog.sina.com.cn/s/blog_7e47087d01017bqy.html

http://www.cnblogs.com/52linux/archive/2012/03/24/2415637.html

http://www.j3j5.com/post-285.html

http://blog.csdn.net/bullbat/article/details/7909490/

http://blog.sina.com.cn/s/blog_65d94e4c010195ys.html

apache的動态和靜态  http://www.cnblogs.com/eoiioe/archive/2008/12/23/1360476.html(2.0和2.2一樣)   http://blog.sina.com.cn/s/blog_6238358c01017gdu.html

apache 日志中記錄代理IP以及真實用戶端IP  http://www.lishiming.net/thread-960-1-1.html

apache隻記錄指定URI的日志  http://www.lishiming.net/thread-981-1-1.html

apache的order allow deny  http://www.lishiming.net/thread-832-1-1.html

apache開啟壓縮  http://www.aminglinux.com/bbs/thread-5528-1-1.html

apache虛拟主機開啟php的短标簽   http://www.aminglinux.com/bbs/thread-5370-1-1.html

apache options參數  http://www.aminglinux.com/bbs/thread-1051-1-1.html

apache 禁止trace或track防止xss攻擊  http://www.aminglinux.com/bbs/thread-1045-1-1.html

apache 配置https 支援ssl  http://www.aminglinux.com/bbs/thread-1029-1-1.html

apache的proxy代理總通路後端web的第一個虛拟主機 http://www.aminglinux.com/bbs/thread-941-1-1.html

apache 自定義header  http://www.aminglinux.com/bbs/thread-830-1-1.html

apache的keepalive和keepalivetimeout  http://www.aminglinux.com/bbs/thread-556-1-1.html

apache2.2到2.4配置檔案變更  http://www.aminglinux.com/bbs/thread-7292-1-1.html

apache配置所有的虛拟主機都指向第一個   http://www.aminglinux.com/bbs/thread-491-1-1.html

httpd-2.4版本編譯安裝方法 http://www.aminglinux.com/bbs/thread-7283-1-1.html

繼續閱讀