LAMP編譯安裝

一、介紹

L指的是Linux
A是Apache
M爲Mysql或者Mariadb
P爲Php,Pyton或者perl
WEB資源類型: 
        靜態資源:原始形式與響應內容一致
        動態資源:原始形式通常爲程序文件,需要在服務器端執 
web服務器通過發起請求的後綴來判斷,如果是靜態的資源就由web服務器自行處理,到磁盤上找到數據後構建相應報文,然後發送給客戶端。

如果是動態這時web服務器會將請求轉發給php。這裏分爲兩種情況:
一種爲php以模塊的方式集成在httpd中,httpd通過cgi協議和php模塊連接。這中間的過程就是httpd服務針對每個有客戶端請求生成一個進程,然後進程生成一個cgi子進程,子進程負責和後邊的php模塊的連接,php模塊執行程序,如果需要用到數據,就會作爲客戶端通過mysql協議連接mysql數據庫服務端,獲取數據並處理,處理完成後的數據成爲靜態的資源,再通過httpd服務傳給客戶端瀏覽器。
另一種情況如果是php會安裝一個名爲php-fpm的單獨的服務,httpd轉發請求時服務就相當於是php-fpm的客戶端,通過FastCgi協議和php-fpm服務端連接。之後的步驟就和上面一樣了。

CGI:Common Gateway Interface 可以讓一個客戶端,從網頁瀏覽器通過http服務器向執行在 網絡服務器上的程序傳輸數據;CGI描述了客戶端和服務器程 序之間傳輸的一種標準 

LAMP編譯安裝

二、編譯安裝過程

環境如下:
系統:centos7.4
mairadb:通用二進制格式,mariadb-10.2.14
httpd:編譯安裝,httpd-2.4.29 
php5:編譯安裝,php-7.1.7
phpMyAdmin:安裝phpMyAdmin-4.8.0.1-all-languages 
Xcache:編譯安裝xcache-3.2.0
php5.4依賴於mariadb-devel包 
順序:httpd--mariadb-->php

1、安裝依賴的工具包組

yum -y groupinstall "Development tools"
yum -y install pcre-devel openssl-devel
./configure 之後有提示未裝的包,根據提示yum安裝即可。

 2、準備軟件包

 APR(Apache portable Run-time libraries,Apache可移植運行庫)的目的如其名稱一樣,主要爲上層的應用程序提供一個可以跨越多操作系統平臺使用的底層支持接口庫。在早期 的Apache版本中,應用程序本身必須能夠處理各種具體操作系統平臺的細節,並針對不同的平臺調用不同的處理函數。

隨着Apache的進一步開 發,Apache組織決定將這些通用的函數獨立出來並發展成爲一個新的項目。這樣,APR的開發就從Apache中獨立出來,Apache僅僅是使用 APR而已。目前APR主要還是由Apache使用,不過由於APR的較好的移植性,因此一些需要進行移植的C程序也開始使用APR,開源項目比如 Flood 

[root@localhost ~/src]$ls
apr-1.6.2.tar.gz       mariadb-10.2.14-linux-x86_64.tar.gz  xcache-3.2.0.tar.gz
apr-util-1.6.0.tar.gz  php-7.1.17.tar.bz2
httpd-2.4.29.tar.bz2   wordpress-4.9.4-zh_CN.tar.gz

3、開始編譯httpd.2.4.29

mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
此步驟可省略編譯apache時再設置路徑--with-included-apr
mkdir /app/httpd2429
/configure --prefix=/app/httpd2429 --enable-so --
enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install
vim /etc/profile.d/httpd2429.sh   /etc/profile是永久性的環境變量,是全局變量,/etc/profile.d/設置所有  用戶生效.以後啓動時直接用apachectl start 即可
export PATH=/app/httpd2429/bin:$PATH
. /etc/profile.d/httpd2429.sh

LAMP編譯安裝

4、二進制安裝數據庫

tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local/    (也可參考我的上篇博客)
解包時可不放在/usr/local/下,但一會創建軟連接一定要放在這下邊!要不會麻煩死 各種腳本都要調。
ln -s mariadb-10.2.14-linux-x86_64/ mysql
useradd -r -m -d /app/mysqldb -u 27 -s /sbin/nologin mysql  創建mysql用戶
[root@localhost /usr/local/mysql]#scripts/mysql_install_db --datadir=/app/mysqldb --us
er=mysql
[root@localhost /usr/local/mysql]$ cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld

添加啓動腳本
[root@localhost /usr/local/mysql]$vim /etc/profile.d/httpd2429.sh 
export PATH=/usr/local/mysql/bin:/app/httpd2429/bin:$PATH
. /etc/profile.d/httpd2429.sh

systemctl start mysqld
ss -tnl
設置權限
mysql_secure_installation   這個一定要設置!!
mysql -uroot -pcentos
grant all on *.* to jin@'172.18.%.%' identified by "centos";

MariaDB [(none)]> create database wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> gran all on wpdb.* to wpuser@'127.%' identified by 'centos';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corres
ponds to your MariaDB server version for the right syntax to use near 'gran all on wpdb.* to wpuser@'127.%' identified by 'centos'' at line 1MariaDB [(none)]> grant all on wpdb.* to wpuser@'127.%' identified by 'centos';
Query OK, 0 rows affected (0.04 sec)

MariaDB [(none)]> grant all on wpdb.* to wpuser@'172.18.%.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on wpdb.* to wpuser@'localhost' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

5、編譯安裝php

/root/src/   tar xvf  php-7.1.7.tar.bz2 
yum install -y libxml2-devel libmcrypt-devel   #libmcrypt-devel  來自epel源
./configure --prefix=/app/php --enable-mysqlnd  --with-mysqli=mysqlnd   --with-openssl --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd2429/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
make -j 4 && make install
編譯安裝一定要看仔細 了!!我在這裏出了不少問題。
[root@localhost ~/src/php-7.1.17]$cp php.ini-production /etc/php.ini
vim /app/httpd24/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

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



LAMP編譯安裝


LAMP編譯安裝

vim index.php
<html><body><h1> Lamp it works!</h1></body></html>
<?php
$mysqli=new mysqli("127.0.0.1","root","centos");
if(mysqli_connect_errno()){
echo "連接數據庫失敗!";
$mysqli=null;
exit;
}
echo "連接數據庫成功!";
$mysqli->close();
phpinfo();
?>
[root@localhost ~]$ps aux |grep php
root 107589 0.0 0.0 112704 964 pts/2 S+ 21:45 0:00 grep --color=auto ph
p

LAMP編譯安裝

  
LAMP編譯安裝


6、安裝wordpress


tar xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd2429/htdocs
ln -s wordpress/ blog
cd blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
define('DB_NAME', 'wpdb');

/** MySQL數據庫用戶名 */
define('DB_USER', 'wpuser');

/** MySQL數據庫密碼 */
define('DB_PASSWORD', 'centos');![]


LAMP編譯安裝



LAMP編譯安裝


ab -c -n 1000 http://URL

LAMP編譯安裝






6、安裝php-xcache

tar xvf xcache-3.2.0.tar.bz2
[root@localhost ~/src/xcache-3.2.0]$/app/php/bin/phpize 
[root@localhost ~/src/xcache-3.2.0]$./configure --enable-xcache --with-php-config=/app
/php/bin/php-config
make && make install
之後會出現一個路徑,複製下來!如下面第一個圖。
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
這裏在“extension”後面複製剛纔那個路徑
[root@lamp xcache-3.2.0]# /etc/init.d/php-fpm restart
apachetcl restart
ab -c10 -n 1000 URL://

  
注意:查了谷歌xache經過測試極大可能是不支持php7以上,此次編譯環境php較新,大家可拿php5.6測試。(博主已經累了,這個折騰了很久。0.0)
LAMP編譯安裝

LAMP編譯安裝

[root@localhost ~/src/xcache-3.2.0]$ab -c 10 -n 1000 http://172.18.252.35/blog/

加速前


LAMP編譯安裝

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