LAMP的web站点搭建(一)

搭建LAMP

一个完整的LAMP的web架构由linux + http + mysql + php四部分搭建组成。

一、编译安装apache,使用httpd-2.4.6版

1、准备编译安装环境,解决依赖关系;

[root@localhost ~]# yum gruoplist
[root@localhost ~]# yum gruopinstall "Development tools" "Server Platfrom Development"

2、下载搭建httpd的软件包,apr、apr-util、httpd;

[root@localhost ~]# lftp 172.16.0.1
lftp 172.16.0.1:~> cd pub/Sources/sources/httpd/
lftp 172.16.0.1:/pub/Sources/sources/httpd> ls
.......
lftp 172.16.0.1:/pub/Sources/sources/httpd> mget apr-1.4.6.tar.bz2 apr-util-1.5.2.tar.bz2 httpd-2.4.6.tar.bz2
6428879 bytes transferred                             
Total 3 files transferred


[root@localhost ~]# ls
anaconda-ks.cfg    apr-util-1.5.2.tar.bz2  install.log
apr-1.4.6.tar.bz2  httpd-2.4.6.tar.bz2     install.log.syslog

3、编译安装apr;

[root@localhost ~]# tar xf apr-1.4.6.tar.bz2
[root@localhost ~]# cd apr-1.4.6
[root@localhost apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.6]# make && make install

4、编译安装apr-util;

[root@localhost ~]# tar xf apr-util-1.5.2.tar.bz2
[root@localhost ~]# cd apr-util-1.5.2
[root@localhost apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.5.2]# make && make install

5、编译安装httpd;

l

[root@localhost ~]# tar xf httpd-2.4.6.tar.bz2
[root@localhost ~]# cd httpd-2.4.6
[root@localhost httpd-2.4.6]# yum -y install pcre-devel
[root@localhost httpd-2.4.6]# yum -y install openssl-devel
[root@localhost httpd-2.4.6]# ./configure --prefix=/usr/local/apache  --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
[root@localhost httpd-2.4.6]# make && make install

6、提供httpd Sysv 服务脚本,修改httpd的配置文件,设置其pid文件的路径;

[root@localhost httpd-2.4.6]# cp build/rpm/httpd.init /etc/rc.d/init.d/httpd
cp: overwrite `/etc/rc.d/init.d/httpd'? y
[root@localhost httpd-2.4.6]# vim /etc/rc.d/init.d/httpd
prog=httpd
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
RETVAL=0
# check for 1.3 configuration
check13 () {
        CONFFILE=/usr/local/apache/conf/httpd.conf


[root@localhost httpd-2.4.6]# vim /usr/local/apache/conf/httpd.conf ServerName 172.16.20.5:80

7、为httpd服务添加环境变量;

[root@localhost ~]# echo "PATH=/usr/local/apache/bin/:$PATH" > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh

8、将httpd服务加入列表,将其启动。

[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# service httpd start
Starting httpd:                                            [  OK  ]

二、编译安装mysql,使用mysql-5.5.28

1、准备编译安装环境,创建用于存储数据的文件系统,并下载解压mysql的通用二进制软件包;

[root@localhost ~]# mkdir -pv /mysql/mydata
mkdir: created directory `/mysql'
mkdir: created directory `/mysql/mydata'
[root@localhost ~]# lftp 172.16.0.1
lftp 172.16.0.1:~> cd pub/Sources/6.x86_64/mysql/
lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> ls
-rw-r--r--    1 0        0        186839926 Aug 22 04:37 mysql-5.5.33-linux2.6-x86_64.tar.gz
-rw-r--r--    1 0        0        307062424 Aug 22 05:15 mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz
lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> get mysql-5.5.33-linux2.6-x86_64.tar.gz
186839926 bytes transferred in 21 seconds (8.31M/s)


[root@localhost ~]# tar  xf mysql-5.5.33-linux2.6-x86_64.tar.gz  -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache  apr-util  etc    include  lib64    mysql-5.5.33-linux2.6-x86_64  share
apr     bin       games  lib      libexec  sbin                          src
[root@localhost local]# ln -sv mysql-5.5.33-linux2.6-x86_64/ mysql
`mysql' -> `mysql-5.5.33-linux2.6-x86_64/'
[root@localhost local]# cd mysql
[root@localhost mysql]# ls
bin      data  include         lib  mysql-test  scripts  sql-bench
COPYING  docs  INSTALL-BINARY  man  README      share    support-files

