标签:lamp
Apache有两种模式提供服务,一种是线程worker模式,一种是进程prefork模式(更加稳定)
线程模式是一个进程下面有许多线程提供服务。
而进程模式是直接是许多进程提供服务,但是消耗cpu。
安装apache
[root@lamp src]# ls
httpd-2.2.27.tar.gz
[root@lamp src]# pwd
/usr/local/src
[root@lamp src]# tar -xf httpd-2.2.27.tar.gz
[root@lamp src]# ls
httpd-2.2.27 httpd-2.2.27.tar.gz
[root@lamp src]# cd httpd-2.2.27
[root@lamp httpd-2.2.27]# ./configure \
--prefix=/usr/local/apache2.2.27 \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite
[root@lamp httpd-2.2.27]# yum install -y zlib zlib-devel
[root@lamp httpd-2.2.27]#make && make install
[root@lamp src]# cd ..
[root@lamp local]# ls
apache2.2.27 etc include lib64 sbin src
bin games lib libexec share
[root@lamp local]# ln -s apache2.2.27 /usr/local/apache
[root@lamp local]# cd apache
[root@lamp apache]# ls
bin cgi-bin error icons lib man modules
build conf htdocs include logs manual
检测语法
[root@lamp local]# /usr/local/apache/bin/apachectl -t
httpd: apr_sockaddr_info_get() failed for lamp
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
启动apache
[root@lamp local]# /usr/local/apache/bin/apachectl start
httpd: apr_sockaddr_info_get() failed for lamp
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
检测是否启动
[root@lamp local]# ps -aux |grep httpd
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root 5133 0.0 0.2 34416 2132 ? Ss 05:10 0:00 /usr/local/apache2.2.27/bin/httpd -k start
daemon 5134 0.0 0.1 34148 1300 ? S 05:10 0:00 /usr/local/apache2.2.27/bin/httpd -k start
daemon 5135 0.0 0.3 378676 3892 ? Sl 05:10 0:00 /usr/local/apache2.2.27/bin/httpd -k start
daemon 5136 0.0 0.3 378676 3900 ? Sl 05:10 0:00 /usr/local/apache2.2.27/bin/httpd -k start
daemon 5137 0.1 0.3 378676 3900 ? Sl 05:10 0:00 /usr/local/apache2.2.27/bin/httpd -k start
root 5220 0.0 0.0 103244 856 pts/0 S+ 05:10 0:00 grep httpd
[root@lamp local]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 5133 root 4u IPv6 59038 0t0 TCP *:http (LISTEN)
httpd 5135 daemon 4u IPv6 59038 0t0 TCP *:http (LISTEN)
httpd 5136 daemon 4u IPv6 59038 0t0 TCP *:http (LISTEN)
httpd 5137 daemon 4u IPv6 59038 0t0 TCP *:http (LISTEN)
测试
[root@lamp local]# iptables -F
[root@lamp local]# /etc/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
配置站点
[root@lamp conf]# pwd
/usr/local/apache/conf
[root@lamp conf]# ls
extra httpd.conf magic mime.types original
[root@lamp conf]# grep -i documentroot httpd.conf
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/usr/local/apache2.2.27/htdocs"
# This should be changed to whatever you set DocumentRoot to.
# access content that does not live under the DocumentRoot.
平滑重启
[root@lamp apache]# /usr/local/apache/bin/apachectl graceful
Apache的配置文件讲解
查看配置里面站点默认的页面
[root@lamp conf]# vim httpd.conf
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
目录结构的设置
-Indexes就是禁止显示目录结构了
或者把这里删除掉,当主页没有找到的话就显示403,而不会显示目录结构,确保安全
Options -Indexes FollowSymLinks
虚拟主机配置文件
[root@lamp extra]# ls -l /usr/local/apache/conf/extra
total 56
-rw-r--r-- 1 root root 2855 Dec 7 05:01 httpd-autoindex.conf
-rw-r--r-- 1 root root 1743 Dec 7 05:01 httpd-dav.conf
-rw-r--r-- 1 root root 2344 Dec 7 05:01 httpd-default.conf 了解
-rw-r--r-- 1 root root 1103 Dec 7 05:01 httpd-info.conf
-rw-r--r-- 1 root root 5078 Dec 7 05:01 httpd-languages.conf
-rw-r--r-- 1 root root 945 Dec 7 05:01 httpd-manual.conf
-rw-r--r-- 1 root root 3789 Dec 7 05:01 httpd-mpm.conf
-rw-r--r-- 1 root root 11492 Dec 7 05:01 httpd-ssl.conf
-rw-r--r-- 1 root root 817 Dec 7 05:01 httpd-userdir.conf
-rw-r--r-- 1 root root 1503 Dec 7 05:01 httpd-vhosts.conf
虚拟主机配置:
域名站点目录
www.bier.org /var/html/www
blog.bier.org /var/html/blog
bbs.bier.org /var/html/bbs
创建站点目录
[root@lamp extra]# mkdir -p /var/html/www
[root@lamp extra]# mkdir -p /var/html/blog
[root@lamp extra]# mkdir -p /var/html/bbs
[root@lamp extra]# touch /var/html/www/index.html
[root@lamp extra]# touch /var/html/blog/index.html
[root@lamp extra]# touch /var/html/bbs/index.html
[root@lamp extra]# tree /var/html/
/var/html/
|-- bbs
| `-- index.html
|-- blog
| `-- index.html
`-- www
`-- index.html
[root@lamp extra]# for i in www blog bbs;do echo "http://$i.bier.org" >/var/html/$i/index.html;done
[root@lamp extra]# for i in www blog bbs;do cat /var/html/$i/index.html;done
http://www.bier.org
http://blog.bier.org
http://bbs.bier.org
配置虚拟机主机
[root@lamp extra]# pwd
/usr/local/apache/conf/extra
[root@lamp extra]# vim httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin 947370895@qq.com
DocumentRoot "/var/html/www"
ServerName www.bier.org
ServerAlias bier.org
ErrorLog "logs/www-error_log"
CustomLog "logs/www-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 947370895@qq.com
DocumentRoot "/var/html/blog"
ServerName blog.bier.org
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 947370895@qq.com
DocumentRoot "/var/html/bbs"
ServerName bbs.bier.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
打开主配置文件这里
[root@lamp conf]# pwd
/usr/local/apache/conf
[root@lamp conf]# vim httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
添加站点目录
<Directory "/var/html">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
检测重启
[root@lamp conf]# /usr/local/apache/bin/apachectl -t
Syntax OK
[root@lamp conf]# /usr/local/apache/bin/apachectl graceful
然后本地解析测试,浏览器访问
安装apache日志轮询工具cronolog
(此工具工作中用这种比较多,不用系统自带的)
安装cronolog工具
tar -xf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install
[root@lamp src]# ll /usr/local/sbin/cronolog
-rwxr-xr-x 1 root root 40438 Dec 7 08:24 /usr/local/sbin/cronolog
Cronolog日志轮询配置说明
错误写法:
CustomLog "|/usr/local/sbin/cronolog logs/access_www_%w.log" common
提示:cronllog日志轮询的正确写法,被轮询的日志路径要写全
正确写法
CustomLog "|/usr/local/sbin/cronolog /app/logs/access_www_%Y%m%d.log" common
提示:这个大多数网站的常规写法(按天记录日志,日志不会被自动覆盖)
[root@lamp src]# mkdir -p /app/logs
在虚拟主机修改好格式,检测重启访问测试
[root@lamp apache]# tail -f /app/logs/access_www_20151207.log
192.168.3.1 - - [07/Dec/2015:08:58:37 -0500] "GET / HTTP/1.1" 304 -
192.168.3.1 - - [07/Dec/2015:08:58:39 -0500] "GET / HTTP/1.1" 304 -
192.168.3.1 - - [07/Dec/2015:08:58:39 -0500] "GET / HTTP/1.1" 304 -
192.168.3.1 - - [07/Dec/2015:08:59:50 -0500] "GET / HTTP/1.1" 304 -
192.168.3.1 - - [07/Dec/2015:08:59:51 -0500] "GET / HTTP/1.1" 304 -
192.168.3.1 - - [07/Dec/2015:08:59:51 -0500] "GET / HTTP/1.1" 304 -
安装mysql
创建mysql用户
[root@lamp src]# useradd mysql -s /sbin/nologin –M
./configure \
--prefix=/usr/local/mysql5.1.72 \
--with-unix-socket-path=/usr/local/mysql5.1.72/tmp/mysql.sock \
--localstatedir=/usr/local/mysql5.1.72/data \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-big-tables \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=complex \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
可以将上面的脚本放入mysql.log,然后cat mysql.log|bash 执行
修改错误
checking for termcap functions library... configure: error: No curses/termcap library found
[root@lamp mysql-5.1.72]# yum install -y ncurses ncurses-devel
make && make install
[root@lamp local]# ln -s mysql5.1.72/ /usr/local/mysql
[root@lamp mysql]# mkdir -p /usr/local/mysql/data存放数据的地方
[root@lamp mysql]# chown -R mysql.mysql /usr/local/mysql/data
配置mysql
[root@lamp mysql]# ls /usr/local/mysql/share/mysql/my*.cnf
/usr/local/mysql/share/mysql/my-huge.cnf
/usr/local/mysql/share/mysql/my-innodb-heavy-4G.cnf
/usr/local/mysql/share/mysql/my-large.cnf
/usr/local/mysql/share/mysql/my-medium.cnf
/usr/local/mysql/share/mysql/my-small.cnf
提示:此版本这些文件在上面的目录下面,一般是在安装目录下的support-files的这个目录下
[root@lamp mysql]# cd /usr/local/mysql/share/mysql/
[root@lamp mysql]# cp my-small.cnf /etc/my.cnf
mysql默认的配置路径和文件名/etc/my.conf
初始化数据库
[root@lamp mysql]# /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql
Installing MySQL system tables...
151207 11:09:10 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK
Filling help tables...
151207 11:09:11 [Warning] ‘--skip-locking‘ is deprecated and will be removed in a future release. Please use ‘--skip-external-locking‘ instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
/usr/local/mysql/bin/mysqladmin -u root password ‘new-password‘
/usr/local/mysql/bin/mysqladmin -u root -h lamp password ‘new-password‘
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!
生成数据
[root@lamp mysql]# ll ./data
total 8
drwx------ 2 mysql root 4096 Dec 7 11:09 mysql
drwx------ 2 mysql root 4096 Dec 7 11:09 test
启动数据库
/usr/local/mysql/bin/mysqld_safe &
检测
[root@lamp mysql]# ps -aux |grep mysqld |grep -v grep
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root 22545 0.0 0.1 106100 1476 pts/1 S 11:47 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
mysql 22653 0.7 2.6 269760 27240 pts/1 Sl 11:47 0:06 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/lamp.err --pid-file=/usr/local/mysql/data/lamp.pid --socket=/usr/local/mysql5.1.72/tmp/mysql.sock --port=3306
[root@lamp mysql]# lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 22653 mysql 10u IPv4 151886 0t0 TCP *:mysql (LISTEN)
安装PHP
检测apache和mysql
[root@lamp src]# netstat -lnptu |egrep "3306|80"
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23167/mysqld
tcp 0 0 :::80 :::* LISTEN 5133/httpd
tcp 0 0 :::8000 :::* LISTEN 5133/httpd
检测安装所需的lib库
安装准备
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
解压编译
./configure \
--prefix=/usr/local/php5.3.27 \
--with-apxs2=/usr/local/apache/bin/apxs \
是给apache添加模块的dso模式添加,php嵌入到apache里面
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir
[root@Centos6 modules]# pwd
/usr/local/apache2/modules
[root@Centos6 modules]# ll
total 26220
-rw-r--r-- 1 root root 9083 Jun 29 16:10 httpd.exp
-rwxr-xr-x 1 root root 24594399 Jun 29 17:01 libphp5.so
有这两个文件,说明apache已经嵌入了php
拷贝配置文件
[root@Centos6 local]# cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/lib/php.ini
配置apache解析php
打开apache主配置文件
定位311gg加下面这两行
AddType application/x-httpd-php .php.phtml
AddType application/x-httpd-php-source.phps
AddType application/x-httpd-php .php
提示:这里一定要配置,不然apahce解析不了php,一打开就下载的情况
然后改一下里面的用户和组
#
User www
Group www
增加index.php
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
[root@Centos6 conf]# useradd -s /sbin/nologin -M www
检测重启apache
[root@Centos6 conf]# chown -R www.www /var/html/blog
[root@Centos6 conf]# cd /var/html/blog
[root@Centos6 conf]# vim index.php
<?php
phpinfo();
?>
浏览器测试php
测试mysql
vim mysql.php
<?php
$link_id=mysql_connect(‘localhost‘,‘root‘,‘123456‘) or mysql_error();
if($link_id){
echo "mysql successful by oldboy !";
}else{
echo mysql_error();
}
?>
到此lamp环境部署完成
本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884102
标签:lamp
原文地址:http://chenshoubiao.blog.51cto.com/6159058/1884102