首页 > 运维 > linux运维 > LAMP=Linux+Apache+Mysql+Php

LAMP=Linux+Apache+Mysql+Php

巴扎黑
发布: 2017-06-23 14:34:40
原创
2866 人浏览过

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

静态服务:

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

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

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

动态服务:

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

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

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

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

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

  b.配合nginxlighttpdphp守护进程模式,FCGI模式。

 

二、apache的安装

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

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

2.安装apache(地址上官网上找)

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

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

 

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/blog"

ServerName blog.etiantian.org

ErrorLog "logs/blog-error_log"

CustomLog "logs/blog-access_log" common

 

ServerAdmin 928939638@qq.com

DocumentRoot "/var/html/bbs"

ServerName bbs.etiantian.org

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

 

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 在最末行加入下面的内容:

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

以上配置是防止403出错,之后检查语法是否错误(有错误查看

 

修改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

创建mysqluseradd 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

phpinfo();

?>

 

 

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

 

vi /var/html/blog/index.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成功

以上是LAMP=Linux+Apache+Mysql+Php的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板