本身編寫的:centos6.6上編譯安裝apache2.4+php5.6+mysql5.6【親自】

在centos6.6上安裝apache2.4+php5.6+mysql5.6php

 

關於wget的安裝

將以前裝系統的.iso文件掛載到光驅html

 

因爲我在/home/jinnan/下創建了一個cdrom文件夾mysql

 

Shell>#mount /dev/cdrom  /home/jinnan/cdromnginx

 

Shell># cd /home/jinnan/cdromc++

 

Shell># lsgit

 

Shell># cd Packagesgithub

 

Shell>#ls | grep wgetsql

 

Shell># rpm -ivh wget-1.12-5.el6.x86_64.rpmshell

 

測試wget可否下載文件數據庫

 

Shell># wget https://cmake.org/files/v2.8/cmake-2.8.2.tar.gz

 

 

依賴軟件查詢:http://rpmfind.net

 

 

關於lamp環境安裝的須要軟件的下載地址:

freetype:    https://www.freetype.org/

 

libxml2:     http://xmlsoft.org/sources/

 

jpegsrc:      http://www.ijg.org

 

libpng:      http://www.libpng.org/pub/png/libpng.html

 

zlib:          http://zlib.net/

 

libgd:          https://libgd.github.io/

 

php:          http://php.net/downloads.php

 

apache:          http://httpd.apache.org/download.cgi

 

apr / apr-util:      http://apr.apache.org/download.cgi

 

pcre:         http://www.pcre.org/

 

cmake:          https://cmake.org/files/

 

mysql:國內鏡像站下載:http://mirrors.sohu.com/mysql/

           臺灣鏡像站: http://ftp.ntu.edu.tw/MySQL/Downloads/

           官方下載:    http://www.mysql.com

 

怎樣從Mysql官網下載mysql.tar.gz版本的安裝包:http://blog.csdn.net/u012453843/article/details/52876462

【若是壓縮包爲.tar.bz2,那麼解壓命令爲 tar jxvf  ****.tar.bz2】

 

安裝gcc:

安裝gcc的時候gcc的幾個依賴關係以下,lib【是library的縮寫】,好比libppl,ppl表明的是包名或軟件名

gcc

         cloog-ppl

                   ppl(libppl.so.7/libppl_c.so.2)

         cpp

                   mpfr(libmpfr.so.1)

gcc-c++

         libstdc++-devel

================================================================

 

 

apr安裝【apr-1.6.2.tar.gz】

 

shell>#tar zxvf apr-1.6.2.tar.gz

 

shell>#cd apr-1.6.2

 

shell>#./configure --prefix=/usr/local/apr1.6

 

shell>#make && make install

 

安裝apr-util:【 apr-util-1.5.4.tar.gz】

 

shell>#tar zxvf apr-util-1.5.4.tar.gz

 

shell>#cd apr-util-1.5.4

 

 

shell>#./configure --prefix=/usr/local/apr-util1.4 \

         --with-apr=/usr/local/apr1.6/

 

shell>#make && make install

 

=============================================================

安裝pcre:【 pcre-8.34.tar.gz】

 

 shell>#./configure --prefix=/usr/local/pcre

 

 shell>#make && make install

 

==========================================================

安裝apache2.4【httpd-2.4.27.tar.gz】

 

 shell>#tar zxvf httpd-2.4.27.tar.gz

 

 shell>#cd httpd-2.4.27

 

shell>#./configure --prefix=/usr/local/apache2.4 \

         --with-apr=/usr/local/apr1.6 \

         --with-apr-util=/usr/local/apr-util1.4 \

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

         --enable-modules=all \

         --enable-mods-shared=all \

         --enable-so \

         --enable-rewrite

 

安裝zlib【zlib-1.2.11.tar.gz】

shell>#tar zxvf zlib-1.2.11.tar.gz

 

shell>#cd zlib-1.2.11

 

shell>#./configure

shell>#make && make install

============================================================

 

安裝libxml2【libxml2-2.7.3.tar.gz】

 

shell>#tar zxvf libxml2-2.7.3.tar.gz

 

shell>#cd libxml2-2.7.3

 

shell>#./configure --prefix=/usr/local/libxml2  \

         --without-zlib

 

shell>#make && make install

=========================================================

安裝jpeg【jpegsrc.v9b.tar.gz】

 

shell>#tar zxvf jpegsrc.v9b.tar.gz

 

shell>#cd jpegsrc.v9b

 

shell>#./configure --prefix=/usr/local/jpeg \

         --enable-shared --enable-static

 

make && make install

==================================================

安裝libpng【libpng-1.6.30.tar.gz】

