LAMP(linux+apache+mariadb+php)环境搭建

Centos6 

ip 192.168.75.156

安装httpd2.4
# yum groupinstall "Development Tools" "Server Platform Development" -y
# yum install pcre-devel
下载 (apr-1.5.0.tar.bz2/apr-util-1.5.3.tar.bz2/httpd-2.4.33.tar.gz/phpMyAdmin-4.4.14.1-all-languages.zip)安装包
解压apr包,进入apr-1.5.0目录
# ./configure --prefix=/usr/local/apr

#make && make install
解压apr-util,进入apr-util目录
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr; make && make install
解压httpd2.4,进入httpd2.4目录
# ./configure --prefix=/usr/local/apache --sysconf=/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=prefork

--preifx: 安装目录

--sysconf:配置 文件目录

--enable-so:支持动态卸载模块

--enable-ssl:启用ssl模块,需要安装ipenssl ,openssl-devel

--enable-cgi:启用cgi

--enable-rewrite:URL重写

--with-zlib:数据报文发送时的压缩库

--with-pcre:url重写时用到的正则表达式分析器,需要安装pcre-devel

--with-apr:apr路径

 --with-apr-util:apr-util 路径

--enable-modules:编译的模块

--enable-mpms-shared=all --with-mpm=prefork 动态加载mpm,并指明使用prefork模式

# make && make install
编辑服务脚本cd /etc/rc.d/init.d/
cp httpd httpd24
vim httpd24如下
# 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/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
# chkconfig --add httpd24
# chkconfig httpd24 on  开机启动
# chkconfig --list httpd24

# hash -r 移除缓存
# vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH
# hash 检查环境变量是否生效
# httpd -t 检查语法 【如果检查是报错,AH00557: httpd: apr_sockaddr_info_get() failed for captain
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
,修改/etc/httpd24/http.conf文件, ServerName localhost:80】
# service httpd24 start 启动httpd24服务
# ss -tnl 查看80端口是否启动
安装mariadb:
下载mariadb安装包
# tar xf mariadb-5.5.60-linux-x86_64.tar.gz -C /usr/local
# mkdir -pv /mydata/data
# useradd -r mysql
# chown -R mysql.mysql /mydata/data
# cd /usr/local
# ln -sv mariadb-5.5.60-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql 安装
# mkdir /etc/mysql
# cp support-files/my-large.cnf /etc/mysql/my.cnf
# vim /etc/mysql/my.cnf 配置mysql配置文件
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
datadir = /mydata/data
innodb_file_per_table = on
skip_name_resolve = on
# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld 添加mysql服务
# chkconfig --add mysqld
# service mysqld start
# /usr/local/mysql/bin/mysql_secure_installation 安全初始化【新安装的mysql 存在匿名用户,密码为空,运行安全初始化,删除匿名用户,禁止管理员远程登录等】
安装php:
首先配置epel源,因为libmcrypt-devel是在epel源中
# yum install bzip2-devel libmcrypt-devel libxml2-devel
下载php安装包 www.php.net
# tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
# ./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
# make && make install [make -j4]
注意:php再编译过程中,不要修改http.conf文件,因为php编译会修改http.conf文件
编辑http.conf 添加下面内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

定位至DirectoryIndex index.html
DirectoryIndex index.php index.html
从安装包中copy php.ini-production 到php配置文件目录中
#cp /home/cp/rpmpkg/php-5.4.40/php.ini-production /etc/php.ini

## 重启httpd服务 service httpd24 restart ,如果重启失败,检查http.pid文件存放路径配置是否存在问题,
## 主配置文件中pid 会存在http安装目录下/usr/local/apache/logs
## 我们自己创建的服务脚本中pidfile设置成与主配置文件中相同 修改/etc/rc.d/init.d/httpd24
## pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
在/usr/local/apache/htdocs/目录下创建 index.php文件测试
$conn=mysql_connect('127.0.0.1','root','captain');
if ($conn)
echo "OK";
else
echo "not Ok";

phpinfo();
?>
访问 http://ip:port/index.php

部署phpmyadmin应用
下载phpmyadmin安装包-->解压,cp到http documentroo下,改名为pma ,然后cp config.sample.inc.php config.inc.php,并将其修改
添加内容
$cfg['blowfish_secret'] = 'hJuJK3UY8iZSgBC4ZmoCprFzn0nkbw';
然后为mysql管理员(等用户)添加密码
# /usr/local/mysql/bin/mysql
> use mysql
> UPDATE user SET password=PASSWORD('captain') WHERE User='root'
> SELECT User,Host,Password FROM user;
> flush privileges;
访问http://ip:port/pma

Xcache (php扩展,加速php)
下载xcache-3.2.0.tar.bz2安装包,解压并进入目录
再编译之前先运行 # /usr/local/php/bin/phpize 生成configure文件
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
cp xcache.ini /etc/php.d/
编辑/etc/php.d/xcache.ini文件
[xcache-common]
;; non-Windows example:
#此处目录为 再编辑(make & make installl)xcache时,显示的xcache.so的路径
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
;; Windows example:
; extension = php_xcache.dll

xcache.admin.enable_auth = Off
然后重启httpd24服务 service httpd24 restart
访问http://192.168.75.156/ 可以看到Xcache,说明安装成功
进行压力测试ab -c 20 -n 100 http://192.168.75.156/pma/index.php
效率大约提升3倍左右

fpm
删除原来的 php 安装包文件,重新解压
cd /home/cp/rpmpkg/php-5.4.40
# ./configure --prefix=/usr/local/php5 --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 --enable-fpm --with-mcrypt --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2
# make && make install
# mkdir /etc/php5{,.d}
为php提供配置文件
# cp php.ini-production /etc/php5/php.ini
# 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 --list php-fpm
为php-fpm提供配置文件进入到 /usr/local/php5/etc 目录
# cp php-fpm.conf.default php-fpm.conf 然后编辑/usr/local/php5/etc/php-fpm.conf
1)pool definitions配置里面
listen = 0.0.0.1:9000 允许远程主机访问
2)修改pm参数
pm.max_children=50
pm.start_servers=5
pm.min_spare_servers=2
pm.max_spare_server=8
3)修改pid路径
pid = /usr/local/php5/var/run/php-fpm.pid
启动php-fpm
# service php-fpm start

参考:http://www.92csz.com/study/linux/16.htm

  https://www.cnblogs.com/apro-abra/p/4862285.html

  http://blog.51cto.com/5990383/1655276

转载于:https://www.cnblogs.com/cncaptain/p/9342481.html

你可能感兴趣的:(LAMP(linux+apache+mariadb+php)环境搭建)