Linux下源碼編譯安裝apache2,PHP5,mysql5

來源:互聯網
上載者:User

#apache

 代碼如下 複製代碼
./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
make
make install
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
cd /etc/rc.d/init.d
#vi httpd
#在檔案首部#!/bin/bash行下,加入以下幾行
# chkconfig: 2345 50 40
# description: This is a Internet www Server
#說明一下,直接調用chkconfig是不行的,必須加上以上兩行。
#description是描述這個服務用的,一定要寫上對服務的描述,而且不可以是中文的,
#chkconfig: 第一組數字是系統運行級2345表示的是將要設為啟動的系統運行層級
#第二個數字是優先順序,00優先順序最高,當然考慮到依賴性,你的服務的優先順序不宜過高
#如果,比自己依賴的服務的優先順序更高,那麼您的服務將無法正常啟動
#第三組數字就是殺死服務的優先順序
chkconfig --add httpd
 
#mysql
 代碼如下 複製代碼
./configure --prefix=/usr/local/mysql --localstatedir=/mydata/web/mysql --with-charset=utf8 --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
#建立mysql使用者和使用者組
groupadd mysql
useradd -g mysql mysql
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R mysql /var/mysql
#初始化許可權資料庫,並不需要啟動mysql
scripts/mysql_install_db --user=mysql
#啟動mysql, "&"是後台運行
/usr/local/mysql/bin/mysqld_safe --user=mysql&
#更改root密碼
/usr/local/mysql/bin/mysqladmin -u root -p password "123456"
#設定為開機自啟動
cd /etc/rc.d/init.d
cp /usr/local/mysql/share/mysql/ mysql.server mysqld
chmod +x mysqld
chkconfig --add mysqld
 
#PHP
 代碼如下 複製代碼
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-zlib --with-png --with-freetype-dir --with-config-file-path=/usr/local/php/etc --enable-gd-native-ttf --with-ttf --enable-memory-limit --enable-zend-multibyte --disable-ipv6 --disable-path-info-check --with-iconv --disable-debug --with-mail --enable-mbregex --with-curl --enable-mbstring=all --enable-zip --enable-exif --with-jpeg-dir=/usr/lib64/
make
make install
#配置apache
 代碼如下 複製代碼
# vi /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#開放80連接埠

 代碼如下 複製代碼
#iptables -A INPUT -i eth0 -p TCP --dport 80 -j ACCEPT

四 、整合apache 與php

 代碼如下 複製代碼
# vi /usr/local/apache2/conf/httpd.conf

在最後一行加上:

 代碼如下 複製代碼
AddType application/x-httpd-php .php

尋找:(設定 WEB 預設檔案)

 代碼如下 複製代碼
DirectoryIndex index.html

替換為:

 代碼如下 複製代碼
DirectoryIndex index.php index.html index.htm //在 WEB 目錄不到預設檔案,httpd 就會執行 /var/www/error/noindex.html

找到這一段:

 代碼如下 複製代碼
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none

更改為AllowOverride all
允許apache rewrite

儲存httpd.conf,退出。

 代碼如下 複製代碼

# /usr/local/apache2/bin/apachectl restart //重啟 Apache

五、 測試

 代碼如下 複製代碼
vi /usr/local/apache2/htdocs/test.php

新增加下面一行,並儲存。

 代碼如下 複製代碼

<?php phpinfo(); ?>

# chmod 755 /usr/local/apache2/htdocs/phpinfo.php

用瀏覽器開啟 http://locahost/test.php

或者 http://本機ip/test.php
(如ip為192.168.4.2 則 http://192.168.4.2/test.php)

當看到php頁面時表示成功!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.