LAMP環境搭建之編譯安裝指南(php-5.3.27.tar.gz)

測試環境:CentOS release 6.5 (Final)php

軟件安裝:httpd-2.2.27.tar.gz   mysql-5.1.72.tar.gz   php-5.3.27.tar.gz html

一、mysql安裝詳見:https://www.cnblogs.com/su-root/p/11210794.htmlmysql

二、apache安裝詳見:https://www.cnblogs.com/su-root/p/11182549.html程序員

三、PHH安裝以下:算法

1、php安裝準備sql

①yum安裝php所依賴的包apache

[root@bqh-119 php]# yum -y install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

②檢測機器是否已經安裝好vim

[root@bqh-119 php]# rpm -qa zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel

③安裝libiconv-1.14.tar.gz  -----(https://excellmedia.dl.sourceforge.net/project/korwah/source/libiconv/libiconv-1.14.tar.gz)瀏覽器

 
 
[root@bqh-119 php]# tar zxf libiconv-1.14.tar.gz 
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install

④快速安裝libmcrypt擴展庫(epel源方法來安裝 安全

[root@bqh-119 yum.repos.d]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@bqh-119 yum.repos.d]#yum makecache
[root@bqh-119 yum.repos.d]# yum install libmcrypt-devel -y

⑤快速安裝mhash加密算法擴展庫

  Mhash是基於離散數學原理的不可逆向的php加密方式擴展庫,其在默認狀況下開啓,mhash的能夠用於場景檢驗數值,消息摘要,小小認證碼,以及無需原文的關鍵信息保存(如密碼)等。

  Mhash爲PHP提供了多種哈希算法,如MD5,SHA1,GOST等,你能夠經過MHASH_hashname()來查看支持的算法有哪些。

注意問題:該擴展不能提供最新的哈希算法;該擴展結果原則上運算不可逆。

[root@bqh-119 php]# yum install mhash mhash-devel -y

⑥快速安裝mcrypt加密擴展庫

  php程序員們在編寫程序時,除了要保證代碼的高性能以外,還有一點是很是重要的,那就是程序的安全性保障。php除了自帶的幾種加密函數外,還有功能更全面的php加密擴展庫mcrypt和mhash。其中,mcrypt擴展能夠實現加密解密功能,就是既能將明文密碼加

密,也能夠密文還原。mcrypt是php裏面重要的加密支持擴扎庫,該庫在默認狀況下不開啓。編輯本段支持的算法和加密模式:mcrypt庫支持20多種加密算法和8中加密模式,具體能夠經過函數crypt_list_algorithms()和mcrypt_list_modes()來顯示。

[root@bqh-119 php]# yum install mcrypt -y

⑦安裝libxslt-devel

[root@bqh-119 php]# yum -y install libxslt-devel

 以上安裝php依賴包就ok了。

2、開始安裝PHP服務

 ①下載php-5.3.27.tar.gz 並解壓。 

下載php:https://www.php.net/distributions/php-5.3.27.tar.gz

[root@bqh-119 php]# tar xf php-5.3.27.tar.gz

②編譯安裝PHP

[root@bqh-119 php-5.3.27]# cd php-5.3.27
[root@bqh-119 php-5.3.27]# ./configure \ --prefix=/application/php5.3.27 \ #指定php的安裝路徑 --with-apxs2=/application/apache/bin/apxs \ #指定apache的bin/apxs路徑,經過apxs來增長php擴展模塊到apache中 --with-mysql=/application/mysql \ #指定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-mbstring \ --enable-static \ --enable-gd-native-ttf \ --with-curl \ --with-xsl \ --enable-ftp \ --with-libxml-dir

 執行上邊命令後效果以下:

③接着執行:

[root@bqh-119 php-5.3.27]# make && make install  #安裝php生成文件至系統

.....
.........以上省略
/root/tools/php-5.3.27/build/shtool install -c ext/phar/phar.phar /application/php5.3.27/bin
ln -s -f /application/php5.3.27/bin/phar.phar /application/php5.3.27/bin/phar
Installing PDO headers:          /application/php5.3.27/include/php/ext/pdo/
[root@bqh-119 php-5.3.27]# echo $?
0

④設置軟鏈接安全方便訪問:

[root@bqh-119 php-5.3.27]# ln -s /application/php5.3.27/ /application/php
[root@bqh-119 php-5.3.27]# ll /application/php
lrwxrwxrwx 1 root root 23 7月  19 03:08 /application/php -> /application/php5.3.27/

⑤安裝php服務後,咱們看一下apache下的模塊路徑及httpd.conf配置文件中切入了libphp5.so

[root@bqh-119 php-5.3.27]# ll /application/apache/modules/
總用量 27824
-rw-r--r-- 1 root root     9115 7月  13 23:26 httpd.exp
-rwxr-xr-x 1 root root 28479402 7月  19 03:02 libphp5.so #經過apxs來增長php擴展模塊到apache中
[root@bqh-119 php-5.3.27]# grep libphp5 /application/apache/conf/httpd.conf
LoadModule php5_module        modules/libphp5.so

注:當用戶訪問apache時,如何是靜態文件,自身解析處理;若是是動態文件,交給php模塊解析處理

⑥拷貝php配置文件到php默認目錄下並改名爲php.ini

[root@bqh-119 php-5.3.27]# ll php.ini-*
-rw-r--r-- 1 101 101 69606 7月  11 2013 php.ini-development   #開發
-rw-r--r-- 1 101 101 69627 7月  11 2013 php.ini-production    #生產
[root@bqh-119 php-5.3.27]# cp php.ini-production /application/php/lib/php.ini

⑦修改apache主配置文件httpd.conf,解決FQDN:

[root@bqh-119 apache]# sed -i 's#\#ServerName www.example.com:80#ServerName 127.0.0.1:80#g' ./conf/httpd.conf
[root@bqh-119 apache]# grep ServerName ./conf/httpd.conf
# ServerName gives the name and port that the server uses to identify itself.
ServerName 127.0.0.1:80

⑧配置apache支持php:在主配置文件httpd.conf第311行後添加下面兩行便可:

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

修改damon用戶爲bqh:

若是不存在bqh用戶,配置好文件後,須要建立bqh用戶。

注:這個damon用戶不是必須修改的,通常狀況咱們是須要修改用戶的,更改默認用戶是爲了安全考慮。

修改默認的首頁文件,例如增長一個index.php:

保存配置後可用diff比對一下:

建立用戶:

[root@bqh-119 conf]# id bqh
id: bqh:無此用戶
[root@bqh-119 conf]# groupadd bqh
[root@bqh-119 conf]# useradd bqh -s /sbin/nologin -M -g bqh 
[root@bqh-119 conf]# id bqh
uid=503(bqh) gid=503(bqh) 組=503(bqh)

⑨測試php

配置apache主配置文件httpd.conf

[root@bqh-119 extra]# cat httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin 1147076062@qq.com
    DocumentRoot "/var/html"
    ServerName test_phpinfo.php
    ServerAlias index.php
    ErrorLog "logs/php-error_log"
    CustomLog "|/usr/local/sbin/cronolog /application/apache/logs/access_php_%Y%m%d.log" combined
</VirtualHost>

注:

  1. 以上基於前文的基於域名的虛擬主機上基礎上配置的,詳情至:http://www.javashuo.com/article/p-anbexyah-bk.html
  2. 以上日誌輪詢是採用的cronolog,詳情至:http://www.javashuo.com/article/p-ttxlmjmb-cb.html
  3. 固然也能夠不建立虛擬主機,直接在默認的配置文件、站點目錄下配置也行ok。

在新建的/var/html/站點目錄下寫一個test_phpinfo.php代碼測試php

[root@bqh-119 html]# cat test_phpinfo.php 
<?php
   phpinfo();
?>

⑩刷新配置,打開瀏覽器輸入地址結果看是否成功。

[root@bqh-119 extra]# /application/apache/bin/apachectl -t
Syntax OK
[root@bqh-119 extra]# /application/apache/bin/apachectl graceful

http://192.168.0.118/test_phpinfo.php

咱們再看看日誌:

[root@bqh-119 extra]# tail -2 /application/apache/logs/access_php_20190720.log 
192.168.0.110 - - [20/Jul/2019:12:52:02 +0800] "GET /test_phpinfo.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2146 "http://192.168.0.119/test_phpinfo.php" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0"
192.168.0.110 - - [20/Jul/2019:12:52:02 +0800] "GET /test_phpinfo.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.1" 200 2524 "http://192.168.0.119/test_phpinfo.php" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0"

ok,目前Apache到php已經通了,下面咱們須要測試php到mysql是否通。

在站點/var/html/目錄下再寫一個test_mysql.php代碼測試php

[root@bqh-119 html]# vim test_mysql.php
[root@bqh-119 html]# cat test_mysql.php 
<?php
$link_id=mysql_connect('localhost','root','bqh123') or mysql_error();
if($link_id) {
   echo "MySQL connection succeeded!";
  }
else {
   echo mysql_error();
  }
?>

瀏覽器輸入地址:http://192.168.0.119/test_mysql.php

ok測試沒有問題。

假如咱們把mysql密碼改了,咱們再來測試一下效果:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

到此爲止,Apache→php→mysql測試已通; LAMP環境搭建ok。 

相關文章
相關標籤/搜索