搭建LNMP环境过程及可能遇到的问题

来源:互联网 发布:clearlist 函数c语言 编辑:程序博客网 时间:2024/06/05 14:39

搭建LNMP环境可以采用一键安装的方法或者单独安装各服务、当然还有很多种搭建方式。

下面就以单独安装各服务为例 简述下安装过程及安装过程中可能遇到的问题

1、新装好的服务器需要先关闭防火墙

1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off2) 即时生效,重启后失效 开启: service iptables start 关闭: service iptables stop 

2、安装nginx

yum install nginx

3、修改nginx配置文件

修改nginx配置文件后,可能重启出现报错:nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)解决办法:vim /etc/nginx/conf.d/default.conf将listen       80 default_server;listen       [::]:80 default_server;改为:listen       80;#listen       [::]:80 default_server;


4、解决nginx无法解析php文件问题

修改文件中对应的php配置部分location ~ \.php$ {root /home/www/wwwroot;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}

5、安装PHP(此处安装的为PHP7)

rpm 安装 Php7 相应的 yum源CentOS/RHEL 7.x:# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmCentOS/RHEL 6.x:# rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpmyum安装php7# yum install php70w php70w-opcache 安装其他插件(选装)php70wphp70w-bcmath php70w-cliphp70w-commonphp70w-dba php70w-devel php70w-embeddedphp70w-enchant php70w-fpm php70w-gd php70w-imap php70w-interbasephp70w-intl php70w-ldap php70w-mbstring php70w-mcrypt php70w-mysqlphp70w-mysqlndphp70w-odbcphp70w-opcachephp70w-pdo php70w-pdo_dblib php70w-pear php70w-pecl-apcu php70w-pecl-imagick php70w-pecl-xdebug php70w-pgsql php70w-phpdbg php70w-process php70w-pspell php70w-recode php70w-snmp php70w-soap php70w-tidy php70w-xml php70w-xmlrpc 


6、改nginx配置文件让PHP的请求转发到php-fpm所绑定的ip和端口上

vi /etc/nginx/conf.d/default.conf                 #行[37-43]去掉#号:location ~ \.php$ {      root /usr/share/nginx/html;      fastcgi_pass 127.0.0.1:9000;      fastcgi_index index.php;      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;      include fastcgi_params;      } 

7、安装MySQL

yum -y install mysql mysql-server    #不需要提示安装查看mysql  mysql-server是否存在:which mysql                   #查看mysql是否存在which mysqld_safe         #查看mysqld_safe是否存在-------------------------------------------------------mysql_install_db          #mysql初始化,在mysql中建立起系统表mysqld_safe &            #启动mysqlps -ef | grep mysqld    #mysqld 是否存在----------------------------------------------mysql -uroot              #链接进入mysql数据库修改mysql密码在mysql系统外,使用mysqladmin# mysqladmin -u root -p password "test123"Enter password: 【输入原来的密码】修改刷新MySQL权限mysql->GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;mysql->flush privileges;

8、配置nginx 支持pathinfo   目录vi /etc/nginx/conf.d/default.conf

典型配置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;}修改第1,6行,支持pathinfolocation ~ \.php(.*)$ { # 正则匹配.php后的pathinfo部分    root html;    fastcgi_pass   127.0.0.1:9000;    fastcgi_index  index.php;    fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;    fastcgi_param PATH_INFO $1; # 把pathinfo部分赋给PATH_INFO变量    include        fastcgi_params;}重启服务


9、VIM编辑器乱码问题

vim下 vimrc文件添加setcoding=utf-8






阅读全文
0 0
原创粉丝点击