您好,登錄后才能下訂單哦!
LAMP簡介
LAMP(Linux- Apache-MySQL-PHP)網(wǎng)站架構(gòu)是目前國際流行的Web框架,該框架包括:Linux操作系統(tǒng),Apache網(wǎng)絡(luò)服務(wù)器,MySQL數(shù)據(jù)庫,Perl、PHP或者Python編程語言,所有組成產(chǎn)品均是開源軟件,是國際上成熟的架構(gòu)框架,很多流行的商業(yè)應(yīng)用都是采取這個架構(gòu)。LAMP具有通用、跨平臺、高性能、低價格的 優(yōu)勢,因此LAMP無論是性能、質(zhì)量還是價格都是企業(yè)搭建網(wǎng)站的首選平臺。
二 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 準(zhǔn)備數(shù)據(jù)存放的文件系統(tǒng)
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 (文件系統(tǒng)為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 (表示已經(jīng)讀入到磁盤中)
c 新建邏輯卷,并將其掛載至特定目錄,此處目錄設(shè)置為/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 新建用戶以安全方式運行進(jìn)程,并創(chuàng)建鏈接
[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 .
先進(jìn)入/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創(chuàng)建一個目錄,因為在/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數(shù)據(jù)文件的存放位置)
開始初始化
[root@localhostmysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
(此處必須在 mysql 目錄下,要在scripts初始化,會報錯)
f 為mysql提供sysv服務(wù)腳本
[root@localhostmysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
然后添加到服務(wù)列表中
[root@localhost mysql]# chkconfig --addmysqld
[root@localhost mysql]# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
啟動服務(wù)
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端口已啟動)
設(shè)置權(quán)限
[root@localhostmysql]#chmod +x /etc/rc.d/init.d/mysqld
g 編輯環(huán)境變量
[root@localhost~]# vim /etc/profile.d/mysql.sh
exportPATH=/usr/local/mysql/bin:$PATH
h導(dǎo)出頭文件和庫文件
ln -sv /usr/local/mysql/include /usr/include/mysql
[root@localhost~]# vim /etc/ld.so.conf.d/mysql.conf (新建)
/usr/local/mysql/lib
讓系統(tǒng)重新載入
[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
(為了不和系統(tǒng)的httpd沖突,我們指定其安裝路徑為/usr/local/apache,配置文件裝到/etc/httd24中,同時一會兒的服務(wù)也要改為httpd24 )
修改httpd的主配置文件,設(shè)置其Pid文件的路徑
[root@web httpd24]
# vim /etc/httpd24/httpd.conf
#添加下面一行
PidFile
"/var/run/httpd.pid"
提供SysV服務(wù)腳本/etc/rc.d/init.d/httpd,內(nèi)容
#!/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
而后為此腳本賦予執(zhí)行權(quán)限:
# chmod +x /etc/rc.d/init.d/httpd
加入服務(wù)列表:
# chkconfig --add httpd
3 編譯安裝php-5.4.26
先解決依賴關(guān)系,不過首先要解決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腳本,并將其添加至服務(wù)列表:
# 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
然后重啟服務(wù)
# 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以后已經(jīng)專門有一個模塊針對FastCGI的實現(xiàn),此模塊為mod_proxy_fcgi.so,它其實是作為mod_proxy.so模塊的 擴(kuò)充,因此,這兩個模塊都要加載
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虛擬主機支持使用fcgi
1)要使用虛擬主機,首先要關(guān)閉中心主機,再開啟虛擬主機的模塊兒,也是在/etc/httpd24/httpd.conf中
在相應(yīng)的虛擬主機中添加類似如下兩行。
ProxyRequests Off 關(guān)閉正向代理
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
然后測試
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。