linux centos 安装lnmp

来源:互联网 发布:稀奇古怪有趣的软件 编辑:程序博客网 时间:2024/06/04 19:10

nginx安装

步骤一
安装前必备准备工作
1  yum install -y gcc-c++                       GCC编译器,可用来编译C语言程序,Nginx不会直接提供二进制可执行程序。

2  yum install -y pcre pcre-devel           PCRE库,该库支持正则表达式,比如rewrite重写功能

3  yum install -y zlib zlib-devel                zlib库,对HTTP包的内容做gzip的压缩

4  yum install -y openssl openssl-devel     openSSL开发库,如果我们的服务器不只是需要HTTP,还需要更安全的SSL协议上传输HTTP,那么就需要openssl。另外如果我们想使用md5、SH1等散列函数,那么也需要安装它。

步骤二
让nginx认识php,如下:
1. 编辑文件php.ini,在文件末尾添加cgi.fix_pathinfo = 1
2.修改/usr/local/nginx/conf/nginx.conf 添加如下代码

修改nginx配置文件,添加fastcgi支持

1、修改nginx.conf文件
vi /etc/nginx/nginx.conf
配置文件部分代码

路径是:/usr/share/nginx/html

  1. [...]
  2.     server {
  3.         listen       80;
  4.         server_name  _;
  5.         #charset koi8-r;
  6.         #access_log  logs/host.access.log  main;
  7.         location / {
  8.             root   /usr/share/nginx/html;
  9.             index  index.php index.html index.htm;
  10.         }
  11.         error_page  404              /404.html;
  12.         location = /404.html {
  13.             root   /usr/share/nginx/html;
  14.         }
  15.         # redirect server error pages to the static page /50x.html
  16.         #
  17.         error_page   500 502 503 504  /50x.html;
  18.         location = /50x.html {
  19.             root   /usr/share/nginx/html;
  20.         }
  21.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  22.         #
  23.         #location ~ \.php$ {
  24.         #    proxy_pass   http://127.0.0.1;
  25.         #}
  26.  
  27.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  28.         #
  29.         location ~ \.php$ {
  30.             root           /usr/share/nginx/html;
  31.             fastcgi_pass   127.0.0.1:9000;
  32.             fastcgi_index  index.php;
  33.             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  34.             include        fastcgi_params;
  35.         }
  36.         # deny access to .htaccess files, if Apache's document root
  37.         # concurs with nginx's one
  38.         #
  39.         location ~ /\.ht {
  40.             deny  all;
  41.         }
  42.     }
  43. [...]

判断nginx配置文件修改的正确性:/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

启动nginx
启动nginx命令:/usr/local/nginx/sbin/nginx

平滑重启nginx命令:/usr/local/nginx/sbin/nginx -s reload

平滑停止nginx信念:/usr/local/nginx/sbin/nginx -s quit
nginx配置文件位置:/usr/local/nginx/conf/nginx.conf

php安装

yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy php-common php-devel php-fpm,没有安装php-fpm,后来yum install php-fpm

开启php-fpm命令是:service php-fpm start

关闭php-fpm命令是:service php-fpm stop

mysql安装

#yum -y install mysql mysql-server mysql-devel 

配置mysql开机启动服务 

#chkconfig --add mysqld (在服务清单中添加mysql服务) 

#chkconfig mysqld on (设置mysql服务随开机启动) 

#service mysqld start (启动mysql服务) 

然后就可以登录mysql了,命令是:mysql -uroot -p ,无密码直接回车就成













0 0