1. 如何在linux搭建完整的web伺服器
可以參考如下Web伺服器的建立過程。示例環境及web伺服器軟體:
Ubuntu 12.04
LAMP(Linux,Apache,Mysql,PHP)
1、安裝Apache
(1)在安裝HTTP Server之前需安裝APR(Apache Portable Runtime)和APR-util安裝APR
$ tar zxvf apr-1.4.6.tar.gz
$ cd apr-1.4.6/
$ ./configure
$ make
$ sudo make install
(2)安裝APR-util
$ tar zxvf apr-util-1.4.1.tar.gz
$ cd apr-util-1.4.1
$ ./configure –with-apr=/usr/local/apr (whereis apr)
$ make
$ sudo make install
(3)安裝httpd-2.4.2.tar.bz2默認安裝位置/usr/local/apache2網頁放在/usr/local/apache2/htdocs配置文件/usr/local/apache2/conf/httpd.conf
$ tar jxvf httpd-2.4.2.tar.bz2
$ cd httpd-2.4.2/
$ ./configure
$ make
$ sudo make install
(4)啟動HTTP Server$ sudo /usr/local/apache2/bin/apachectl startAH00558: httpd: Could not reliably determine the server』s fully qualified domain name, using 127.0.1.1. Set the 『ServerName』 directive globally to suppress this message
(5)查看http是否正常運行$ netstat -a | grep httptcp 0 0 *:http *:* LISTEN
(6)在瀏覽器輸入127.0.0.1如果正常應該顯示「It works!」
2、安裝MySQL
(1)、下載安裝mysql-5.5.25.tar.gz,默認安裝位置/usr/local/mysql/
$ tar zxvf mysql-5.5.25.tar.gz
$ cd mysql-5.5.25/
$ sudo groupadd mysql
$ sudo useradd -r -g mysql mysql
$ cmake .
$ make
$ sudo make install
$ cd /usr/local/mysql/
$ sudo chown -R mysql .
$ sudo chgrp -R mysql .
$ sudo scripts/mysql_install_db –user=mysql
$ sudo chown -R root .
$ sudo chown -R mysql data/
$ sudo cp support-files/my-medium.cnf /etc/my.cnf
$ sudo cp support-files/mysql.server /etc/init.d/mysql.server
(2)、啟動MySQL:
方法1:$ sudo service mysql.server start
方法2:$ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &
3、安裝PHP
(1)安裝下載php-5.4.4.tar.gz
$ tar zxvf php-5.4.4.tar.gz
$ cd php-5.4.4
$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-mysqli --enable-mbstring --with-mcrypt(可能需要安裝libmcrypt-dev )
$ sudo make install
$ sudo cp php.ini-development /usr/local/lib/php.ini
(2)配置HTTP Server使之支持PHPapache配置文件/usr/local/apache2/conf/httpd.conf修改或添加如下配置
<;IfMole dir_mole>
DirectoryIndex index.php
<;/IfMole>
<;FilesMatch \.php$>
SetHandler application/x-httpd-php
<;/FilesMatch>
(3)重啟HTTP Server
$ sudo /usr/local/apache2/bin/apachectl restart