专栏首页CaiRuiLAMP=Linux+Apache+Mysql+Php

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 条评论
登录 后参与评论

相关文章

  • LAMP实战之构建博客网站

    1、首先检查LAMP环境 [root@cairui htdocs]# ps -ef | grep httpd php 13160 1 0 M...

    用户1173509
  • 临时和永久关闭Selinux

    临时关闭: [root@localhost ~]# getenforce Enforcing [root@localhost ~]# setenforce 0 ...

    用户1173509
  • linux+Nginx+Mysql+Php

    LNMP简介 LAMP(Linux apache mysql php)---比较早的web服务。 LNMP(Linux nginx mysql php)---比...

    用户1173509
  • 麦思博思考问题之道

    经理人是否高效,取决于他的思考方式。从麦肯锡的思维方式,你可以学会用更积极有效的方法来解决问题,摘要…

    白凡
  • Android分区

    实现手机必需的通信功能,大家通常所的刷RADIO就是刷写modem分区,在所有适配的ROM中这部分是不动,否则会造成通话不稳定

    233333
  • CICS配置管理TIPS

    其中 backend_server 是后端服务器的 IP 地址。 添加以下行以编辑 /etc/services 文件:

    gigiwangs
  • Laravel中实现微信QQ等第三方登录

    Laravel 是 Taylor Otwell 开发的一款基于 PHP 语言的 Web 开源框架,采用了 MVC 的架构模式,在 2011 年 6 月正式发布了...

    蓝默空间
  • 【Vue 学习笔记 一、Vue开发环境搭建】

      1.首先安装Nodejs (因为我的系统是Windows的所以就选择第一个了,这个看个人的开发环境)

    梅花
  • Eclipse中快捷键的使用

    用户5166556
  • 一张图搞懂Spring bean的完整生命周期。

    一张图搞懂Spring bean的生命周期,从Spring容器启动到容器销毁bean的全过程,包括下面一系列的流程,了解这些流程对我们想在其中任何一个环节怎么操...

    Java技术栈

扫码关注云+社区

领取腾讯云代金券