服務器之07源碼安裝LAMPMX(同臺主機)


本次APACHE  PHP   MYSQL 在同一臺主機的編譯安裝


源碼安裝Linux6.6 +Apache2.4 +Mysql5.5+Php5.4+phpMyAdmin4.0 + Xcache3.0爲PHP加速


Apache2.4與Php5.4通信是 modules的方式



111111111111111111111111111111111111111111111111111111111111111111

11111111111111111                           1111111111111111111111

11111111111111111         編譯APACHE        1111111111111111111111

11111111111111111    1111111111111111111111

111111111111111111111111111111111111111111111111111111111111111111


安裝環境搭建:


yum groupinstall "Development tools"  安裝開發包組

yum groupinstall "Server Platform Development" 安裝開發包組


如果不想編譯pcre那麼

yum -y install pcre-devel libzip-devel

編譯時要指定 --with-pcre 即可



apr->apr-util->pcre--->httpd


更新時間:

hwclock -s


tar xf apr-1.5.2.tar.gz

cd apr-1.5.2


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

make && make install

cd ..


--------------------------------

在執行configure可能會出現

rm: cannot remove `libtoolT': No such file or directory錯誤信息。

--------------------------------

解決方法:

提示編輯configure這個文件,將 $RM "$cfgfile" 那行註釋掉 ,然後重新編譯即可。

--------------------------------


tar xf apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

cd ..


tar xf pcre-8.37.tar.gz 

cd pcre-8.37

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

make && make install

cd..


tar xf httpd-2.4.16.tar.gz

cd httpd-2.4.16


 ./configure --prefix=/usr/local/apache \

--sysconfdir=/etc/httpd24 \

--enable-so \

--enable-cgi \

--enable-cgid \

--enable-rewrite \

--enable-ssl \

--with-zlib \

--with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre \

--enable-modules=most \

--enable-mpms-shared=all \

--with-mpm=event 







make && make install

cd..



重要選項說明:

--perfix=/usr/local/apache    指定安裝目錄

--sysconfdir=/etc/httpd24     指定配置文件目錄


--enable-so 啓用 支持基於DSO動態共享模塊 (必要)

--enable--ssl 啓用支持加密訪問https(必要)

--enable-rewirte 啓用 支持URL重寫(必要)

--enable-cgi 啓用 支持CGI腳本

--enable-cgid 啓用支持帶線程CGI腳本 MPMs(如果選event那麼就必須要有cgid)


--enable-modules=most 啓用常用共享模塊(動態)(必要)

--enable-mpms-shared=all 啓用MPM支持全部多道處理方式3種(prefork worker event)


--with-event 指定prefork worker event的其中一個爲默認啓用

--with-zlib  調用庫 (必要)

--with-apr=/usr/local/apr  指定APR路徑(必要)

--with-apr=/usr/local/apr-util 指定APR-UTIL路徑(必要)

--with-pcre=/usr/local/pcre 指定pcre庫路徑(必要)



httpd2.4新特性

        1)MPM支持在運行時裝載

              --enable-mpms-shared=all 並設定默認的啓用的MPM  --with-mpm=event

2) 支持event

3)異步讀寫

4) 在每模塊及每目錄上指定日誌級別

5)每請求配置:<If> <Elseif>

6) 增強版的表達式分析器

7) 毫秒級的keepalive timeout

8)支持主機名的虛擬主機不在需要NameVirtualHost指令

9) 支持使用自定義變量

       

新增一些模塊: mod_proxy_fcgi 和PHP交互用fastCGI

mod_ratelimit 速率限定

mod_request 對請求方法限定

mod_remoteip 對遠端IP最限制

對於基於IP的訪問做了修改,統一使用require進行





後續的配置:

0產看 HTTP運行模式 prefork worker event

#/usr/local/apache/bin/httpd -l  看不到了

#/usr/local/apache/bin/apachectl -l 看不到了

環境變量裏面沒有

cp /usr/local/apache/bin/apachectl /usr/local/bin/httpd24

可以用了  httpd24 -V 版本 -M 模塊  -l


1導出頭文件(開發)纔用到

    # ln -sv /usr/local/apache/include  /usr/include/httpd


2配置文件並且定義Pid文件的路徑

# vim /etc/httpd24/httpd.conf 

 添加 PidFile  "/var/run/httpd/httpd.pid"

 

去掉#號ServerName 192.168.1.202:80


具體可以自己設置虛擬主機

訪問控制等


3導出man手冊

# vim /etc/man.config

        MANPATH /usr/local/apache/man

4輸出二進制程序

 

        # echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd24.sh

. /etc/profile.d/httpd24.sh

5提供服務腳本 

1 cp /usr/local/apache/bin/apachectl  /etc/rc.d/init.d/httpd24 

(24用於區分httpd)

2vim /etc/rc.d/init.d/httpd24

  在開頭的#!/bin/sh  下面加上

              #chkconfig: 2345  85  15



3權限與檢測

chmod +x /etc/init.d/httpd24 給執行權限

chkconfig --add httpd24 加入系統自啓動

chkconfig --list | grep httpd24 看看是否看機啓動ON OFF

service httpd24 start 啓動HTTP服務

netstat -tunlp 檢測端口是否開啓

top 看是否httpd 進程USER是daemon



222222222222222222222222222222222222222222222222222222222222222222222222

22222222222222222222   222222222222222222222

22222222222222222222    通用二進制格式安裝MYSQL    222222222222222222222

22222222222222222222   222222222222222222222

222222222222222222222222222222222222222222222222222222222222222222222222


安裝依賴包yum install wget gcc gcc-c++ make cmake ncurses-devel libtool zilib-devel automake perl libncurses5-dev kdelibs_dev kdelib


第一步:


1解壓到USR/LOCAL目錄(通用二進制必須路徑)

tar xf mysql-5.5.TAB鍵 -C /usr/local 

2創建MYSQL組(安全)

groupadd -r mysql

3創建MYSQL用戶並不登錄(安全)

useradd -g mysql -r -s /sbin/nologin mysql

4驗證一下

id mysql

uid=499(mysql) gid=498(mysql) 組=498(mysql)

5進入目錄並創建軟鏈接

cd /usr/local

ln -sv mysql-5.5.40-linux2.6-x86_64 mysql

6進入目錄:

cd /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql/*



第二步:實現規劃好MYSQL的數據板寸目錄(最好是RIND下的LVM上 開機掛載 )

假設已經是LVM了掛載點爲 /data  目錄下創建目錄mysqldata 

/data/mysqldata 這個目錄要改屬主屬組(目的是讓MYSQL進程有權限寫等)

# chown -R mysql.mysql /data/mysqldata


chown -R mysql.mysql /usr/local/mysql/data

chmod -R 755 /usr/local/mysql/data


1執行數據庫初始化腳本

cd /usr/local/mysql

scripts/mysql_install_db --user=mysql


--basedir 安裝目錄

--datadir  數據目錄

--defaults-extra-file 額外文件的目錄(安裝文件)

--user 運行用戶


2把/usr/local/mysql目錄下所有文件屬主改成ROOT

chown -R root ./*



3拷貝啓動腳本到init.d目錄,加入service服務控制,查看開機啓動

cp support-files/mysql.server /etc/rc.d/init.d/mysqld

chkconfig --add mysqld 

chkconfig --list mysqld


4拷貝配置文件:

cp support-files/my-large.cnf /etc/my.cnf   512M內存

cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf 4 G 內存

vim /etc/my.cnf


如果你改了MYSQL的數據目錄位置)

datadir=路徑

thread_concurrency = 4 是CPU物理核心的2倍


5 啓動並測試

service mysqld start

ss -ntl   看3306端口


6 客戶端連接

/usr/local/mysql/bin下有命令把他加入環境變量

vim /etc/profile.d/mysql.sh

內容 export PATH=/usr/local/mysql/bin:$PATH

讀一下這個文件

. /etc/profile.d/mysql.sh


7 初次登錄mysql給ROOT加入密碼刪除危險用戶:

#mysql

mysql>  

1刪危險用戶:

use mysql;  把MYSQL設置爲默認庫

SHOW Databases;  看有幾個庫

SHOW TABLES; 看默認庫中有多少表

DESC user; 看USER表

SELECT User,Host,Password FROM user;看USER表的幾個字段

DROP User ''@'localhost';

DROP User ''@'tset.centos';



2加密碼(安全)分別加也可以一起加密碼:


SET PASSWORD FOR 'root'@'localhost' = PASSWORD('litao_59');

SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('litao_59');

SET PASSWORD FOR 'root'@'主機名' = PASSWORD('litao_59');

SET PASSWORD FOR 'root'@'::1' = PASSWORD('litao_59');

或者

UPDATE user SET password=PASSWORD('litao_59') WHERE user='root';


flush privileges;  通知mysql重讀授權表讓授權立即生效


3root 用戶方便自己登陸的配置

cd ~  回家

vim .my.cnf

[mysql]

user = root

host = localhost

password = litao_59


4導出頭文件庫文件

ln -sv /usr/local/mysql/include/ /usr/include/mysql  頭文件

vim /etc/ld.so.conf.d/mysql.conf  建立庫文件配置文件

   輸入/usr/local/mysql/lib

ldconfig  讀一下MYSQL庫

ldconfig -p | grep mysql 查看

        libmysqlclient.so.18  有他就好


5給某些用戶授權:


CREATE DATABASE taodb;   創建taodb數據庫

GRANT ALL PRIVILEGES ON taodb.* TO 'tao'@'localhost' IDENTIFIED BY'litao_59';


權限所有 把taodb數據庫授權給用戶tao登錄範圍localhost (php的IP) 登錄密碼litao_59


flush privileges;  通知mysql重讀授權表讓授權立即生效





------------------------

完畢 service mysqld restart

------------------------




3333333333222223333333333333333333333333333333333333333333333333333

3333333333332222233333 333333333333333333333333333

3333333322223333333333    編譯 PHP5.4   333333333333333333333333333

3333333333332222233333 333333333333333333333333333

3333333333332222233333333333333333333333333333333333333333333333333


編譯前安裝需要圖形開發包組:

yum groupinstall 'Server Platform Development'


libmcrypt擴展及其壓縮:

yum -y install libmcrypt-devel bzip2-devel




-------PHP編譯------------

tar xf php-5.4.25.tar.gz

cd php-5.4.25



二、FastCGI方式結合


./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file--scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts







./configure --prefix=/usr/local/php 指定目錄

--with-mysql=/usr/local/mysql 如果是RPM包安裝的MYSQL直接用--with-mysql 要裝mysql-devel

--with-openssl  支持SSL

--with-mysqli=/usr/local/mysql/bin/mysql_config  通信機制要找到/usr/local/mysql/bin/mysql_config藉口

--enable-mbstring  多字節字串

--with-freetype-dir 支持freetype字體解析工具

--with-jpeg-dir 圖片

--with-png-dir 圖片

--with-zlib  壓縮庫

--enable-xml  支持xml

--with-libxml-dir=/usr    到哪裏找xml

--enable-sockets 支持sokets通信

--with-apxs2=/usr/local/apache/bin/apxs  找apache2 的 apxs文件

--with-mcrypt 

--with-config-file-path=/etc  配置文件php.ini路徑

--with-config-file-scan-dir=/etc/php.d  掃描路徑下當做配置文件

--with-bz2  支持壓縮

--enable-maintainer-zts 支持





看到--------------沒錯什麼錯誤--------------------

config.status: creating php5.spec

config.status: creating main/build-defs.h

config.status: creating scripts/phpize

config.status: creating scripts/man1/phpize.1

config.status: creating scripts/php-config

config.status: creating scripts/man1/php-config.1

config.status: creating sapi/cli/php.1

config.status: creating sapi/cgi/php-cgi.1

config.status: creating ext/phar/phar.1

config.status: creating ext/phar/phar.phar.1

config.status: creating main/php_config.h

config.status: executing default commands


看到--------------------make-----------------------

clicommand.inc

invertedregexiterator.inc

directorygraphiterator.inc

directorytreeiterator.inc

pharcommand.inc

phar.inc


Build complete.

Don't forget to run 'make test'. 


看到-----------------make install------------------


[PEAR] Archive_Tar    - installed: 1.3.12

[PEAR] Console_Getopt - installed: 1.3.1

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util       - installed: 1.2.3

[PEAR] PEAR           - installed: 1.9.5

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

/root/php-5.4.25/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Installing PDO headers:          /usr/local/php/include/php/ext/pdo/


-成功-----------------------------------------------



2設置PHP的配置文件:

cd 源碼包裏

cp php.ini-production /etc/php.ini


3 編輯Apache支持PHP 

vim /etc/httpd24/httpd.conf

增加:

250行     DirectoryIndex index.php index.html


379行     AddType application/x-httpd-php .php

380行     AddType application/x-httpd-source .phps


4 驗證Apache與PHP

rm -rf /usr/local/apache/htdocs/index.html

vim /usr/local/apache/htdocs/index.php

<?php

phpinfo();

?>


5 驗證PHP能否鏈接MYSQL


vim /usr/local/apache/htdocs/index.php

-------------------------------------

<?php

$link=mysql_connect('localhost','tao','litao_59');

        if ($link)

echo "php-mysql_link_OKKKKKKKKKKKK";

        else

echo "php-mysql_link_NOOOOOOOOOOOO";


          mysql_close();

?>


------------------------------------

service httpd24 restart 顯示php-mysql_link_OKKKKKKKKKKKK成功




4444444444444444444444444444444444444444444444444444444444444444444444

444444444444444444444444                     4444444444444444444444444

444444444444444444444444     phpMyAdmin      4444444444444444444444444

444444444444444444444444                     4444444444444444444444444

4444444444444444444444444444444444444444444444444444444444444444444444



rm -rf /usr/local/apache/htdocs/index.php


tar xf phpMyAdmin-4.0.10.10-all-languages.tar.gz 


mv phpMyAdmin-4.0.10.10 /usr/local/apache/htdocs/pma


測試:

訪問192.168.1.201/pma OK


---------------------------------------------

#cd /usr/local/apache/bin/

測試: 你的LAMP服務器 ab 命令(可以慢慢增大併發數)-c (併發數)-n (請求個數)

#./ab -c 10 -n 100 http://192.168.1.201/pma/index.php

關鍵看:

Requests per second:    20.84 [#/sec] (mean)  每秒鐘所完成的請求數

Time per request:       47.996 [ms] (mean)   完成每個請求消耗的時間


---------------------------------------------



555555555555555555555555555555555555555555555555555555555555555555555

55555555555555555555 55555555555555555555555555555

55555555555555555555  Xcache 55555555555555555555555555555

55555555555555555555 55555555555555555555555555555

555555555555555555555555555555555555555555555555555555555555555555555


tar xf xcache-3.1.2.tar.gz

cd xcache-3.1.2


phpize 編譯PHP第三方擴展


/usr/local/php/bin/phpize

Configuring for:

PHP Api Version:         20100412

Zend Module Api No:      20100525

Zend Extension Api No:   220100525


./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config


顯示:

appending configuration tag "CXX" to libtool

configure: creating ./config.status

config.status: creating config.h


make && make install顯示:

Build complete.

Don't forget to run 'make test'.

Installing shared extensions: 

/usr/local/php/lib/php/extensions/no-debug-zts-20100525/複製這行


mkdir /etc/php.d

cp xcache.ini /etc/php.d/

vim /etc/php.d/xcache.ini

關鍵看這個:使用多少內存來存緩存

xcache.size  =  60M  

extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so


提供測試頁:

vim /usr/local/apache/htdocs/index.php

<?php

$link=mysql_connect('localhost','tao','litao_59');

        if ($link)

echo "php-mysql_link_OKKKKKKKKKKKK";

        else

echo "php-mysql_link_NOOOOOOOOOOOO";


          mysql_close();

phpinfo();

?>



重啓apache

service httpd24 restart


訪問 http://192.168.1.201   找到下面的字樣即可

XCache

XCache Version  3.1.2  

Modules Built  cacher  


一般來shuo,啓動XCache的PHP 速度要快3倍


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