LAMP简介
LAMP(Linux- Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构。LAMP具有通用、跨平台、高性能、低价格的 优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。
二 Mysql 配置
1首先下载mysql-5.5.33包组(mariadb-5.5.36-linux-x86_64.tar.gz),然后解压mariadb-5.5.36-linux-x86_64.tar.gz到/usr/local
[root@localhost ~]# tar xfmariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
2 准备数据存放的文件系统
a 新建一个sda3
[root@localhost~]# fdisk /dev/sda
Command (m for help): n
Commandaction
e extended
p primary partition (1-4)
p
Partitionnumber (1-4): 3
Firstcylinder (7859-13054, default 7859):
Usingdefault value 7859
Lastcylinder, +cylinders or +size{K,M,G} (7859-13054, default 13054): +20G
Command(m for help): t
Partitionnumber (1-4): 3
Hex code(type L to list codes): 8e (文件系统为LVM)
Changedsystem type of partition 3 to 8e (Linux LVM)
Command (m for help): w
b读入磁盘中
[root@localhost ~]# kpartx -af /dev/sda
device-mapper: reload ioctl on sda1failed: Invalid argument
create/reload failed on sda1
device-mapper: reload ioctl on sda2failed: Invalid argument
create/reload failed on sda2
device-mapper: reload ioctl on sda3failed: Invalid argument
create/reload failed on sda3
[root@localhost ~]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3 (表示已经读入到磁盘中)
c 新建逻辑卷,并将其挂载至特定目录,此处目录设置为/mydata
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# vgcreate myvg/dev/sda3
Volume group "myvg" successfully created
[root@localhost ~]# lvcreate -L 10G -nmydata myvg
Logical volume "mydata" created
[root@localhost ~]# mke2fs -t ext4 -LMYDATA -b 4096 -m 3 /dev/myvg/mydata
并且能开机挂载,编辑fastab文件
/dev/mapper/vg0-root / ext4 defaults 1 1
UUID=90ebd4cf-95c1-4338-b0dd-19b2b1cb943d/boot ext4 defaults 1 2
/dev/mapper/vg0-usr /usr ext4 defaults 1 2
/dev/mapper/vg0-var /var ext4 defaults 1 2
/dev/mapper/vg0-swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=MYDATA /mydata ext4 defaults 0 0
(开机挂载)
d 新建用户以安全方式运行进程,并创建链接
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd-g mysql -r mysql
[root@localhost ~]# idmysql
uid=496(mysql)gid=493(mysql) groups=493(mysql)
[root@localhost ~]#chown -R mysql.mysql /mydata/data/
[root@localhost ~]# ll -a/mydata/data/
total 8
drwxr-xr-x 2 mysql mysql4096 Aug 11 20:15 .
先进入/usr/local目录下
[root@localhost local]# ln-sv mariadb-5.5.36-linux-x86_64 mysql
lrwxrwxrwx 1 root root 27 Aug 11 20:18mysql -> mariadb-5.5.36-linux-x86_64
e 为mysql提供主配置文件
cd/usr/local/mysql/
mkdir /etc/mysql创建一个目录,因为在/etc下有个my.cnf
cpsupport-files/my-large.cnf /etc/mysql/my.cnf
vim/etc/mysql/my.cnf
port = 3306
socket =/tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
datadir = /mydata/data (指定mysql数据文件的存放位置)
开始初始化
[root@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
(此处必须在 mysql 目录下,要在scripts初始化,会报错)
f 为mysql提供sysv服务脚本
[root@localhostmysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
然后添加到服务列表中
[root@localhost mysql]# chkconfig --addmysqld
[root@localhost mysql]# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
启动服务
root@localhost mysql]# service mysqld start
Starting MySQL... [ OK ]
[root@localhost mysql]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:52971 *:*
LISTEN 0 128 :::50732 :::*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 *:111 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:6010 *:*
LISTEN 0 128 ::1:6010 :::*
LISTEN 0 50 *:3306 *:* (3306端口已启动)
设置权限
[root@localhostmysql]#chmod +x /etc/rc.d/init.d/mysqld
g 编辑环境变量
[root@localhost~]# vim /etc/profile.d/mysql.sh
exportPATH=/usr/local/mysql/bin:$PATH
h导出头文件和库文件
ln -sv /usr/local/mysql/include /usr/include/mysql
[root@localhost~]# vim /etc/ld.so.conf.d/mysql.conf (新建)
/usr/local/mysql/lib
让系统重新载入
[root@localhost ~]#ldconfig -v | grep mysql
/usr/local/mysql/lib:
libmysqld.so.18 -> libmysqld.so.18
libmysqlclient.so.18 ->libmysqlclient_r.so.18.0.0
/usr/lib64/mysql:
libmysqlclient.so.16 -> libmysqlclient.so.16.0.0
libmysqlclient_r.so.16 -> libmysqlclient_r.so.16.0.0
三 Apache2.4.9 编译安装
首先检测pcre-devel "Development tools" "Server Platform Development" 这个三个包组装了没
yum -y
install
pcre-devel
yum -y groupinstall
"Development tools"
yum -y groupinstall
"Server Platform Development
然后编译安装apr
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
在编译apr-util
# tar xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
编译安装httpd2.4.9
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
(为了不和系统的httpd冲突,我们指定其安装路径为/usr/local/apache,配置文件装到/etc/httd24中,同时一会儿的服务也要改为httpd24 )
修改httpd的主配置文件,设置其Pid文件的路径
[root@web httpd24]
# vim /etc/httpd24/httpd.conf
#添加下面一行
PidFile
"/var/run/httpd.pid"
提供SysV服务脚本/etc/rc.d/init.d/httpd,内容
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
3 编译安装php-5.4.26
先解决依赖关系,不过首先要解决yum源问题,
# yum -y groupinstall "X Software Development"
编译安装php-5.4.26
# tar xf php-5.4.26.tar.bz2
# cd php-5.4.26
./configure --prefix=/usr/local/php5 --with-mysql=--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysqli=--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
(因为本机是没有装mysql,所以文中红色部分是本机没装mysql的编译)
# make
# make install
然后为
为php提供配置文件:
# cp php.ini-production /etc/php.ini
配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid
然后重启服务
# service php-fpm start
查看端口
# netstat -tnlp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 689/php-fpm
配置http-2.4.9
在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的 扩充,因此,这两个模块都要加载
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虚拟主机支持使用fcgi
1)要使用虚拟主机,首先要关闭中心主机,再开启虚拟主机的模块儿,也是在/etc/httpd24/httpd.conf中
在相应的虚拟主机中添加类似如下两行。
ProxyRequests Off 关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
然后编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
然后测试
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。