本文一步一步描述如何使用yum安装LNMP,
系统环境: centos 最新版(CentOS 5.4) 主机ip: 192.168.0.1
PHP: 5.1.6
MYSQL:5.077
Nginx:0.6.39
第一步:升级系统到最新版本
yum -y update
第二步:安装mysql数据库
yum -y install mysql mysql-server
chkconfig --level 235 mysqld on
sed -i 's#old_passwords=1#old_passwords=1\nskip-innodb\nskip-bdb\n#' /etc/my.cnf
/etc/init.d/mysqld start
mysqladmin -u root password mysqlrootpasswd
第三步:安装nginx
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
rpm -Uvh epel-release-5-3.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
rm -rf epel-release-*
yum -y install nginx
chkconfig --level 235 nginx on
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
修改/etc/nginx/nginx.conf配置文件
vi /etc/nginx/nginx.conf
内容如下:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain text/css text/xml application/x-javascript application/atom+xml application/rss+xml;
gzip_vary on;
server_name_in_redirect off; #自动添加斜线”/”语句
include /etc/nginx/conf.d/*.conf;
}
新建/etc/nginx/conf.d/http.conf文件,默认网站(使用ip访问的网站)
vi /etc/nginx/conf.d/http.conf
内容如下:
server {
listen 80;
server_name _;
# error_log /usr/share/nginx/html/log/error.log;
# access_log /usr/share/nginx/html/log/access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
启动nginx
/etc/init.d/nginx start
第四步:安装php CGI
wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rm -rf rpmforge-release-*
yum -y install lighttpd-fastcgi php-cli php-mysql php-gd php-mbstring php-mcrypt php-eaccelerator php-pecl-memcache
chkconfig --del httpd
chkconfig --del lighttpd
echo 'cgi.fix_pathinfo = 1' >> /etc/php.ini
启动php cgi
echo "/usr/bin/spawn-fcgi -s /tmp/php-cgi.sock -C 2 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid " >> /etc/rc.local
/usr/bin/spawn-fcgi -s /tmp/php-cgi.sock -C 2 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
或通过另外一种方式启动(建议使用第一种方式)
echo "/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid" >> /etc/rc.local
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
第五步:建立测试页面
chmod -R 777 /var/lib/php/session/
echo "" > /usr/share/nginx/html/phpinfo.php
第六步:安装phpmyadmin
cd /usr/share/nginx/html
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/2.11.10/phpMyAdmin-2.11.10-all-languages-utf-8-only.tar.gz
tar zxvf phpMyAdmin-2.11.10-all-languages-utf-8-only.tar.gz
mv phpMyAdmin-2.11.10-all-languages-utf-8-only phpmyadmin
cd phpmyadmin
cp config.sample.inc.php config.inc.php
sed -i "/blowfish_secret/s/''/'test99'/" ./config.inc.php
第七步:验证
访问
http://192.168.0.1/phpinfo.php #访问phpinfo信息
http://192.168.0.1/phpmyadmin #访问phpmyadmin数据库管理程序