CentOS7 Apache+Mysql+PHP+Memcached安装

一、安装apache2.4


yum install apache


二、安装mysql


1)安装camek
yum install cmake
sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper
yum -y install  gcc gcc-c++ gcc-


wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
tar -zxvf mysql-5.6.25.tar.gz 
cd mysql-5.6.25
cmake .
make
sudo make install


mysql将会安装到/usr/local/mysql路径。


添加mysql用户和组:
sudo groupadd mysql
sudo useradd -r -g mysql mysql


修改目录和文件权限,安装默认数据库:
cd /usr/local/mysql
sudo chown -R mysql .
sudo chgrp -R mysql .
sudo scripts/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R mysql data




启动mysql:


CentOS7自带MariaDB的支持,/etc下默认存在my.cnf文件干扰mysql运行,需要先删掉
cd /etc
sudo rm -fr my.cnf my.cnf.d




再/etc下重建my.cnf文件,内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
 
[mysqld]
 
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
 
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
 
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = /data/mysql/data
# port = .....
# server_id = .....
# socket = .....
 
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
 
max_connection = 10000
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
 
#binary log 
log-bin = mysql-bin
binlog_format = mixed
expire_logs_day = 30
 
#slow query log 
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 3
log-queries-not-using-indexes
log-slow-admin-statements





启动mysql:
sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &


编辑/etc/rc.d/rc.local文件,添加mysql的开机启动命令:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
sudo chmod a+x /etc/rc.d/rc.local




修改mysql root密码:
/usr/loca/mysql/bin/mysql -uroot
use mysql;
UPDATE user SET password = PASSWORD('test2015') WHERE user = 'root';
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'stcm2015';
FLUSH PRIVILEGES;




三、安装apache






centos7.0安装完毕后,通过yum 安装的apache版本是 2.4.6的。
于是先停止了httpd服务,然后卸载了默认安装的版本。
systemctl stop httpd.service


rpm -qa|grep httpd #查看apache包,然后删除
rpm -e httpd-2.2.15-15.el6_2.1.x86_64 #不过要先把依赖apache的包删除
或者
yum remove httpd
yum list|grep httpd #查看apache包名,例如httpd.x86_64
yum erase httpd.x86_64         #相关依赖包自动会被删除


开始安装2.4.10
wgethttp://mirrors.cnnic.cn/apache/httpd/httpd-2.4.10.tar.gz
wget http://apache.dataguru.cn/apr/apr-1.5.1.tar.gz
wget http://apache.dataguru.cn/apr/apr-util-1.5.3.tar.gz
cd apr-1.5.1
./configure --prefix=/usr/local/apr
Make
Make install
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
Make
Make install


tar –xvf httpd-2.4.10.tar.gz
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd2 --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 --enable-proxy --enable-proxy-fcgi


# 参数依次是: httpd安装路径  httpd配置文件存放路径  启用模块化方式  启用ssl安全连接
# 启用cgi脚本功能  启用url重写  启用服务器压缩  启用正则表达式支持    apr安装路径 
# apr util安装路径   启用常用模块以确保apache正常工作    将多进程模型非静态化 
# 启用事件异步模型
Make
Make install


vi /usr/local/conf/httpd.conf
servername 名字改好


启动服务器:
/usr/local/apache/bin/apachectl 


启动服务如果报错:
H01177: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded??
grep 'slotmem' /usr/local/conf/httpd.conf 
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
/usr/local/apache/bin/apachectl start


常见的错误 这种只有mini安装会出现 一般大部分菜鸟都不会安装devel的包
. 代码如下:
checking for OpenSSL version >= 0.9.7… FAILED
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl… configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
解决办法
. 代码如下:
yum install openssl-devel
yum update openssl




四、安装php5.6


安装php前要先安装libxml2和libcurl,如下:


1)libxml2
wget https://git.gnome.org/browse/libxml2/snapshot/libxml2-2.9.1.zip
unzip libxml2-2.9.1.zip
cd libxml2-2.9.1
./autogen.sh
./configure --help
./configure --enable-shared --with-python=no
make
make install


2)libcurl
wget http://curl.haxx.se/download/curl-7.38.0.zip
unzip curl-7.38.0.zip
cd curl-7.38.0
./configure --enable-shared
make 
make install


安装php5.6:
cd php-5.6.10
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs 
make
make install






五、安装memcached


tar -zxvf memcached-1.4.10.tar.gz 
cd memcached-1.x.x 
./configure  #到这一步报错了如下:
#configure: error: libevent is required.  You can get it from http://www.monkey.org/~provos/libevent/
Memcache用到了libevent这个库用于Socket的处理,所以还需要安装libevent。


wget  http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz
tar zxvf  libevent-2.0.10-stable.tar.gz
./configure -prefix=/usr/local/libevent
make &
make install


测试libevent是否安装成功
ls -al /usr/lib | grep libevent




下面接着安装memcache
./configure –with-libevent=/usr/local/libeven
测试是否成功安装memcached
 ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 203321 01-05 08:03 /usr/local/bin/memcached
说明安装成功


memcached的基本设置:
1.启动Memcache的服务器端:
# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid


-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址192.168.0.200,
-p是设置Memcache监听的端口,我这里设置了12000,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid,


2.如果要结束Memcache进程,执行:


# kill `cat /tmp/memcached.pid`


也可以启动多个守护进程,不过端口不能重复。


3.重启apache


安装Memcache的PHP扩展
1.在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。
2.安装PHP的memcache扩展


wget http://pecl.php.net/get/memcache-2.2.6.tgz 
tar vxzf memcache-2.2.6.tgz
cd memcache-2.2.6.tgz
/usr/local/php/bin/phpize
./configure –enable-memcache –with-php-config=/usr/local/php/bin/php-config –with-zlib-dir
make
make install


3.上述安装完后会有类似这样的提示:


Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/


4.把php.ini中的extension_dir = “./”修改为
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”


5.添加一行来载入memcache扩展:extension=memcache.so


Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?php
$mem = new Memcache;
$mem->connect(”127.0.0.1″, 11211);
$mem->set(’key’, ‘This is a test!’, 0, 60);
$val = $mem->get(’key’);
echo $val;
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值