Lammp安装过程
Lammp安装过程
-1 建设环境
<VirtualHost *:80>
DocumentRoot "/www/magedu.com"
ServerName magedu.com
ServerAlias www.magedu.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/magedu.com/$1
<Directory "/www/magedu.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
add命令格式(添加一个缓存):add keyname flag timeout datasize --flag标示号 timeout存储时间s datasize字段长度
pm.min_spare_servers = 2 空闲时保留的最小工作线程
pm.max_spare_servers = 8 空闲时保留的最大工作线程
- 创建mysql数据库的lvm环境
创建lv逻辑卷
新安装一个硬盘25G sdb
#fdisk /dev/sdb
#pvcreate /dev/sdb1
#vgcreate vgmysql /dev/sdb1
#lvcreate -L 20G -n lvmysql vgmysql
#vim /etc/fstab
/dev/mapper/vgmysql-lvmysql /mydata/data ext4 defaults 0 0
#mkdir /mydata
#mount -a
#mkdir /mydata/data
#cd /mydata && chown -R mysql:mysql data && chmod -R 770 data
- 安装repo环境
#vim /etc/yum.repos.d/fedora.repo
[fedora_epel]
name=fedora_epel
baseurl=http://mirror.sohu.com/fedora-epel/6Server/x86_64/
gpcheck=0
#yum repolist
- 安装开发环境包
#yum groupinstall "Desktop Platform Development"
-2 编译httpd
- 开始编译:
#tar xf httpd-***.tar.gz
#cd httpd-***
#./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
主目录位置:/usr/local/apache
配置文件位置:若已经安装过httpd的话,则--sysconfdir=/etc/httpd+版本号
apr-util位置:/usr/local/apr-util
apr位置:/usr/local/apr
- 编译过程中,可能会出现的问题:apr-util/apr/pcre没有安装,则安装对应的软件即可
- apr软件安装
-
- ./configure --prefix=/usr/local/apr && make && make install
- apr-util软件安装
- ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
- pcre直接通过yum install pcre-devel安装
- httpd启动和配置文件
#vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
#. /etc/profile.d/httpd.sh
启动脚本,这里借用rpm包的启动脚本(也可以直接通过/usr/local/apache/bin/apachectl控制)
#vim /etc/rc.d/init.d/httpd
#vim /etc/rc.d/init.d/httpd
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
#chkconfig --add httpd
#chkconfig httpd on
修改配置文件,启用最基本的httpd,并测试
#vim /etc/httpd/httpd.conf
修改配置文件,启用最基本的httpd,并测试
#vim /etc/httpd/httpd.conf
ServerName www.example.com:80 //Servername和/etc/hosts名字最好相同
Directoryindex index.html
- 关于php-fcgi的修改(若没有启用php-fcgi,则不需此步)[需要配合php编译中的php-fcgi参数]
-
- 修改httpd配置文件,启动httpd代理模块和fcgi模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
-
- 添加文件格式
AddType application/x-httpd-php .php
AddType application/x-httpd-php-sources .phps
-
- 添加php支持页
DirectoryIndex index.php
-
- 修改虚拟主机
ProxyRequests Off 关闭正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
这里的/path/to/document_root是网站根路径
2.4版本中,vhost启用前,先开启主配置文档中的Include /etc/httpd/extra/httpd-vhosts.conf
-
-
- 示例:
-
DocumentRoot "/www/magedu.com"
ServerName magedu.com
ServerAlias www.magedu.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/magedu.com/$1
<Directory "/www/magedu.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
-4 mysql编译(这里采用二进制包)
- 解压,赋予权限:
#ln -sv /usr/local/mysql-*** /usr/local/mysql
#useradd -r mysql
#cd /usr/local/mysql
#chown -R root:mysql .
权限非常重要
- 复制、修改配置文件
#cd support-files
#mv /etc/my.cnf /etc/my.cnf.bak
#cp my.large.cnf /etc/my.cnf
#vim /etc/my.cnf
在[mysql]标签下添加数据库目录路径,默认mysql的socket文件在/tmp/mysql.sock
datadir = /mydata/data
basedir = /usr/local/mysql
#修改线程(修改为物理cpu核心的2倍)
thread_concurrency = 2
basedir = /usr/local/mysql
#修改线程(修改为物理cpu核心的2倍)
thread_concurrency = 2
- 复制脚本文件
#cp mysql.server /etc/rc.d/init.d/mysqld
#chkconfig --add mysqld
#chkconfig mysqld on
- 库/头/环境变量设置
#ln -sv /usr/local/mysql/include /usr/include 有时候不可以,则用下面命令
ln -sv /usr/local/mysql/include/* /usr/local/include [加载php的pdo-mysql的时候需要此步骤]
#vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
#ldconfig -v | grep mysql
#vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
#. /etc/profile.d/mysql.sh
- 初始化msyql数据库
#cd /usr/local/mysql/scripts
#./mysql_install_db --user=mysql --datadir=/mydata/data --basedir=/usr/local/mysql
报错:/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:安装libaio-devel和libaio包
#chown -R mysql:mysql /mydata/data
#chmod -R 700 /mydata/data
#./mysql_install_db --user=mysql --datadir=/mydata/data --basedir=/usr/local/mysql
报错:/usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决:安装libaio-devel和libaio包
#chown -R mysql:mysql /mydata/data
#chmod -R 700 /mydata/data
- 授权httpd可以远程登录mysql(mysql单独分离则需此步骤)[远程授权,还需要配合php中的PDO-mysql模块]
#mkdir /mydata/data/dbname
#chown -R mysql:mysql /mydata/data/dbname
#chmod -R 700 /mydata/data/dbname
#mysqladmin -uroot password 123456
#mysql -uroot -p123456
>GRANT ALL PRIVILEGES ON dbname.* TO 'admin'@'http_ip' IDENTIFIED BY 'password' [with grant option];
>FLUSH PRIVILEGES;
#chown -R mysql:mysql /mydata/data/dbname
#chmod -R 700 /mydata/data/dbname
#mysqladmin -uroot password 123456
#mysql -uroot -p123456
>GRANT ALL PRIVILEGES ON dbname.* TO 'admin'@'http_ip' IDENTIFIED BY 'password' [with grant option];
>FLUSH PRIVILEGES;
将http_ip和password和http_ip替换成对应的数据
授权admin账户在http_ip端登录mysql,并授权可以在dbname数据库操作的权限
-5 memcached缓存安装[需要配合php的memcache模块]
- 安装libevent
# tar xf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21
# ./configure --prefix=/usr/local/libevent
# make && make install
# echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
# ldconfig -v | grep libevent
# cd libevent-2.0.21
# ./configure --prefix=/usr/local/libevent
# make && make install
# echo "/usr/local/libevent/lib" > /etc/ld.so.conf.d/libevent.conf
# ldconfig -v | grep libevent
- 安装配置memcached
# tar xf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install
启动脚本创建及修改
#vim /etc/profile.d/memcached.sh 创建环境变量
export PATH=/usr/local/memcached/bin:$PATH
#cp scripts/memcached.sysv /etc/rc.d/init.d/memcached
#chmod +x /etc/rc.d/init.d/memcached
#vim /etc/rc.d/init.d/memcached 内含启动时所用账户/内存大小
添加. /etc/profile.d/memcached.sh 添加环境变量 --默认启动脚本会去/bin下找memcached,故需在启动脚本中加入
修改USER=root 修改启动账户
#mkdir /var/run/memcached 创建pid路径
# cd memcached-1.4.15
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install
启动脚本创建及修改
#vim /etc/profile.d/memcached.sh 创建环境变量
export PATH=/usr/local/memcached/bin:$PATH
#cp scripts/memcached.sysv /etc/rc.d/init.d/memcached
#chmod +x /etc/rc.d/init.d/memcached
#vim /etc/rc.d/init.d/memcached 内含启动时所用账户/内存大小
添加. /etc/profile.d/memcached.sh 添加环境变量 --默认启动脚本会去/bin下找memcached,故需在启动脚本中加入
修改USER=root 修改启动账户
#mkdir /var/run/memcached 创建pid路径
- 启动memcached
- 测试
add命令格式(添加一个缓存):add keyname flag timeout datasize --flag标示号 timeout存储时间s datasize字段长度
get命令格式(获取一个缓存):get keyname
如:添加
add mykey 0 10 12 --add添加
Hello world! --输入12字节的存储信息
如:获取
add mykey 0 10 12 --add添加
Hello world! --输入12字节的存储信息
如:获取
get mykey --get获取
VALUE mykey 0 12
Hello world!
END
VALUE mykey 0 12
Hello world!
END
退出telnet
ctrl+]
\q
-6 php编译
- 进入安装目录,并编译安装
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --enable-fpm --enable-fpm --with-http_stub_status_module
此处php的mysql环境所需要的库和头可以直接调用mysql二进制安装包的文件,即将第四步的安装包解压至http端的/usr/local/,并改名mysql,之后进行第四步的库/头/环境变量设置ln -sv /usr/local/mysql/include/* /usr/local/include
-
- --with-mcrypt 加密工具(libmcrypt,mhash),phpmyadmin需要
- --with-apxs2 apache钩子,意思就是将php改成模块化
- --enable-maintainer-zts 表明支持apache_mpm的worker和event(若apache是prefork,则不需添加)
- --enable-fpm 使php支持fastcgi模式(若php不工作在fcgi模式下,则不需添加)
- --with-config-file-scan-dir=/etc/php.d 表明php在读取配置文件的时候,同时读取php.d下的*.ini额外配置文件,一般模块配置文件存放此处
- 复制配置文件
#cp php.ini-production /etc/php.ini
#mkdir /etc/php.d
#mkdir /etc/php.d
- 关于php-fcgi的修改(若没有启用php-fcgi,则不需此步)[需要配合httpd服务,且需要修改httpd配置]:
-
- 复制php源码目录中的启动脚本
#cp sapi/fpm/init.d.php-fpm到/etc/rc.d/init.d/php-fpm 并添加进chkconfig
#chkconfig --add php-fpm
#chkconfig php-fpm on
#chmod u+x /etc/rc.d/init.d/php-fpm
#chkconfig --add php-fpm
#chkconfig php-fpm on
#chmod u+x /etc/rc.d/init.d/php-fpm
如果想实现daemon的效果,则需要修改启动文件,加入以下指令
首行加入[ -f /etc/rc.d/init.d/function ] && . /etc/rc.d/init.d/function
在case $1 in
start)
daemon ***
在case $1 in
start)
daemon ***
-
- 复制配置文件
#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
pidfile pid路径,默认路径是/usr/local/php/var/run/php-fpm,此处如果修改到其他位置,可能会因为权限问题无法创建,导致php-fpm无法启动
error_log 错误日志路径
pm.max_children = 50 每个线程最大请求
pm.start_servers = 5 启动时创建的工作线程 pm.min_spare_servers = 2 空闲时保留的最小工作线程
pm.max_spare_servers = 8 空闲时保留的最大工作线程
listen 监听的ip和端口
- 关于php加速器xcache(可不安装,建议安装)
-
- 进入xcache安装包,执行phpize程序,以来识别xcache
cd /xcache
/usr/local/php/bin/phpize
-
- 编译
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
安装完成后,会出现
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
-
- 配置文件
#cp xcache.ini /etc/php.d
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
-
- 测试
#service php-fpm restart
#php -v
看是否存在xcache模块
- 关于php与远程mysql相连(若http与mysql同一台设备,则无需此步)[需要配合mysql远程授权]
-
- 进入pdo_mysql安装包,执行phpize程序,以来识别pdo
cd /pdo_mysql
/usr/local/php/bin/phpize
-
- 编译
./configure --with-pdo-mysql=/usr/local/mysql --with-php-config=/usr/local/php/bin/php-config
安装完成后,会出现
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
注意:若报mysql.h找不到,则在本地环境下安装mysql二进制包,并建立头文件的链接
-
- 配置文件
[pdo_mysql]
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/pdo_mysql.so-
- service php-fpm restart
- 关于php与memcached相连(原因在于memcached属于半客户端、半服务端,所用如果php不支持,是无法缓存php程序的)[需要配合memcached服务器]
-
- 编译安装模块memcache(是memcache而不是memcached)
#phpize
#./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
#make
#make install
安装完成后,会出现
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
-
- 配置文件
[memcache]
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/memcache.so-
- service php-fpm restart
- 测试
<?php
$mem = new Memcache;$mem->connect("127.0.0.1", 11211) or die("Could not connect");$version = $mem->getVersion();echo "Server's version: ".$version."<br/>\n";$mem->set('hellokey', 'Hello World', 0, 600) or die("Failed to save data at the memcached server");echo "Store data in the cache (data will expire in 600 seconds)<br/>\n";$get_result = $mem->get('hellokey');echo "$get_result is from memcached server.";
?>
若输出如下信息,则表示安装成功:
Server's version: 1.4.15
Store data in the cache (data will expire in 600 seconds)Hello World is from memcached server.