shell>#tar zxvf libpng-1.6.30.tar.gz

 

shell>#cd libpng-1.6.30

 

shell>#./configure --prefix=/usr/local/png  \

         --enable-shared --enable-static

 

 

shell>#make  && make install

==========================================================

安裝字體庫freetype【freetype-2.5.5.tar.gz】

 

shell>#tar zxvf freetype-2.5.5.tar.gz

 

shell>#cd freetype-2.5.5

 

shell>#./configure --prefix=/usr/local/freetype

 

 

shell>#make && make install

 

===============================================

 

安裝libgd【libgd-2.1.1.tar.gz】

【本人安裝php的時候出現一個錯誤,沒法找到一個關於gd的一個文件】,所以在裝gd的時候不要指定安裝目錄

 

shell>#tar zxvf libgd-2.1.1.tar.gz

 

shell>#cd libgd-2.1.1

 

 

shell>#./configure --with-jpeg=/usr/local/jpeg/ \

         --with-png=/usr/local/png/ \

         --with-zlib \

         --with-freetype=/usr/local/freetype

 

 

shell>#make && make install

 

==========================================================

 

安裝php5.6:【php-5.6.31.tar.gz】

 

shell>#tar zxvf php-5.6.31.tar.gz

 

shell>#cd php-5.6.31

 

 

shell>#./configure --prefix=/usr/local/php5.6 \

         --with-apxs2=/usr/local/apache2.4/bin/apxs \

         --with-mysql=mysqlnd \

         --with-pdo-mysql=mysqlnd \

         --with-mysqli=mysqlnd \

         --with-freetype-dir=/usr/local/freetype \

         --with-gd \

         --with-zlib --with-libxml-dir=/usr/local/libxml2 \

         --with-jpeg-dir=/usr/local/jpeg \

         --with-png-dir=/usr/local/png \

         --enable-mbstring=all \

         --enable-mbregex \

         --enable-shared

 

 

 

shell>#make  &&  make install

 

 

shell>#cp php.ini-development /usr/local/php5.6/lib/php.ini

 

=============================================

 

配置Apache使其支持php

vi /usr/local/apache2.4/conf/httpd.conf

1)      在httpd.conf(Apache主配置文件)中增長:

AddType application/x-httpd-php .php   

 

2)      找到下面這段話:

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

在index.html 前面添加index.php

nginx 的安裝

 

下載地址: http://nginx.org/download/nginx-1.4.2.tar.gz

安裝準備: nginx依賴於pcre庫,要先安裝pcre

shell># yum install pcre pcre-devel

shell># cd /usr/local/src/

shell># wget http://nginx.org/download/nginx-1.4.2.tar.gz

shell># tar zxvf nginx-1.4.2.tar.gz

shell># cd nginx-1.4.2

shell># ./configure --prefix=/usr/local/nginx

shell># make && make install

 

nginx+php的編譯

apache通常是把php當作本身的一個模塊來啓動的.

而nginx則是把http請求變量(如get,user_agent等)轉發給 php進程,即php獨立進程,與nginx進行通訊. 稱爲 fastcgi運行方式.

所以,爲apache所編譯的php,是不能用於nginx的.

 

注意: 咱們編譯的PHP 要有以下功能:

鏈接mysql, gd, ttf, 以fpm(fascgi)方式運行

老師編譯php的參數(未親測):

shell># ./configure  --prefix=/usr/local/fastphp \

--with-mysql=mysqlnd \

--enable-mysqlnd \

--with-gd \

--enable-gd-native-ttf \

--enable-gd-jis-conv

--enable-fpm

本身編譯php採用的是以下參數(親測成功):

shell>#./configure --prefix=/usr/local/php5.6.nginx \

--with-mysql=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-mysqli=mysqlnd \

--with-freetype-dir=/usr/local/freetype \

--with-gd \

--with-zlib --with-libxml-dir=/usr/local/libxml2 \

--with-jpeg-dir=/usr/local/jpeg \

--with-png-dir=/usr/local/png \

--enable-mbstring=all \

--enable-mbregex \

--enable-shared \

--enable-fpm

shell># make && make install

編譯安裝完後

shell># cp /usr/local/fastphp/etc/php-fpm.conf.default  /usr/local/fastphp/etc/php-fpm.conf

shell># cd /home/jinnan/upload/php-5.6.31

shell>#cp php.ini-development  /usr/local/php5.6.nginx/lib/php.ini

編譯完畢後:

1:

nginx+php的配置比較簡單,核心就一句話----

把請求的信息轉發給9000端口的PHP進程,

讓PHP進程處理 指定目錄下的PHP文件.

 

以下例子:

location ~ \.php$ {

            root html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

 

        }

 