2、创建mysql用户,并以安全方式运行;

[root@localhost mysql]# chown -R mysql:mysql *
[root@localhost mysql]# ll
total 200
drwxr-xr-x  2 mysql mysql   4096 Sep 11 22:32 bin
-rw-r--r--  1 mysql mysql  17987 Jul 15 20:01 COPYING
drwxr-xr-x  3 mysql mysql   4096 Sep 11 22:33 data
drwxr-xr-x  2 mysql mysql   4096 Sep 11 22:32 docs
drwxr-xr-x  3 mysql mysql   4096 Sep 11 22:33 include
-rw-r--r--  1 mysql mysql 134493 Jul 15 20:01 INSTALL-BINARY
drwxr-xr-x  3 mysql mysql   4096 Sep 11 22:33 lib
drwxr-xr-x  4 mysql mysql   4096 Sep 11 22:33 man
drwxr-xr-x 10 mysql mysql   4096 Sep 11 22:33 mysql-test
-rw-r--r--  1 mysql mysql   2496 Jul 15 20:01 README
drwxr-xr-x  2 mysql mysql   4096 Sep 11 22:33 scripts
drwxr-xr-x 27 mysql mysql   4096 Sep 11 22:33 share
drwxr-xr-x  4 mysql mysql   4096 Sep 11 22:33 sql-bench
drwxr-xr-x  3 mysql mysql   4096 Sep 11 22:33 support-files
[root@localhost ~]# useradd mysql
[root@localhost ~]# chown -R mysql:mysql /mysql/mydata
[root@localhost ~]# chmod -R 755 /mysql/mydata/

3、编译安装mysql,并进行初始化;

[root@localhost mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/mydata

4、为mysql服务添加环境变量;

[root@localhost mysql]# echo "PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysqld.sh
[root@localhost mysql]# source /etc/profile.d/mysqld.sh


5、为mysql服务提供主配置文件;

[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[root@localhost mysql]# vim /etc/my.cnf
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
datadir = /mysql/mydata

6、为mysql服务提供Sysv服务脚本;

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

7、赋权服务脚本,将服务加入列表,并启动mysql服务。

[root@localhost mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost mysql]# service mysqld start
Starting MySQL..                                           [  OK  ]

三、编译安装php-fpm,使用php 5.4.19

1、基于开发编译环境,还需要额外解决相关的关系;

[root@localhost ~]# yum -y install libxml2-devel curl-devel bzip2-devel libmcrypt libmcrypt-devel

2、下载并编译安装php;

[root@localhost ~]# lftp 172.16.0.1
lftp 172.16.0.1:/pub/Sources/sources/php> mget php* xcache-3.0.3.tar.bz2
[root@localhost ~]# tar xf php-5.4.19.tar.bz2
[root@localhost ~]# cd php-5.4.19
[root@localhost php-5.4.19]# ./configure --prefix=/usr/local/php  --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl  --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc  --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --enable-maintainer-zts --enable-fpm
[root@localhost php-5.4.19]# make and make install

3、为php服务提供主配置文件;

[root@localhost php-5.4.19]# cp php.ini-production /etc/php.ini
[root@localhost php-5.4.19]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@localhost php-5.4.19]# cd /etc/rc.d/init.d/
[root@localhost init.d]# cp init.d.php-fpm php-fpm
[root@localhost php-5.4.19]# cd /usr/local/php/etc/
[root@localhost etc]# cp  php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vim php-fpm.conf
listen = 172.16.20.5:9000

4、为php服务添加环境变量

[root@localhost php-5.4.19]#  echo "PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH" >/etc/profile.d/php-fpm.sh
[root@localhost php-5.4.19]# source /etc/profile.d/php-fpm.sh

5、编辑apache的主配置文件,以apache支持php


[root@localhost ~]# vim /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
.............
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

6、将php-fpm服务加入列表,并启动php-fpm服务;

[root@localhost ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost ~]# chkconfig --add php-fpm
[root@localhost ~]# chkconfig php-fpm on
[root@localhost ~]# chkconfig --list php-fpm
php-fpm         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# service php-fpm start
Starting php-fpm  done

7、重新启动httpd服务,并配置相关页面文件,访问相关web页面进行测试。


本文出自 “丿Sky 灬ONE PEICE” 博客,转载请与作者联系!

你可能感兴趣的:(Web,lamp,站点搭建)