安装Web服务
先安装Web服务,通过命令yum groupinstall命令进行安装,建议用groupinstall而不用Install是因为groupinstall,会把该服务所有相关的服务包一起安装,这样不会有丢失。
我们通过service httpd restart来开启服务,这里用restart而不用start的原因是restart更安全,因为你不知道该服务是否已经开启,如果已经start了再次用start可能会有意外的问题产生,故这里用restart.
我们通过命令chkconfig httpd on来开启httpd服务在下次开机后,仍然是开启有效的,这样的好处在于通过设置自动开启服务,避免人为失误操作,也会保证计算机重启或者断电后服务还是开启的。
验证httpd服务是否正常开启,是否能够对外提供服务,我们进入/var/www/html/,这里是主站点,我们写一个简单的页面,然后重定向到index.html,这是默认的首页。通过http访问该服务,发现已经成功服务该站点。
我们通过命令vim /etc/httpd/conf/httpd.conf可以对httpd配置文件进行修改,也可以用配置文件里面的功能,有些功能用#号注释掉了,如果想使用该功能的话,直接删除#号,可以让内置的配置文件该功能生效。
我们通过命令ll /etc/httpd可以查看到该目录下有conf和conf.d目录文件,再进一步查看/etc/httpd/conf.d下面可以看到的文件都是httpd的模块文件,用来支持动态页面的模块文件。
Apache和Selinux之间的关系,我们进入/var/www/html/目录下,通过ll –Z查看目录下index.html Selinux属性,通过命令ps –auxZ|grep http查看httpd的进程,这些http进程都有httpd_t的Selinux上下文属性,Selinux就规定了http_t这类的进程上下文属性可以访问httpd_sys_content_t这类文件的上下文属性,从而保证了网站的内容可以被访问。
8
查看Apache日志信息,日志信息存储在/var/log/httpd/目录下,可以查看http访问的日志及https的访问日志,可以查看错误的http日志及https的错误日志等信息,通过日志的信息帮我们了解到是什么原因导致http、https不能访问。
可以参考如下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修改或添加如下配置
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
(3)重启HTTP Server
$ sudo /usr/local/apache2/bin/apachectl restart
完全可以参考如下:
#/bin/bash
setenforce 0
# 检查必要的编译工具是否已经安装
rpm -q gcc gcc-c++ libtool-ltdl
if [ $? != 0 ]
then
echo
echo "Error: Some packages is not installed"
echo
echo "Please Install All Packages"
echo
exit 200
fi
###################################################################################################
# 检查是否有 RPM 包安装的 MySQL ,有的话是否卸载,最好卸载
rpm -q mysql
if [ $? = 0 ]
then
echo "package mysql is installed"
read -p "Remove RPM MySQL ? [Yes/No] " Q
case "$Q" in
yes | YES | Yes)
yum remove mysql -y
no | No | NO)
echo "OK , Do Not Remove"
*)
echo "Please Input Yes or No"
esac
fi
# 检查是否有 RPM 包安装的 htppd
rpm -q httpd
if [ $? = 0 ]
then
echo "Package httpd is installed"
read -p "Remove RPM HTTP ? [Yes/No] " QQ
case "$QQ" in
yes | Yes | YES)
yum remove httpd -y
no | No | NO)
echo "OK , Not Deleted"
*)
echo "Please Input Yes or No"
exit
esac
fi
# 检查是否有 RPM 包安装的 PHP
rpm -q php
if [ $? = 0 ]
then
echo "Package PHP is installed"
read -p "Remove RPM PHP ? [Yes/No] " QQQ
case "$QQQ" in
yes | Yes | YES)
yum remove php -y
no | No | NO)
echo "OK , Not Deleted"
*)
echo "Please Input Yes or No"
exit
esac
fi
###################################################################################################
# 创建一个临时目录
mkdir /lamp/
echo "$(date) Start" >>/lamp/install.lamp.log
# 解压 当前目录下 的 源码包 到指定目录
tar zxvf httpd-2.2.9.tar.gz -C /lamp/
tar zxvf mysql-5.0.56.tar.gz -C /lamp/
tar jxvf php-5.2.6.tar.bz2 -C /lamp/
###################################################################################################
# HTTP
cd /lamp/httpd-2.2.9
./configure \
--prefix=/usr/local/apache2 \
--enable-so \
--enable-rewrite \
--enable-ssl \
--with-ssl=/usr/lib \
--enable-auth-digest \
--enable-cgi \
--enable-suexec \
--with-suexec-caller=daemon \
--with-suexec-docroot=/usr/local/apache2/htdocs
make &&make install &&echo "httpd installed" >>/lamp/install.lamp.log
grep httpd /lamp/install.lamp.log
if [ $? = 0 ]
then echo Good
else
cat /lamp/install.lamp.log
echo "Error: httpd is Installation failure
"
exit
fi
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' /usr/local/apache2/conf/httpd.conf
/usr/local/apache2/bin/apachectl start
echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.d/rc.local
###################################################################################################
# MySQL
grep mysql /etc/passwd
if [ $? -eq 0 ]
then
service mysqld stop
mv /etc/my.cnf /etc/my.cnf.bak
else
groupadd -g 27 mysql
useradd -u 27 -g 27 -M -s /sbin/nologin mysql
fi
cd /lamp/mysql-5.0.56
./configure \
--prefix=/usr/local/mysql/
make &&make install &&echo "MySQL installed" >>/lamp/install.lamp.log
grep -i mysql /lamp/install.lamp.log
if [ $? = 0 ]
then echo Good
else
cat /lamp/install.lamp.log
echo "Error: MySQL is Installation failure
"
exit
fi
cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
cp /lamp/mysql-5.0.56/support-files/mysql.server /etc/rc.d/init.d/mysqld
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig --levels 24 mysqld off
export PATH=$PATH:/usr/local/mysql/bin
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile
echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf
ldconfig
###################################################################################################
# PHP
cd /lamp/php-5.2.6
./configure \
--prefix=/usr/local/php5 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--enable-sockets \
--enable-mbstring
make &&make install &&echo "php installed" >>/lamp/install.lamp.log
grep php /lamp/install.lamp.log
if [ $? = 0 ]
then echo Good
else
cat /lamp/install.lamp.log
echo "Error: PHP5 is Installation failure
"
exit
fi
cp php.ini-dist /usr/local/php5/php.ini
echo "AddType application/x-httpd-php .php .phtml" >>/usr/local/apache2/conf/httpd.conf
/usr/local/apache2/bin/apachectl restart
echo "$(date) End" >>/lamp/install.lamp.log
echo "Complete" >>/lamp/install.lamp.log
echo END
<<BENET
如果测试 PHP 时没有被 Apache 识别,请重启一下浏览器。再不行就重启一下 Apache 。
像这样:
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
BENET
echo "
OK Very Good
Please Set MySQL Server's Password
Like This:
mysqladmin -u root password \"1234567890\"
“
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)