LAMP=Linux+Apache+Mysql+Php

一、当前互联网主流web服务

静态服务:

1.apache---中小型静态web服务的主流,web服务器中的老大哥

2.nginx---大型新型网络静态web服务主流,web服务器中的初生牛犊

3.lighttpd---静态web服务不温不火,逐渐被淘汰的意味,社区不活跃,效率很高。

动态服务:

1.IIS(Internet information services)---微软的web服务器(asp、aspx)

2.tomcat---中小企业动态web服务主流,互联网java容器主流(jsp,do)

3.resin---大型动态网站web服务主流,互联网java容器主流(jsp,do)

4.php(fcgi)---大中小网站,php程序的解析容器

  a.配合apache,php不是守护进程,而是mod_php5.so(module)

  b.配合nginx,lighttpd,php守护进程模式,FCGI模式。

二、apache的安装

1.首先确定安装httpd服务(yum install httpd -y)

确定:yum install gcc gcc++ zlib zlib-devel -y

2.安装apache(地址http://apache.fayea.com/httpd/上官网上找)

apache源码编译:

./configure --prefix=/application/apache2.2.32 \

--enable-expires \

--enable-headers \

--enable-modules=most \

--enable-so \

--with-mpm=worker \

--enable-deflate \

--enable-rewrite

make &&make install

3.启动apache服务:

1)查看apache语法是否可行:[root@localhost local]# /application/apache/bin/apachectl -t

2)启动apache服务:[root@localhost local]# /application/apache/bin/apachectl start

3)查看是否启动apache服务:lsof -i:80或者ps -ef|grep apache

it works 表示成功

如果不ok检查端口,防火墙,selinux,进程

strace追踪进程的命令

修改编译内容在/application/apache/htdocs/下 有index.html

三、/application/apache目录结构

apache优化1.把root@localhost conf]# vi httpd.conf 里的Index前面加-号或者直接删除

/application/apache/conf/extra 三个重点文件

四、虚拟主机

1.虚拟主机:部署多个站点,每个站点希望用不同的域名和站点目录,或者是不同的端口,不同的IP的时候需要虚拟主机。

一句话,一个http服务要配置多个站点,就需要虚拟机。

虚拟机分类:

a.基于域名

b.基于端口

c.基于IP

2.搭建虚拟机(基于域名)

域名 站点目录

www.etiantian.org        /var/html/www

blog.etiantian.org        /var/html/blog

bbs.etiantian.org         /var/html/bbs

创建主页文件:

[root@localhost apache]# mkdir /var/html/{www,blog,bbs} -p

[root@localhost apache]# touch /var/html/{www,blog,bbs}/index.html

[root@localhost apache]# for name in www blog bbs;do echo "http://$name.etiantian.org" >/var/html/$name/index.html;done

[root@localhost apache]# for name in www blog bbs;do cat /var/html/$name/index.html;done

vim /application/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/www"

ServerName www.etiantian.org

ServerAlias etiantian.org

ErrorLog "logs/www-error_log"

CustomLog "logs/www-access_log" common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/blog"

ServerName blog.etiantian.org

ErrorLog "logs/blog-error_log"

CustomLog "logs/blog-access_log" common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/bbs"

ServerName bbs.etiantian.org

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

</VirtualHost>

vim /application/apache/conf/httpd.conf(去点下两行注释)

[root@localhost extra]# /application/apache/bin/apachectl -t

Syntax OK

检查语法

[root@localhost extra]# /application/apache/bin/apachectl graceful 重启apache

vim /application/apache/conf/httpd.conf 在最末行加入下面的内容:

<Directory "/application/apache2.2.32/htdocs">

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

以上配置是防止403出错,之后检查语法是否错误http://blog.csdn.net/u011130583/article/details/42363831(有错误查看

修改windows本地system32 drives hosts (192.168.76.128 www.etiantian.org blog.etiantian.org bbs.etiantian.org

[root@localhost extra]# grep "^Include" /application/apache/conf/httpd.conf

Include conf/extra/httpd-mpm.conf

Include conf/extra/httpd-vhosts.conf

一.mysql

创建mysql:useradd mysql -g mysql -M -s /sbin/nologin

mysql的编译:

./configure --prefix=/application/mysql5.1.72 \

--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock \

--localstatedir=/application/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

yum -y install ncurses-devel(出错解决方案)

root@localhost application]# cd /home/cai/tools/

[root@localhost tools]# cd mysql-5.1.72/support-files/

[root@localhost support-files]# cp my-small.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

[root@localhost support-files]# cd /etc/

[root@localhost etc]# less my.cnf

[root@localhost etc]# mkdir /application/mysql/date -p

[root@localhost etc]# chown -R mysql.mysql /application/mysql

[root@localhost etc]#/application/mysql/bin/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data/ --user=mysql

Installing MySQL system tables...

170314 20:15:22 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.

OK

Filling help tables...

