LAMP環境編譯安裝

Apache有兩種模式提供服務,一種是線程worker模式,一種是進程prefork模式(更加穩定)

線程模式是一個進程下面有許多線程提供服務。

而進程模式是直接是許多進程提供服務,但是消耗cpu。


安裝apache

[root@lamp src]# ls

httpd-2.2.27.tar.gz

[root@lamp src]# pwd

/usr/local/src

[root@lamp src]# tar -xf httpd-2.2.27.tar.gz

[root@lamp src]# ls

httpd-2.2.27  httpd-2.2.27.tar.gz

[root@lamp src]# cd httpd-2.2.27

[root@lamp httpd-2.2.27]# ./configure \

--prefix=/usr/local/apache2.2.27 \

--enable-deflate \

--enable-expires \

--enable-headers \

--enable-modules=most \

--enable-so \

--with-mpm=worker \

--enable-rewrite


[root@lamp httpd-2.2.27]# yum install -y zlib zlib-devel


[root@lamp httpd-2.2.27]#make && make install


[root@lamp src]# cd ..

[root@lamp local]# ls

apache2.2.27  etc    include  lib64    sbin   src

bin           games  lib      libexec  share

[root@lamp local]# ln -s apache2.2.27 /usr/local/apache


[root@lamp local]# cd apache

[root@lamp apache]# ls

bin    cgi-bin  error   icons    lib   man     modules

build  conf     htdocs  include  logs  manual


檢測語法

[root@lamp local]# /usr/local/apache/bin/apachectl -t

httpd: apr_sockaddr_info_get() failed for lamp

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Syntax OK


啓動apache

[root@lamp local]# /usr/local/apache/bin/apachectl start

httpd: apr_sockaddr_info_get() failed for lamp

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName


檢測是否啓動

[root@lamp local]# ps -aux |grep httpd

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root      5133  0.0  0.2  34416  2132 ?        Ss   05:10   0:00 /usr/local/apache2.2.27/bin/httpd -k start

daemon    5134  0.0  0.1  34148  1300 ?        S    05:10   0:00 /usr/local/apache2.2.27/bin/httpd -k start

daemon    5135  0.0  0.3 378676  3892 ?        Sl   05:10   0:00 /usr/local/apache2.2.27/bin/httpd -k start

daemon    5136  0.0  0.3 378676  3900 ?        Sl   05:10   0:00 /usr/local/apache2.2.27/bin/httpd -k start

daemon    5137  0.1  0.3 378676  3900 ?        Sl   05:10   0:00 /usr/local/apache2.2.27/bin/httpd -k start

root      5220  0.0  0.0 103244   856 pts/0    S+   05:10   0:00 grep httpd


[root@lamp local]# lsof -i :80

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd   5133   root    4u  IPv6  59038      0t0  TCP *:http (LISTEN)

httpd   5135 daemon    4u  IPv6  59038      0t0  TCP *:http (LISTEN)

httpd   5136 daemon    4u  IPv6  59038      0t0  TCP *:http (LISTEN)

httpd   5137 daemon    4u  IPv6  59038      0t0  TCP *:http (LISTEN)



測試

[root@lamp local]# iptables -F

[root@lamp local]# /etc/init.d/iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

wKiom1hX9SeQ88HOAAAs5gkzCzI106.png


配置站點

[root@lamp conf]# pwd

/usr/local/apache/conf

[root@lamp conf]# ls

extra  httpd.conf  magic  mime.types  original


[root@lamp conf]# grep -i documentroot httpd.conf 

# DocumentRoot: The directory out of which you will serve your

DocumentRoot "/usr/local/apache2.2.27/htdocs"

# This should be changed to whatever you set DocumentRoot to.

    # access content that does not live under the DocumentRoot.


平滑重啓

[root@lamp apache]# /usr/local/apache/bin/apachectl graceful




Apache的配置文件講解


查看配置裏面站點默認的頁面

[root@lamp conf]# vim httpd.conf


<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>




目錄結構的設置

-Indexes就是禁止顯示目錄結構了

或者把這裏刪除掉,當主頁沒有找到的話就顯示403,而不會顯示目錄結構,確保安全

Options -Indexes FollowSymLinks




虛擬主機配置文件

[root@lamp extra]# ls -l /usr/local/apache/conf/extra

total 56

-rw-r--r-- 1 root root  2855 Dec  7 05:01 httpd-autoindex.conf

-rw-r--r-- 1 root root  1743 Dec  7 05:01 httpd-dav.conf

-rw-r--r-- 1 root root  2344 Dec  7 05:01 httpd-default.conf 瞭解

-rw-r--r-- 1 root root  1103 Dec  7 05:01 httpd-info.conf

-rw-r--r-- 1 root root  5078 Dec  7 05:01 httpd-languages.conf

-rw-r--r-- 1 root root   945 Dec  7 05:01 httpd-manual.conf

-rw-r--r-- 1 root root  3789 Dec  7 05:01 httpd-mpm.conf

-rw-r--r-- 1 root root 11492 Dec  7 05:01 httpd-ssl.conf

