1、啊,好久没写博客了,之前一直是个小小的PHP程序员,本以为PHP开发就是天天写几行代码就Ok的,实则不然呐,工欲善其事,必先利其器啊,LNMP就是一个PHP开发的必备的东东啊,,当然如果你不了解N(nginx),则A(apache)就是你的首选!!
一、当然L(linux)系统,这个嘛,大家都会安装的,就不说了(现在开源事业做的这么火,找个mirror安装就Ok了嘛)
二、N的安装:
1、首选看你安装的是哪个版本的Linux系统,俺的是Centos6.3(安装省心,简单),当然有的朋友一想,咦?是Centos的嘛,当然就用yum安装就好喽,嗯,没错,用yum安装前,首先得了解一下“源”的概念,不然yum install后,安装的服务都是过时的,如果要安装最新的软件版本,就需要添加源,源这个东西嘛,就像apple越狱后,下载免费软件时,得添加源一样,,以添加nginx源为例:在/etc/yum.repos.d/目录下,建立nginx.repo,写入
1 [nginx]
2 name=nginx repo
3 baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
4 gpgcheck=0
5 enabled=1
~
保存退出
2、安装两个基本源:a、rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
b、rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
3、用yum install 安装nginx,命令:yum install nginx pcre -y (y参数是不提示源检索出的信息)
4、设置开机自启动:chkconfig --level 3 nginx on
5、要了解nginx配置文件的机制:nginx有两个目录存储配置文件
a、/etc/nginx/nginx.conf文件(主配置文件)
user root;(<span style="color:#ff0000;"><strong>此处需要注意,默认情况下user apache,因此要改成root</strong></span>)
3 worker_processes 1;
4
5 error_log /var/log/nginx/error.log warn;(<span style="color:#ff0000;"><strong>所有错误日志全部存储在这里,不分是不是http请求过来的</strong></span>)
6 #pid /var/run/nginx.pid;
7
8
9 events {
10 worker_connections 1024;
11 }
12
13
14 http {
15 include /etc/nginx/mime.types;
16 default_type application/octet-stream;
17
18 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19 '$status $body_bytes_sent "$http_referer" '
20 '"$http_user_agent" "$http_x_forwarded_for"';
21
22 access_log /var/log/nginx/access.log main;(<span style="color:#ff0000;"><strong>此处只存储http请求时的访问日志</strong></span>)
23
24 sendfile on;
25 #tcp_nopush on;
26
27 keepalive_timeout 65;
28
29 #gzip on;
30
31 include /etc/nginx/conf.d/*.conf;
32 }
b、/etc/nginx/conf.d/*.conf文件(个人认为是虚拟目录配置文件,主配置文件加载此目录下所配置.conf的配置文件)
server {
2
3 listen 80;
4 server_name inner-sample-test.com;(<span style="color:#ff0000;"><strong>虚拟域名</strong></span>)
5 root /home/jim/www;(<span style="color:#ff0000;"><strong>文档根目录,注意:root一定要放在server中,此处路径与nginx通过php-fpm与php通讯相关,非常重要</strong></span>)
6
7 #charset koi8-r;
8 #access_log /var/log/nginx/log/host.access.log main;
9
10 location / {
11 index index.php index.html index.htm;
12 }
13
14 #error_page 404 /404.html;
15
16 # redirect server error pages to the static page /50x.html
17 #
18 error_page 500 502 503 504 /50x.html;
19 location = /50x.html {
20 root /usr/share/nginx/html;
21 }
22
23 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
24 #
25 #location ~ \.php$ {
26 # proxy_pass http://127.0.0.1;
27 #}
28
29 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
30 #
31 location ~ \.php$ {
32 fastcgi_pass 127.0.0.1:9000;(<span style="color:#ff0000;"><strong>php-fpm配置【fastcgi:common gateway interface】</strong></span>)
33 fastcgi_index index.php;
34 include fastcgi_params;
35 }
36
37 # deny access to .htaccess files, if Apache's document root
38 # concurs with nginx's one
39 #
40 #location ~ /\.ht {
41 # deny all;
42 #}
43 }
44
fastcgi-param文件内容
[jim@localhost nginx]$ vim fastcgi_params
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
保存退出
6、service nginx start
7、如果各项配置都无问,把documentRoot目录给个大一点权限
三、M的安装
1、安装M时,首先要知道两个东东,mysql与mysqld (前者可理解为mysql客户端,后者是服务端),很相似memcache与memcached (d是管理用的)
2、还是以Centos6.3为例
a、
## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
b、
yum --enablerepo=remi,remi-test list mysql mysql-server(<span style="color:#ff0000;"><strong>注意:有个remi-test源参</strong></span>)
c、
yum --enablerepo=remi,remi-test install mysql mysql-server<span style="font-family: Arial, Helvetica, sans-serif;">(</span><span style="font-family: Arial, Helvetica, sans-serif; color: rgb(255, 0, 0);"><strong>注意:有个remi-test源参</strong></span><span style="font-family: Arial, Helvetica, sans-serif;">)</span>
d、
/etc/init.d/mysqld start ## use restart after update
## OR ##
service mysqld start ## use restart after update
chkconfig --levels 235 mysqld on
e、安装完mysql后,为了安全起见,请运
/
usr
/
bin
/
mysql_secure_installation
根据提示进行相应操作
f、如果想要远程连接mysql,请使用grant命令
四、安装P
yum --enablerepo=remi install php php-cli php-mysql php-common php-gd php-fpm php-mbstring php-pdo php-xml php-pecl-memcache php-pecl-redis
注:php-common,这个东东很重要,很多php扩展已集成在里边,不需要再去手动编译很多.so去挂接php
总结:就说一点最重要的,LNMP安装是有先后顺序的,原因不多说,自已实践去,顺序规则是:PHP最后安装,其它可随意