您的位置首页百科问答

Linux搭建WEB服务器

Linux搭建WEB服务器

的有关信息介绍如下:

Linux搭建WEB服务器

如何在linux下搭建web服务器

1.安装Apache

(1)在安装HTTPServer之前需安装APR(ApachePortableRuntime)和APR-util安装APR(http://apr.apache.org/)

$tarzxvfapr-1.4.6.tar.gz

$cdapr-1.4.6/

$./configure

$make

$sudomakeinstall

(2)安装APR-util(http://apr.apache.org/)

$tarzxvfapr-util-1.4.1.tar.gz

$cdapr-util-1.4.1

$./configure–with-apr=/usr/local/apr(whereisapr)

$make

$sudomakeinstall

(3)安装httpd-2.4.2.tar.bz2(http://httpd.apache.org/)默认安装位置/usr/local/apache2网页放在/usr/local/apache2/htdocs配置文件/usr/local/apache2/conf/httpd.conf

$tarjxvfhttpd-2.4.2.tar.bz2

$cdhttpd-2.4.2/

$./configure

$make

$sudomakeinstall

(4)启动HTTPServer$sudo/usr/local/apache2/bin/apachectlstartAH00558:httpd:Couldnotreliablydeterminetheserver’sfullyqualifieddomainname,using127.0.1.1.Setthe‘ServerName’directivegloballytosuppressthismessage

(5)查看http是否正常运行$netstat-a|grephttptcp00*:http*:*LISTEN

(6)在浏览器输入127.0.0.1如果正常应该显示“Itworks!”

2.安装MySQL

下载mysql-5.5.25.tar.gz(http://www.mysql.com/downloads/mysql/)默认安装位置/usr/local/mysql/

$tarzxvfmysql-5.5.25.tar.gz

$cdmysql-5.5.25/

$sudogroupaddmysql

$sudouseradd-r-gmysqlmysql

$cmake.

$make

$sudomakeinstall

$cd/usr/local/mysql/

$sudochown-Rmysql.

$sudochgrp-Rmysql.

$sudoscripts/mysql_install_db–user=mysql

$sudochown-Rroot.

$sudochown-Rmysqldata/

$sudocpsupport-files/my-medium.cnf/etc/my.cnf

$sudocpsupport-files/mysql.server/etc/init.d/mysql.server

启动MySQL

方法1:$sudoservicemysql.serverstart

方法2:$sudo/usr/local/mysql/bin/mysqld_safe--user=mysql&

3.安装PHP

(1)安装下载php-5.4.4.tar.gz(http://php.net/)

$tarzxvfphp-5.4.4.tar.gz

$cdphp-5.4.4

$./configure--with-apxs2=/usr/local/apache2/bin/apxs--with-mysql--with-mysqli--enable-mbstring--with-mcrypt(可能需要安装libmcrypt-dev)

$sudomakeinstall

$sudocpphp.ini-development/usr/local/lib/php.ini

(2)配置HTTPServer使之支持PHPapache配置文件/usr/local/apache2/conf/httpd.conf修改或添加如下配置

<;IfModuledir_module>

DirectoryIndexindex.php

<;/IfModule>

<;FilesMatch\.php$>

SetHandlerapplication/x-httpd-php

<;/FilesMatch>

(3)重启HTTPServer

$sudo/usr/local/apache2/bin/apachectlrestart