有段时间没有安装过LNMP环境了,昨天按照宴哥的方法(源地址)又安装了一次,然后自己也做了点修改整理了一份存档。
1 安装nginx
mkdir -p /Data/tgz cd /Data/tgz yum install wget yum install pcre yum install openssl* yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make yum -y install gd gd2 gd-devel gd2-devel /usr/sbin/groupadd www /usr/sbin/useradd -g www www ulimit -SHn 65535 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz tar zxvf pcre-8.32.tar.gz cd pcre-8.32 ./configure --prefix=/Data/apps/pcre make && make install cd ../ wget http://nginx.org/download/nginx-1.5.2.tar.gz tar zxvf nginx-1.5.2.tar.gz cd nginx-1.5.2 ./configure --user=www --group=www --prefix=/Data/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/Data/tgz/pcre-8.32 --with-http_realip_module --with-http_image_filter_module make make install cd ../
2 安装Mysql
wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz cd mysql-5.6.10 ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --localstatedir=/usr/local/mysql/var --with-tcp-port=3306 --without-debug --enable-assembler --sysconfdir=/etc --with-mysqld-user=mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,utf8 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-pthread --enable-thread-safe-client --with-big-tables --with-plugins=all make make install /usr/sbin/groupadd mysql /usr/sbin/useradd -g mysql mysql mkdir -p /Data/data/mysql/data yum install libaio /Data/apps/mysql/scripts/mysql_install_db --basedir=/Data/apps/mysql --datadir=/Data/data/mysql/data --user=mysql sed -i "/usr/local/mysql/Data/apps/mysql" /Data/apps/mysql/bin/mysqld_safe #配置文件 cp ./support-files/my-default.cnf /etc/my.cnf vi /etc/my.cnf basedir = /Data/apps/mysql datadir = /Data/data/mysql/data #mysql启动脚本 可以使用诸如 service mysqld start|restart|stop命令管理mysql cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld vi /etc/rc.d/init.d/mysqld #修改basedir、datadir #修改mysql初始化root账户密码 实际mysql的root账户没有密码 设定一个密码 /server/apps/mysql/bin/mysqladmin -u root -p password
3 安装PHP依赖库
mkdir -p /Data/apps/libs/ wget http://www.ijg.org/files/jpegsrc.v9.tar.gz tar zxvf jpegsrc.v9.tar.gz cd jpeg-9/ ./configure --enable-shared --enable-static make make install cd ../ wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz tar zxvf libpng-1.6.2.tar.gz cd libpng-1.6.2/ ./configure make make install cd ../ wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz tar zxvf freetype-2.4.12.tar.gz cd freetype-2.4.12/ ./configure make make install cd ../ wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure --prefix=/Data/apps/libs make make install cd libltdl/ ./configure --enable-ltdl-install make make install cd ../../ tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make make install cd ../ vi /etc/ld.so.conf 添加: /Data/apps/libs/lib 然后: ldconfig tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ export LD_LIBRARY_PATH=/usr/local/lib:LD_LIBRARY_PATH touch malloc.h ./configure make make install cd ../
4 编译安装PHP
wget http://cn2.php.net/distributions/php-5.5.8.tar.gz tar zxvf php-5.5.8.tar.gz cd php-5.5.8/ export LIBS="-lm -ltermcap -lresolv" export DYLD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64" export LD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64" ./configure --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/Data/apps/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts make make install cp php.ini-development /Data/apps/php/etc/php.ini cd ../ ln -s /Data/apps/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib mv /Data/apps/php/etc/php-fpm.conf.default /Data/apps/php/etc/php-fpm.conf
5 设置php-fpm启动脚本 详细设置
6 nginx 配置设置
将默认的注释去掉 /script 修改为$document_root
即如下
location ~ \.php$ {
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;
}