首先需要明确,LNMP是指Linux、Nginx、MySQL、PHP的组合。安装LNMP环境后,可能需要安装一些PHP扩展模块来增强PHP的功能。这里以eAccelerator、xCache、memcached、imageMagick和ion为例,详细讲解以下完整攻略:
安装eAccelerator
- 下载eAccelerator
shell
wget https://github.com/eaccelerator/eaccelerator/tarball/master -O eaccelerator.tar.gz
- 解压eAccelerator
shell
tar zxvf eaccelerator.tar.gz
- 进入目录并编译
shell
cd eaccelerator-eaccelerator-xxxxxx
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
- 安装eAccelerator
shell
make install
- 修改PHP配置文件
在php.ini文件中加入以下内容:
ini
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/eaccelerator.so"
eaccelerator.shm_size=64
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.keys="accelerator_php"
然后重启PHP服务即可。
安装xCache
- 下载xCache
shell
wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
- 解压xCache
shell
tar zxvf xcache-3.2.0.tar.gz
- 进入目录并编译
shell
cd xcache-3.2.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make
- 安装xCache
shell
make install
- 修改PHP配置文件
在php.ini文件中加入以下内容:
```ini
[xcache-common]
;; general settings
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache]
;; ini settings
xcache.size = 32M
xcache.shm_scheme = "mmap"
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
;; user-specific settings
xcache.var_size = 32M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 0
xcache.var_namespace_mode = 0
xcache.var_namespace = ""
```
然后重启PHP服务即可。
安装memcached
- 安装libevent
shell
wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar zxvf libevent-2.1.12-stable.tar.gz
cd libevent-2.1.12-stable
./configure --prefix=/usr/local/libevent
make && make install
- 安装memcached
shell
wget https://memcached.org/latest
tar zxvf memcached-latest.tar.gz
cd memcached-xxxx
./configure --with-libevent=/usr/local/libevent --prefix=/usr/local/memcached
make && make install
- 修改PHP配置文件
在php.ini文件中加入以下内容:
ini
[memcached]
extension=memcached.so
memcached.use_sasl = 1
memcached.sess_lock_wait_min = 1000
memcached.sess_lock_max_wait_time = 5000
memcached.sess_lock_max_wait_time_ms = 5000
memcached.sess_lock_wait_dither = 1
memcached.sess_lock_expire = 0
memcached.sess_lock_max_concurrency = 100
session.save_handler=memcached
session.save_path="localhost:11211"
memcached.sess_prefix="memc.sess.key."
memcached.sess_consistent_hash=1
memcached.sess_binary_protocol=0
memcached.sess_expire = 180
然后重启PHP服务即可。
安装imageMagick
- 下载imageMagick
shell
wget https://www.imagemagick.org/download/releases/ImageMagick-7.1.0-7.tar.gz
- 解压imageMagick
shell
tar zxvf ImageMagick-7.1.0-7.tar.gz
cd ImageMagick-7.1.0-7
- 编译并安装
shell
./configure --prefix=/usr/local/imagemagick
make
make install
- 安装php imagick扩展
shell
/usr/local/php/bin/pecl install imagick
- 修改PHP配置文件
在php.ini文件中加入以下内容:
```ini
[imagick]
extension=imagick.so
imagick.locale_fix=0
imagick.progress_monitor=0
[ImageMagick]
extension=imagick.so
ImageMagick.locale_fix=0
ImageMagick.progress_monitor=0
```
然后重启PHP服务即可。
安装ion
- 下载ioncube
shell
wget https://www.ioncube.com/php-7.4.0-beta-loaders/ioncube_loaders_lin_x86-64.tar.gz
- 解压ioncube
shell
tar zxvf ioncube_loaders_lin_x86-64.tar.gz
- 复制ioncube扩展到PHP扩展目录
shell
cp ioncube/ioncube_loader_lin_7.x.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
- 修改PHP配置文件
在php.ini文件中加入以下内容:
ini
[ioncube]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/ioncube_loader_lin_7.x.so"
ioncube.loader_threads="1"
ioncube.debug_level="0"
然后重启PHP服务即可。
这就是eAccelerator、xCache、memcached、imageMagick和ion的完整攻略,如果按照以上步骤执行,应该可以成功安装PHP扩展模块。但是需要注意的是,每种PHP扩展模块的安装过程可能略有不同,需要根据具体情况进行相应的修改。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:LNMP安装php扩展模块(eAccelerator、xCache、memcached、imageMagick和ion) - Python技术站