LNMP安装配置
mysql : http://dev.mysql.com/downloads/mysql/
php :http://cn.php.net/get/php-5.3.6.tar.gz/from/cn2.php.net/mirror
nginx :http://nginx.org/download/nginx-1.0.13.tar.gz
注意:mysql下载类型选择source code,最后一个tar.gz包
如果安装包是tar.bz2格式的,请用 tar -jxvf xxx.tar.bz2命令解压
安装过程中可能会遇到提示有些软件或者lib未找到的错误,像libncurses5-dev, chkconfig, libiconv, libmcrypt, pcre, libjpeg, libpng, cmake等,需要自己下载手动安装
安装CMAKE
下载:http://www.cmake.org/cmake/resources/software.html
#tar -zxvf cmake-2.8.7.tar.gz #./bootstrap #./configure #make && make install
报错提示: Cannot find appropriate Makefile processor on this system.
解决 : yum install make
安装MYSQL
版本:5.5.19
#mkdir /usr/local/mysql #mkdir /usr/local/mysql/data #groupadd mysql #useradd -g mysql mysql #chown -R mysql /usr/local/mysql #chown -R mysql.mysql /usr/local/mysql/data #tar -zxvf mysql-5.5.19.tar.gz #cd mysql-5.5.19 #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_unicode_ci \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DSYSCONFDIR=/etc \ -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \ -DMYSQL_TCP_PORT=3306 #make && make install #cd ../mysql #chmod +w . #mkdir -p /var/mysql #mkdir -p /var/mysql/data #mkdir -p /var/mysql/log #chown -R mysql.mysql /var/mysql #cp support-files/my-large.cnf /etc/my.cnf #cp support-files/mysql.server /etc/init.d/mysqld #./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --defaults-file=/etc/my.cnf
安装完成之后,启动mysql服务
#/etc/init.d/mysqld start
修改mysql的root用户密码
#mysql -u root -p mysql>use mysql mysql>UPDATE user SET password=PASSWORD('123456') WHERE user='root' ->\g mysql>\q #/etc/init.d/mysqld restart
将mysql加入开机启动项
#chkconfig --add mysqld #chkconfig --level 345 mysqld on
安装PHP
版本:5.3.6
#tar -zxvf php-5.3.6.tar.gz #cd php-5.3.6 #./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr/lib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --with-freetype-dir=/usr/local/freetype --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear #make && make install
安装完成之后配置PHP,包括php.ini, php-fpm.conf等
#cp php.ini-production /usr/local/php/etc/php.ini #ln -s /usr/local/php/sbin/php-fpm /etc/init.d/ #cp /usr/local/php/etc/php-fpm.conf-default /usr/local/php/etc/php-fpm.conf
最后修改php.ini和php-fpm.conf配置项
安装nginx
版本:1.0.13
#tar -zxvf nginx-1.0.13.tar.gz #cd nginx-1.0.13 #./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module #make && make install
安装完成之后修改/usr/local/nginx/conf/nginx.conf配置文件
打开nginx.conf文件,找到
#location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}将前面的#去掉
location 定义文件类型, \.php$ 代表所有以 php 作为文件后缀的文件类型.
root 定义php项目文件的物理路径,例如:将html修改为/usr/local/website
fastcgi_index 定义 php 文件类型中的默认索引页
fastcgi_param SCRIPT_FILENAME 定义了页面请求参数, 如客户端需要访问 /t1.php 则会自动读取 /www/t1.php文件, 如客户端访问 / 则自动读取 /www/index.php 文件,/scripts需要改为php项目文件的物理路径
include 定义fastcgi 配置信息将会被保存到 /usr/local/nginx/conf/fastcgi_params 文件中
配置php-fpm的启动、停止、重启shell
#vi /sbin/php-fpm输入以下内容并保存退出
#! /bin/sh start () { /usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf echo 'success:php-fpm start!' exit 0 } stop () { kill -INT `cat /usr/local/php/var/run/php-fpm.pid` echo 'success:php-fpm stop!' exit 0 } restart () { kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` echo 'success:php-fpm restart!' exit 0 } case $1 in start) start ;; stop) stop ;; restart) restart ;; esac
更改执行权限
#chmod +x /sbin/php-fpm
现在我们可以直接在terminal中操作php-fpm
#php-fpm start #php-fpm restart #php-fpm stop