./configure --prefix=/usr/local/php --with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-fpm --enable-sockets \
--enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
--with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt=/usr/local/libmcrypt \
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 \
--enable-maintainer-zts
make && make install
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php/etc/php-fpm.conf
sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' /usr/local/php/etc/php-fpm.conf
sed -i 's/pm.max_children = 5/pm.max_children = 300/g' /usr/local/php/etc/php-fpm.conf
sed -i 's/pm.start_servers = 2/pm.start_servers = 10/g' /usr/local/php/etc/php-fpm.conf
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 10/g' /usr/local/php/etc/php-fpm.conf
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 50/g' /usr/local/php/etc/php-fpm.conf
service php-fpm start
mysql部分
rpm -e --nodeps mariadb-libs
groupadd -r mysql
useradd -r -g mysql -s /bin/false -M mysql
tar zxf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql/
ln -s /usr/local/mysql/bin/* /usr/local/bin
cat >> /etc/my.cnf << EOF
[client]
socket=/usr/local/mysql/data/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
pid-file=/usr/local/mysql/data/mysql.pid
server_id=1
socket=/usr/local/mysql/data/mysql.sock
log-error=/usr/local/mysql/data/mysql.err
EOF
mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig on mysqld
systemctl daemon-reload
systemctl start mysqld
memcache部分
tar zxf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable/
./configure && make&& make install
tar zxf memcached-1.4.33.tar.gz
cd memcached-1.4.33/
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local
make && make install
vi ~/.bash_profile
MEMCACHED_HOME=/usr/local/memcached
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$MEMCACHED_HOME/lib
memcached -d -m 2048 -l 192.168.154.131 -p 11211 -u root -c 10240 -P /usr/local/memcached/memcached.pid
firewall-cmd --permanent --add-port=11211/tcp
firewall-cmd --reload
在php上
加载memcache.so(使php作为memcache的客户端)
tar zxf memcache-3.0.8.tgz
cd memcache-3.0.8/
/usr/local/php/bin/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-20131226/;记住这个路径,需要加载到php的配置文件中。
vim /etc/php.ini
##查找extension并在对应位置添加
extension=/usr/local/php/lib/php/extensions/no-debug-zts-20131226/memcache.so
##在末尾添加
session.save_handler = memcache
session.save_path = "tcp://192.168.154.131:11211?persistent=1&weight=1&timeout=1&retry_interval=15"
service php-fpm restart
在nginx上
编写php测试页面。vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
(成功表示php上安装好了memcache.so)
编写memcache测试页面。vim /usr/local/nginx/html/test.php