打zZ~瞌睡 Menu

All items for July, 2016

CentOS源码编译安装Apache + PHP + MySQL

1. 安装编译器和库文件:

#有些是中途安装AMP的过程中发现没有安装,作为总结,写在最前边
sudo yum install -y cmake.x86_64 gcc-c++.x86_64 ncurses.x86_64 ncurses-devel.x86_64 libxml2-devel.x86_64 libcurl-devel.x86_64 libjpeg-turbo-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 autoconf.noarch

 

2. 安装MySQL
2.1 下载MySQL:可以在http://dev.mysql.com/downloads/mysql/查看对应版本

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.50.tar.gz

2.2 创建mysql用户

groupadd mysql
useradd -r -g mysql mysql

2.3 创建mysql目录

mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/data

tar -zxvf mysql-5.5.50.tar.gz
cd mysql-5.5.50
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install

cp support-files/my-medium.cnf /etc/my.cnf

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
/usr/local/mysql/bin/mysqld_safe &
cd /usr/local/mysql/ #重要,否则会报 Can't find a 'mysql' client in PATH or ./bin
bin/mysql_secure_installation

 

3. 安装apache

wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.31.tar.gz
wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz
wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz
wget http://downloads.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.zip

tar -zxvf apr-1.5.2.tar.gz
./configure && make && make install

tar -zxvf apr-util-1.5.4.tar.gz
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install

unzip pcre-8.39.zip
./configure --prefix=/usr/local/pcre && make && make install

tar -zxvf httpd-2.2.31.tar.gz
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-included-apr --enable-deflate --enable-expires --enable-headers --enable-rewrite --enable-so
make && make install

 

4. 安装PHP

wget http://am1.php.net/get/php-5.5.38.tar.gz/from/this/mirror
tar -zxvf php-5.5.38.tar.gz
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib --with-curl --enable-exif --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-gettext --with-mhash --enable-mbstring --with-mysql --with-mysqli --enable-zip --with-pear
make && make install
sudo cp php.ini-production /usr/local/php5/lib/php.ini

修改/usr/local/apache2/conf/httpd.conf,添加:

AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

重启apache:

sudo /usr/local/apache2/bin/apachectl start|graceful

 

5. 安装xcache

wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
tar -zxvf xcache-3.2.0.tar.gz
cd xcache-3.2.0
/usr/local/php5/bin/phpize
./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=/usr/local/php5/bin/php-config
make && make install

建立缓存文件

touch /tmp/xcache
chmod 0777 /tmp/xcache

拷贝xcache管理后台到可访问目录

cp -R htdocs/ /var/www/html/xcache

生成密码

http://{ip}/xcache/cacher/mkpassword.php
Username: xcache
Password: 123456
记住生成后的密码,替换下边的{generated password}

将以下代码写入/usr/local/php/lib/php.ini

[xcache-common]
extension = xcache.so

[xcache.admin]
xcache.admin.enable_auth = On
xcache.admin.user = "xcache"
xcache.admin.pass = "{generated password}"

[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size= 64M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

[xcache.coverager]
xcache.coverager = On
xcache.coveragedump_directory = ""

访问管理地址查看缓存使用情况

http://{ip}/xcache