-rw-r--r-- 1 root root   817 Dec  7 05:01 httpd-userdir.conf

-rw-r--r-- 1 root root  1503 Dec  7 05:01 httpd-vhosts.conf



虛擬主機配置:

域名站點目錄

www.bier.org  /var/html/www

blog.bier.org /var/html/blog

bbs.bier.org  /var/html/bbs

創建站點目錄

[root@lamp extra]# mkdir -p /var/html/www

[root@lamp extra]# mkdir -p /var/html/blog

[root@lamp extra]# mkdir -p /var/html/bbs


[root@lamp extra]# touch /var/html/www/index.html

[root@lamp extra]# touch /var/html/blog/index.html

[root@lamp extra]# touch /var/html/bbs/index.html


[root@lamp extra]# tree /var/html/

/var/html/

|-- bbs

|   `-- index.html

|-- blog

|   `-- index.html

`-- www

`-- index.html


[root@lamp extra]# for i in www blog bbs;do echo "http://$i.bier.org" >/var/html/$i/index.html;done



[root@lamp extra]# for i in www blog bbs;do cat /var/html/$i/index.html;done

http://www.bier.org

http://blog.bier.org

http://bbs.bier.org


配置虛擬機主機

[root@lamp extra]# pwd

/usr/local/apache/conf/extra

[root@lamp extra]# vim httpd-vhosts.conf



<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/var/html/www"

    ServerName www.bier.org

    ServerAlias bier.org

    ErrorLog "logs/www-error_log"

    CustomLog "logs/www-access_log" common

</VirtualHost>



<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/var/html/blog"

    ServerName blog.bier.org

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log" common

</VirtualHost>


<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/var/html/bbs"

    ServerName bbs.bier.org

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log" common

</VirtualHost>




打開主配置文件這裏

[root@lamp conf]# pwd

/usr/local/apache/conf

[root@lamp conf]# vim httpd.conf


# Virtual hosts

Include conf/extra/httpd-vhosts.conf


添加站點目錄

<Directory "/var/html">

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

</Directory>



檢測重啓

[root@lamp conf]# /usr/local/apache/bin/apachectl -t

Syntax OK


[root@lamp conf]# /usr/local/apache/bin/apachectl graceful



然後本地解析測試,瀏覽器訪問



安裝apache日誌輪詢工具cronolog

 (此工具工作中用這種比較多,不用系統自帶的)

安裝cronolog工具

tar -xf cronolog-1.6.2.tar.gz

cd cronolog-1.6.2

./configure 

make 

make install


[root@lamp src]# ll /usr/local/sbin/cronolog 

-rwxr-xr-x 1 root root 40438 Dec  7 08:24 /usr/local/sbin/cronolog





Cronolog日誌輪詢配置說明

錯誤寫法:

CustomLog "|/usr/local/sbin/cronolog logs/access_www_%w.log" common

提示:cronllog日誌輪詢的正確寫法,被輪詢的日誌路徑要寫全



正確寫法

CustomLog "|/usr/local/sbin/cronolog /app/logs/access_www_%Y%m%d.log" common

提示:這個大多數網站的常規寫法(按天記錄日誌,日誌不會被自動覆蓋)


[root@lamp src]# mkdir -p /app/logs


在虛擬主機修改好格式,檢測重啓訪問測試

[root@lamp apache]# tail -f /app/logs/access_www_20151207.log     

192.168.3.1 - - [07/Dec/2015:08:58:37 -0500] "GET / HTTP/1.1" 304 -

192.168.3.1 - - [07/Dec/2015:08:58:39 -0500] "GET / HTTP/1.1" 304 -

192.168.3.1 - - [07/Dec/2015:08:58:39 -0500] "GET / HTTP/1.1" 304 -

192.168.3.1 - - [07/Dec/2015:08:59:50 -0500] "GET / HTTP/1.1" 304 -

192.168.3.1 - - [07/Dec/2015:08:59:51 -0500] "GET / HTTP/1.1" 304 -

192.168.3.1 - - [07/Dec/2015:08:59:51 -0500] "GET / HTTP/1.1" 304 -




安裝mysql

創建mysql用戶

[root@lamp src]# useradd mysql -s /sbin/nologin –M



./configure \

--prefix=/usr/local/mysql5.1.72 \

--with-unix-socket-path=/usr/local/mysql5.1.72/tmp/mysql.sock \

--localstatedir=/usr/local/mysql5.1.72/data \

--enable-assembler \

--enable-thread-safe-client \

--with-mysqld-user=mysql \

--with-big-tables \

--without-debug \

--with-pthread \

--enable-assembler \

--with-extra-charsets=complex \

--with-readline \

--with-ssl \

--with-embedded-server \

--enable-local-infile \

--with-plugins=partition,innobase \

--with-mysqld-ldflags=-all-static \

--with-client-ldflags=-all-static


可以將上面的腳本放入mysql.log,然後cat mysql.log|bash 執行


修改錯誤

checking for termcap functions library... configure: error: No curses/termcap library found


