Centos7yum安裝LNMP環境


  這次我們用下載yum源

  由於我們的環境采用的是centos7minal安裝,所以沒有配置很多東西,需要自己安裝一下.

 

#yum install -y wget
#cd /ect/yum.erpos.s/
#mkdir 1
#mv Cen* 1/
#wget httl://mirrors.aliyun.com/repo/Centos-7.repo
#yum clean all
#yum makecache

  由於現在yum源里沒有nginx,所以我們只能去nginx官網找源了.http://nginx.org/packages/centos/  根據自己要的版本下載.

[root@wz home]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
獲取http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
警告:/var/tmp/rpm-tmp.KMa86x: 頭V4 RSA/SHA1 Signature, 密鑰 ID 7bd9bf62: NOKEY
准備中...                          ################################# [100%]
正在升級/安裝...
   1:nginx-release-centos-7-0.el7.ngx ################################# [100%]

  

[root@wz home]# yum info nginx
已加載插件:fastestmirror
nginx                                                              | 2.9 kB  00:00:00     
nginx/x86_64/primary_db                                            |  31 kB  00:00:16     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可安裝的軟件包
名稱    :nginx
架構    :x86_64
時期       :1
版本    :1.12.2
發布    :1.el7_4.ngx
大小    :716 k
源    :nginx/x86_64
簡介    : High performance web server
網址    :http://nginx.org/
協議    : 2-clause BSD-like license
描述    : nginx [engine x] is an HTTP and reverse proxy server, as well as
         : a mail proxy server.

  現在在nginx版本找到了nginx1.12.2

-----------------------------------------------------------------------------------------------------------------------------分割線---------------------------------------------------------------------------------------------------------------------------------

其實我們也可以通過epel源來安裝.1、安裝LNMP之前要安裝EPEL,以便安裝源以外的軟件,如Nginx,phpMyAdmin等。

yum install epel-release

  提示:EPEL,即Extra Packages for Enterprise Linux,企業版linux附加包。這個軟件倉庫里有很多非常常用的軟件,而且是專門針對RHEL設計的,對RHEL標准yum源是一個很好的補充,完全免費使用,由Fedora項目維護,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的yum源。 

yum update

  接下來安裝nginx

[root@xpsl ~]# yum install nginx                   #安裝    
[root@xpsl ~]# systemctl start nginx               #啟動
[root@xpsl ~]# ps -aux | grep nginx                #查看是否存在服務
[root@xpsl ~]# curl hostlocal                      #查nginx啟動是否正常
[root@xpsl ~]# systemctl enable nginx              #把nginx加入啟動項
            

  安裝PHP和依賴包

[root@xpsl ~]# yum install -y php php-devel php-fpm php-mysql php-common php-devel php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel

  開啟php-fpm

[root@xpsl ~]# systemctl start php-fpm
[root@xpsl ~]# systemctl enable php-fpm

   因為mysql被甲骨文公司收購,所以安裝mariadb和mariadb-server

[root@xpsl ~]# yum install -y mariadb mariadb-server

  啟動mariadb和初始化mariadb

[root@xpsl ~]# systemctl start mariadb
[root@xpsl ~]# systemctl enable mariadb
mysql_secure_installation

  除了newpasswd需要輸入兩邊新密碼,其他全部回車。

  下面是備用方法

初次安裝mysql是root賬戶是沒有密碼的
設置密碼的方法
  
# mysql -uroot
mysql> set password for ‘root’@‘localhost’ = password('mypasswd');
mysql> exit

  修改php.ini的配置

vim /etc/php.ini 
cgi.fix_pathinfo=1 #將注釋去掉,開啟PHP的pathinfo偽靜態功能。
max_execution_time = 0  #腳本運行的最長時間,默認30秒
max_input_time = 300#腳本可以消耗的時間,默認60秒
memory_limit = 256M#腳本運行最大消耗的內存,根據你的需求更改數值,默認128M
post_max_size = 100M  #單提交的最大數據,此項不是限制上傳單個文件的大小,而是針對整個表單的提交數據進行限制的。限制范圍包括表單提交的所有內容.例如:發表貼子時,貼子標題,內容,附件等…默認8M
upload_max_filesize = 10M#上載文件的最大許可大小 ,默認2M

  修改php-fpm的配置

[root@xpsl ~]# vi /etc/php-fpm.d/www.conf 

找到以下兩行,解除注釋 
listen.owner = nobody 
listen.group = nobody 

找下以下兩行,將各自的apache改為nginx 
user = apache -> user = nginx 
group = apache -> group = nginx

  寫ngnix網站模板

vim /etc/nginx/conf.d/default.conf  
server {
    listen       80;
    server_name  服務器IP;


    root   /usr/share/nginx/html;


        location / {
            root   /usr/share/nginx/html;
            index index.php index.html index.htm;
        }


    error_page  404              /404.html;


    # redirect server error pages to the static page /50x.html  
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


    location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }


}

  注:/usr/share/nginx/html/為網站跟目錄

#cd /usr/share/
#chown nginx.nginx nginx
#cd nginx/html
# echo "<?php phpinfo(); ?>" >index.php
#測試下網站試試
#如果沒有打開防火牆那就打開一下
# firewall-cmd --zone=public --add-port=80/tcp --permanent

  安裝phpmyadmin

#yum install -y unzip wget
#wget https://files.phpmyadmin.net/phpMyAdmin/4.4.12/phpMyAdmin-4.4.12-all-languages.zip
#unzip phpMyAdmin-4.4.12-all-languages.zip
#mv phpMyAdmin-4.4.12-all-languages /usr/share/nginx/html/phpmyadmin
#chown -R nginx.nginx /var/lib/php/session

  

到此安裝完成。

 

 

 

 

 

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM