LNMP的安装
安装环境
CentOS 6.5 64位
一、准备工作
1.关闭selinux
2.防火墙开启80和3306端口
3.下载软件包:nginx,mysql,php,pcre,cmake,libmcrypt,Zend Guard,GD库
4.安装编译工具及库文件
yum install make apr* autoconf automake curl-devel gcc gcc-c++ gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd gettext gettext-devel kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch
二、安装cmake
tar zxvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./configure --prefix=/usr/local/cmake
make && make install
vim /etc/profile
export PATH=$PATH:/usr/local/cmake/bin
source /etc/profile
三、安装mysql
groupadd mysql #创建mysql组
useradd -g mysql mysql -s /bin/false #创建mysql用户
mkdir -p /data/mysql #创建数据库目录
chown -R mysql:mysql /data/mysql #修改所有者
mkdir -p /usr/local/mysql #创建安装目录
cd /usr/local/src
tar zxvf mysql-5.6.15.tar.gz #解压mysql
cd mysql-5.6.15
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc #使用cmake编译
报错Could NOT find Curses
rm CMakeCache.txt
yum install ncurses-devel
yum install bison
重新编译
make && make install #编译安装
cd /usr/local/mysql
cp ./support-files/my-default.cnf /etc/my.cnf #拷贝配置文件
vim /etc/my.cnf #打开配置文件
datadir = /data/mysql #添加MySQL数据库路径,在 [mysqld] 部分增加
./scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成系统数据库
cp support-files/mysql.server /etc/rc.d/init.d/mysqld #加入系统启动文件
chmod 755 /etc/init.d/mysqld #添加权限
chkconfig mysqld on #开机启动
vim /etc/rc.d/init.d/mysqld #打开启动文件
basedir = /usr/local/mysql #MySQL程序安装路径
datadir = /data/mysql #MySQl数据库存放目录
service mysqld start #启动mysql
vim /etc/profile #打开系统文件
export PATH=$PATH:/usr/local/mysql/bin #添加环境变量
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql #添加链接
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now
mysql_secure_installation #设置mysql密码
/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码
四、安装pcre
cd /usr/local/src
mkdir /usr/local/pcre #创建安装目录
tar zxvf pcre-8.31.tar.gz
cd pcre-8.31
./configure --prefix=/usr/local/pcre #配置
make
make install
五、安装nginx
groupadd nginx #创建nginx组
useradd -g nginx nginx -s /bin/false #创建nginx用户
tar zxvf nginx-1.9.9.tar.gz #解压
cd nginx-1.9.9
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre=/usr/local/src/pcre-8.31 --without-http_memcached_module
make && make install #编译安装
/usr/local/nginx/sbin/nginx #启动nginx
mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi} #创建缺少文件夹
vim /etc/rc.d/init.d/nginx #创建启动文件
#!/bin/bash # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
chmod 755 /etc/rc.d/init.d/nginx #添加权限
chkconfig nginx on #开机启动
service nginx start #启动nginx
六、安装libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.8.tar.gz #解压
cd libmcrypt-2.5.8 #进入目录
./configure #配置
make #编译
make install #安装
七、安装gd
cd /usr/local/src
tar zxvf gd-2.0.35.tar.gz #解压
cd gd-2.0.35 #进入目录
./configure --enable-m4_pattern_allow --prefix=/usr/local/gd --with-jpeg=/usr/lib --with-png=/usr/lib --with-xpm=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib
make #编译
make install #安装
八、安装php
cd /usr/local/src
tar -zvxf php-5.3.16.tar.gz
cd php-5.3.16
mkdir -p /usr/local/php5 #建立php安装目录
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-freetype-dir=/usr/lib --with-iconv --with-zlib --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-ctype #配置
make #编译
make install #安装
cp php.ini-production /usr/local/php5/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.int #添加软链接
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
vim /usr/local/php5/etc/php-fpm.conf #编辑配置文件添加以下内容
user = nginx #设置php-fpm运行账号为www
group = nginx #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
cp /usr/local/src/php-5.3.16/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #设置开机启动
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig php-fpm on
vim /usr/local/php5/etc/php.ini
disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
date.timezone = PRC #设置时区
expose_php = OFF #禁止显示php版本的信息
short_open_tag = ON #支持php短标签
九、配置nginx支持php
vim /etc/nginx/nginx.conf
user nginx nginx;
index index.php index.html index.htm; #添加index.php
location ~ \.php$ { #取消FastCGI server部分location的注释
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
service nginx restart
十、配置php支持Zend Guard
安装Zend Guard
cd /usr/local/src
mkdir /usr/local/zend #建立Zend安装目录
tar xvfz ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz #解压安装文件
cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/zend/ #拷贝文件到安装目录
vi /usr/local/php5/etc/php.ini #编辑文件
在最后位置添加以下内容
[Zend Guard]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
十一、测试
rm -rf /usr/local/nginx/html/*
使用WinSCP工具把DedeCMS-V5.7-GBK-SP1\uploads文件夹里面的所有文件以二进制方式上传到/usr/local/nginx/html/目录
chown nginx.nginx /usr/local/nginx/html/ -R #设置目录所有者
chmod 700 /usr/local/nginx/html/ -R #设置目录权限
shutdown -r now
mysql -uroot -p #进入mysql控制台,提示输入MySQLroot密码
create database dedecms; #建立数据库
exit; #退出

浙公网安备 33010602011771号