[root@lamp mysql-5.1.72]# yum install -y ncurses ncurses-devel


make && make install


[root@lamp local]# ln -s mysql5.1.72/ /usr/local/mysql


[root@lamp mysql]# mkdir -p /usr/local/mysql/data存放數據的地方

[root@lamp mysql]# chown -R mysql.mysql /usr/local/mysql/data


配置mysql


[root@lamp mysql]# ls /usr/local/mysql/share/mysql/my*.cnf

/usr/local/mysql/share/mysql/my-huge.cnf

/usr/local/mysql/share/mysql/my-innodb-heavy-4G.cnf

/usr/local/mysql/share/mysql/my-large.cnf

/usr/local/mysql/share/mysql/my-medium.cnf

/usr/local/mysql/share/mysql/my-small.cnf


提示:此版本這些文件在上面的目錄下面,一般是在安裝目錄下的support-files的這個目錄下


[root@lamp mysql]# cd /usr/local/mysql/share/mysql/

[root@lamp mysql]# cp my-small.cnf /etc/my.cnf

mysql默認的配置路徑和文件名/etc/my.conf






初始化數據庫

[root@lamp mysql]# /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql


Installing MySQL system tables...

151207 11:09:10 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

OK

Filling help tables...

151207 11:09:11 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

OK


To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system


/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

/usr/local/mysql/bin/mysqladmin -u root -h lamp password 'new-password'


You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &


You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl


Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!



生成數據

[root@lamp mysql]# ll ./data

total 8

drwx------ 2 mysql root 4096 Dec  7 11:09 mysql

drwx------ 2 mysql root 4096 Dec  7 11:09 test




啓動數據庫


/usr/local/mysql/bin/mysqld_safe &



檢測

[root@lamp mysql]# ps -aux |grep mysqld |grep -v grep

Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ

root     22545  0.0  0.1 106100  1476 pts/1    S    11:47   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe

mysql    22653  0.7  2.6 269760 27240 pts/1    Sl   11:47   0:06 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/lamp.err --pid-file=/usr/local/mysql/data/lamp.pid --socket=/usr/local/mysql5.1.72/tmp/mysql.sock --port=3306



[root@lamp mysql]# lsof -i :3306

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld  22653 mysql   10u  IPv4 151886      0t0  TCP *:mysql (LISTEN)



安裝PHP

檢測apache和mysql

[root@lamp src]# netstat -lnptu |egrep "3306|80"

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      23167/mysqld        

tcp        0      0 :::80                       :::*                        LISTEN      5133/httpd          

tcp        0      0 :::8000                     :::*                        LISTEN      5133/httpd


檢測安裝所需的lib庫

安裝準備

yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y


tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install



解壓編譯


./configure \

--prefix=/usr/local/php5.3.27 \

--with-apxs2=/usr/local/apache/bin/apxs \   

是給apache添加模塊的dso模式添加,php嵌入到apache裏面

--with-mysql=/usr/local/mysql \

--with-xmlrpc \

--with-openssl \

--with-zlib \

--with-freetype-dir \

--with-gd \

--with-jpeg-dir \

--with-png-dir \

--with-iconv=/usr/local/libiconv \

--enable-short-tags \

--enable-sockets \

--enable-zend-multibyte \

--enable-soap \

--enable-mbstring \

--enable-static \

--enable-gd-native-ttf \

--with-curl \

--with-xsl \

--enable-ftp \

--with-libxml-dir




[root@Centos6 modules]# pwd

/usr/local/apache2/modules

[root@Centos6 modules]# ll

total 26220

-rw-r--r-- 1 root root     9083 Jun 29 16:10 httpd.exp

-rwxr-xr-x 1 root root 24594399 Jun 29 17:01 libphp5.so

有這兩個文件,說明apache已經嵌入了php


拷貝配置文件

[root@Centos6 local]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/lib/php.ini




配置apache解析php

打開apache主配置文件

定位311gg加下面這兩行

  AddType application/x-httpd-php .php.phtml

AddType application/x-httpd-php-source.phps

 AddType application/x-httpd-php .php


提示:這裏一定要配置,不然apahce解析不了php,一打開就下載的情況


然後改一下里面的用戶和組

#

User www

Group www


增加index.php

<IfModule dir_module>

    DirectoryIndex index.html index.php

</IfModule>



[root@Centos6 conf]# useradd -s /sbin/nologin -M www

檢測重啓apache

[root@Centos6 conf]# chown -R www.www /var/html/blog

[root@Centos6 conf]# cd /var/html/blog

[root@Centos6 conf]# vim index.php

<?php

phpinfo();

?>


瀏覽器測試php



測試mysql

vim mysql.php


<?php

$link_id=mysql_connect('localhost','root','123456') or mysql_error();


if($link_id){

echo "mysql successful by oldboy !";

}else{

echo mysql_error();

}

?>




到此lamp環境部署完成



本文出自 “比爾linux運維筆記” 博客,請務必保留此出處http://chenshoubiao.blog.51cto.com/6159058/1884102


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章