Apache+MySQL+PHP(手動安裝)

版主: stnet253

回覆文章
admin
系統管理員
文章: 36
註冊時間: 2012-02-25, 22:10
聯繫:

Apache+MySQL+PHP(手動安裝)

未閱讀文章 admin »

Linux - Apache+MySQL+PHP(手動安裝)
環境RedHat AS5 for x86

安裝Apache2
下載網址 http://httpd.apache.org/download.cgi

解壓縮/ 編譯Apache2
# tar jxvf httpd-2.2.17.tar.bz2
# cd httpd-2.2.17
# ./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl=static --enable-mods-shared=all --enable-modules=most --with-mpm=worker
# make && make install

編輯配置httpd.conf檔案
# vi /usr/local/apache2/conf/httpd.conf
User apache //Apache 的使用者及群組
Group apache
ServerAdmin [email protected] //管理E-mail位址
ServerName 192.168.11.200:80 //伺服器位址:80

<IfModule dir_module>
DirectoryIndex index.html index.htm index.php index.php3
</IfModule>

啟動apache2
# /usr/local/apache2/bin/apachectl start //啟動Apache2
# ps -ef |grep httpd
root 15785 1 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
apache 15786 15785 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
apache 15787 15785 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
apache 15789 15785 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
apache 15791 15785 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start
apache 15968 15785 0 12:43 ? 00:00:00 /usr/local/apache2/bin/httpd -k start

測試網頁
http://webserver/ IP/index.html
出現 It Work!代表成功了 ; 如果沒出現,可能firewall被檔住..
# /usr/local/apache2/bin/apachectl stop //Apach2停止

調整Apache效能
編輯httpd-default檔案
# vi /usr/local/apache2/conf/extra/httpd-default.conf
內容如下
Timeout 60
KeepAlive On
MaxKeepAliveRequests 800
KeepAliveTimeout 5
HostnameLookups Off

編輯httpd-mpm檔案
bash-3.00# vi /usr/local/apache2/conf/extra/httpd-mpm.conf
內容如下
<IfModule mpm_worker_module>
StartServers 2
MaxClients 800
MinSpareThreads 25
MaxSpareThreads 100
ThreadsPerChild 50
MaxRequestsPerChild 100
</IfModule>

修改httpd.conf檔案
#vi /usr/local/apache2/conf/httpd.conf

將httpd-mpm.conf及httpd-default註解取消 , 沒有此2行的就自行加入
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf

自動啟動和關閉Apache Server
# ln –s /usr/local/apache2/bin/apachectl /etc/rc3.d/S85httpd
# ln –s /usr/local/apache2/bin/apachectl /etc/rc0.d/K85httpd
# ln –s /usr/local/apache2/bin/apachectl /etc/rc1.d/K85httpd
# ln -s /usr/local/apache2/bin/apachectl /etc/rc2.d/K85httpd

編譯及安裝Mysql5
下載網址 http://dev.mysql.com/downloads/mirror.p ... 62#mirrors

安裝cmake
# cd/usr/local/src/tarbag
# wget -c http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
# tar zxvf cmake-2.8.3.tar.gz
# cd ../software/cmake-2.8.3
# ./bootstrap
# make && make install

解壓縮 /編譯Mysql5
# groupadd mysql
# useradd –g mysql –s /sbin/nologin mysql

# tar zxvf mysql-5.5.9.tar.gz
# cd mysql-5.5.9/
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1
# make && make install

編譯選項說明
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安裝目錄
-DDEFAULT_CHARSET=utf8 //使用utf8字元
-DDEFAULT_COLLATION=utf8_general_ci //校驗字元
-DEXTRA_CHARSETS=all //安裝所有擴展字元集
-DWITH_EMBEDDED_SERVER=1 //編譯成embedded mysql library
-DENABLED_LOCAL_INFILE=1 //允許從本地導入資料
-DWITH_MYISAM_STORAGE_ENGINE=1 //安裝myisam引擎

配置
# chown -R mysql..mysql /usr/local/mysql
# cd /usr/local/mysql
# cp ./support-files/my-medium.cnf /etc/my.cnf
# ./scripts/mysql_install_db --user=mysql
# ./bin/mysqld_safe --user=mysql &

自動啟動和關閉Mysql Server
# cp ./support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld restart
# export PATH=$PATH:/usr/local/mysql/bin
# export LD_LIBRARY_PATH=/usr/local/mysql/lib:/lib:/usr/local/lib:/var/lib

查看mysql
Mysql預設使用的Port是3306
# netstat -na | grep 3306
*.3306 *.* 0 0 49152 0 LISTEN

設定 MySQL 的 root user密碼
# mysqladmin -u root password xxxxx
# mysqladmin -u root -h `hostname` password -p
Enter password:
New password:
Confirm new password:

測試 Mysql Server
# mysqladmin version -p
Enter password: //輸入剛加入的root 密碼
mysqladmin Ver 8.42 Distrib 5.5.9, for Linux on i686
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.9-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 5 min 11 sec
Threads: 1 Questions: 19 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.61
如出現上面的有關mysql5相關資訊 , 則表示安裝成功!

查看mysql 內所有資料庫
# mysqlshow -p
Enter password:
+--------------------+
| Databases |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+

進入 mysql 模式
# mysql -uroot -p
Enter password: //輸入root 密碼
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.9-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> quit;
Bye

PHP5
下載網址 http://www.php.net/
# tar jxvf php-5.3.5.tar.bz2
# cd php-5.3.5

編譯及安裝php
# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
--with-mysql=/usr/local/mysql –with-gd –with-zlib-dir
# make && make install

將php.ini設定檔copy至/usr/local/php5/lib目錄內
cp php.ini-production /usr/local/php5/php.ini

編輯Apache 設定檔 , 讓Apache可以看得懂PHP Script 並使PHP模組去解析它們
# vi /usr/local/apache2/conf/httpd.conf

檢查所下, 如沒有自行加入
DirectoryIndex index.html index.htm index.php index.php3
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php .phtml

測試php5
# vi /usr/local/apache2/htdocs/info.php
<? php
phpinfo();
?>

打開IE測試:http://192.168.11.200/info.php




重啟動 Apache2
# usr/local/apache2/bin/apachectl restart //重新啟動Apache2

安裝 phpMyAdmin
下載網址 http://www.phpmyadmin.net/

解壓縮phpMyAdmin
#tar zxvf phpMyAdmin-3.3.9.2-all-languages.tar.gz -C /usr/local/apache2/htdocs/
#mv phpMyAdmin-3.3.9.2-all-languages/ phpMyAdmin

打開IE測試 http://192.168.11.200/phpMyAdmin/


輸入mysql 資料庫的帳號及密碼即可.
回覆文章

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 0 位訪客