1:碰到php文件,

2: 把根目錄定位到 html,

3: 把請求上下文轉交給9000端口PHP進程,

4: 並告訴PHP進程,當前的腳本是 $document_root$fastcgi_scriptname

(注:PHP會去找這個腳本並處理,因此腳本的位置要指對)

=================================================

因爲mysql使用更高級的cmake安裝,在安裝mysql前要先安裝cmake

 

安裝cmake:【cmake-3.8.2.tar.gz】

 

shell>#tar zxvf cmake-3.8.2.tar.gz

 

shell>#cd cmake-3.8.2

 

shell>#./bootstrap

 

shell>#make && make install

 

安裝mysql5.6【mysql-5.6.37.tar.gz】

 

shell>#tar zxvf mysql-5.6.37.tar.gz

 

shell>#cd mysql-5.6.37

 

shell>#cmake \

         -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6 \

         -DMYSQL_DATADIR=/usr/local/mysql/data \

         -DDEFAULT_CHARSET=utf8 \

         -DDEFAULT_COLLATION=utf8_general_ci

 

 

 

以上編譯參數說明(準備安裝到那裏

數據存儲目錄

默認的字符集

校對字符集)

 

 

 

 

 

 

 

若是出現以下錯誤:(安裝ncurses-devel)

 

 

安裝(ncurses-devel):

 

將以前裝系統的.iso文件掛載到光驅

 

因爲我在/home/jinnan/下創建了一個cdrom文件夾

 

Shell>#mount /dev/cdrom  /home/jinnan/cdrom

 

Shell># cd /home/jinnan/cdrom

 

Shell># ls

 

Shell># cd Packages

 

Shell>#ls | grep ncurses-devel

 

Shell># rpm -ivh ncurses-devel-5.7-3.20090208.el6.x86_64.rpm

 

從新進入到mysql解壓後的目錄

Shell>#cd mysql-5.6.37

必定要刪除CMakeCache.txt,不然從新cmake會報錯

Shell># rm -f CMakeCache.txt    //刪除該文件

從新cmake

Shell># cmake \

         -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6 \

         -DMYSQL_DATADIR=/usr/local/mysql/data \

         -DDEFAULT_CHARSET=utf8 \

         -DDEFAULT_COLLATION=utf8_general_ci

Shell>#make && make install

複製配置文件

shell># cp support-files/my-default.cnf /etc/my.cnf

配置並初始化MySQL

shell># useradd  mysql   (該mysql用戶會存在於同名的組下)

shell># chmod +x /usr/local/mysql5.6

(數據庫用戶信息不當心刪除光了,刪除data目錄,今後開始執行如下指令,直至結束)

shell># chown -R mysql.mysql /usr/local/mysql5.6

 

初始化mysql數據庫  

shell># /usr/local/mysql5.6/scripts/mysql_install_db \

--user=mysql \

--basedir=/usr/local/mysql5.6 \

--datadir=/usr/local/mysql5.6/data &

 

把mysql安裝文件(除了data)的主人都改成root,避免數據庫恢復爲出廠設置。

shell># chown -R root /usr/local/mysql5.6

shell># chown -R mysql /usr/local/mysql5.6/data

 

& 後臺運行mysql服務

shell># /usr/local/mysql5.6/bin/mysqld_safe --user=mysql &

 

//查看mysql是否有啓動

shell># ps –A | grep mysql   

 

測試數據庫

shell># /usr/local/mysql5.6/bin/mysql –u root

mysql> show databases;  

 

接上步,修改mysql密碼(可不作此步,默認無密碼)

Mysql>use mysql

 

mysql> delete from user where host != 'localhost';

 

mysql> delete from user where user != 'root';

 

mysql> update user set password=password('root') where user='root';

mysql> flush privileges;

 

 

若是但願在任何一個目錄下均可以進入mysql數據庫,則須要在/root/.bash_profile中添加mysql命令的路徑:/home/mysql/bin

 

若是要讓全部用戶都可以在全部目錄下進入mysql數據庫,那麼修改環境變量 /etc/profile

配置開機自啓動服務項

shell># cp 安裝包解壓目錄/support-files/mysql.server /etc/init.d/mysqld

shell># chmod +x /etc/init.d/mysqld

shell># chkconfig --add mysqld

shell># chkconfig mysqld on    //設置開機自啓動

 

配置文件路徑:

shell># vi /etc/rc.d/rc.local

在  文件中增長啓動相關服務的命令以下:

/usr/local/apache2.4/bin/apachectl start

/usr/local/mysql5.6/bin/mysqld_safe --user=mysql &

service vsftpd start

相關文章
相關標籤/搜索