170314 20:15:22 [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

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/application/mysql/bin/mysqladmin -u root password 'new-password'

/application/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /application/mysql ; /application/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /application/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql/scripts/mysqlbug script!

启动mysql :/application/mysql/bin/mysqld_safe &(启动服务注意添加到开机自启动)

[root@localhost support-files]# netstat -lntup|grep mysql (确认是否启动了该服务)

vi /etc/profile在最后添加用户一行

关闭:

mysqladmin shutdown

/application/mysql/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' 设置密码

mysql -uroot -p(设置过密码后登录mysql的方法)

二、php

LAMP下的php

apache==》libphp5.so

nginx php==》fcgi php-

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers(需要安装的各种库)

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(oldboy里的)

libiconv库需要(编译安装)

php编译:

./configure \

--prefix=/application/php5.3.27 \

--with-apxs2=/application/apache/bin/apxs \

--with-mysql=/application/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@localhost php]# ll /application/apache/modules/

总用量 23908

-rw-r--r-- 1 root root 9262 4月 15 09:27 httpd.exp

-rwxr-xr-x 1 root root 24465701 4月 15 10:15 libphp5.so

[root@localhost php]# grep libphp5 /application/apache/conf/httpd.conf

LoadModule php5_module modules/libphp5.so

配置php文件:

有两个,一个是生产环境 一个是开发环境(测试环境)

[root@localhost php-5.3.27]# diff php.ini-development php.ini-production

[root@localhost php-5.3.27]# cp php.ini-production /application/php/lib/php.ini

小结:正式配置文件一般关闭显示LOG,不输出LOG

配置apache支持php

vim /application/apache/conf/httpd.conf 修改98行 ServerName 192.168.76.128:80

vim /application/apache/conf/httpd.conf 在311行下添加两行

AddType application/x-httpd-php .php .phtml

AddType application/x-httpd-php-source .phps

user daemon 修改为其他的 底下的也该(默认的大家都知道必须修改)

166行 修改为

[root@localhost conf]# diff httpd.conf httpd.conf.ori

67,68c67,68

< User www

< Group www

---

> User daemon

> Group daemon

168c168

< DirectoryIndex index.php index.html

---

> DirectoryIndex index.html

320,321d319

< AddType application/x-httpd-php .php .phtml

< AddType application/x-httpd-php-source .phps

添加www用户:useradd www -s /sbin/nologin -M

[root@localhost conf]# /application/apache/bin/apachectl graceful 重启apache服务

测试php 在以建的虚拟机中 /var/html/blog vi index.php

[root@localhost blog]# cat index.php

<?php

phpinfo();

?>

出现这个界面表示php+apache成功

vi /var/html/blog/index.php

<?php

//$link_id=mysql_connect('主机名','用户','密码');

$link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();

if($link_id){

echo "mysql successful by oldboy !";

}else{

echo mysql_error();

}

?>

上界面表示mysql成功

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏前端架构与工程

NodeJS学习笔记 - Apache反向代理集成实现

初学,简单的实现,为进行优化。 1. 假设NodeJS服务端监听3000端口 2. Apache反向代理设置     a. 在httpd.conf配置文件中开启...

2309
来自专栏zhisheng

ELK 实时日志分析平台环境搭建

简单介绍 ELK(ElasticSearch, Logstash, Kibana),三者组合在一起搭建实时的日志分析平台,目前好多公司都是这套! Elastic...

31411
来自专栏CSDN技术头条

资源控制在大数据和云计算平台中的应用

本文针对大数据平台中资源控制这个层面来详细介绍资源控制在不同操作系统上的具体技术实现,以及大数据平台和资源控制的集成。

6398
来自专栏技术翻译

分析R中的Elasticsearch数据

您可以在任何可以安装R和Java的计算机上使用纯R脚本和标准SQL访问Elasticsearch数据。您可以使用适用于Elasticsearch的CData J...

2333
来自专栏运维小白

Linux基础(day42)

11.14/11.15 Apache和PHP结合 配置httpd支持php目录概要 httpd主配置文件/usr/local/apache2.4/conf/ht...

2297
来自专栏Debian社区

Debian 9.3上安装和配置 Observium 监控平台

Observium是一个免费的开源网络管理和监控工具,可用于监控所有的网络设备。 它是用PHP编写的,使用SNMP从连接的设备收集数据并使用Web界面监视它们。...

1561
来自专栏老马寒门IT

Postman 接口测试神器

官方 github 地址: https://github.com/postmanlabs

4691
来自专栏小狼的世界

Filebeat+Logstash+ElasticSearch+Kibana搭建Apache访问日志解析平台

对于ELK还不太熟悉的同学可以参考我前面的两篇文章ElasticSearch + Logstash + Kibana 搭建笔记、Log stash学习笔记(一)...

1451
来自专栏Felix的技术分享

《一个操作系统的实现》笔记(2)--保护模式

3908
来自专栏coding

win10下配置linux子系统

2017

扫码关注云+社区

领取腾讯云代金券