CentOS7.6使用yum配置lnmp環境
一、安裝版本詳情
Server:MariaDB
Server version:5.5.60-MariaDB MariaDB Server
[root@ln-125 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@ln-125 ~]# nginx -v
nginx version: nginx/1.14.2
[root@ln-125 ~]# php-fpm -v
PHP 5.4.16 (fpm-fcgi) (built: Oct 30 2018 19:32:20)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
二、安裝Nginx服務
1.配置Nginx的yum源
[root@ln-125 ~]# cat >> /etc/yum.repos.d/nginx.repo <<EOF [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ #releasever 是linux 的版本號centos 7 gpgcheck=0 enabled=1 EOF
2.安裝並加入開機自啟動
yum clean all ; yum makecache ; yum list nginx ; #這時就可以看到nginx安裝包了 ; yum install nginx ; systemctl enable nginx ; systemctl start nginx
如果有需要補充的安裝模組可以根據當前Nginx版本到官方去下載原始碼包根據當前版本增量編譯追加的模組即可
[root@ln-125 ~]# nginx -V nginx version: nginx/1.14.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
三、安裝相關php服務
查詢當前的php安裝包
yum list phpphp-fmp
這裡為什麼要安裝php-fpm?
因為php-fpm,是nginx和php的橋樑,php-fpm(快速程序管理),php-fpm預設程序為127.0.0.1:9000,一會php和php-fpm安裝完成後,要配置nginx的配置檔案,讓其遇到客戶端php請求是,轉發給php-fpm(127.0.0.1:9000),php-fpm再讓php解析完成,最後又給nginx.
1.安裝
yum install -y php php-fpm php-pear php-devel #httpd #httpd 可選,引數更新中 php-pear為php的擴充套件工具,安裝後可以用pecl install 命令安裝php擴充套件
2.配置Nginx支援php檔案
預設Nginx是處理html和htm檔案的需要配置Nginx支援php
location / { root/usr/share/nginx/html;#設定根目錄的絕對路徑 indexindex.html index.htm index.php;#匹配php檔案 } location ~ \.php$ {#原來是註釋掉的需要開啟或複製 root/usr/share/nginx/html;#設定絕對路徑 fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;#設定根目錄匹配 includefastcgi_params; }
3.設定php的unix sock 方式通訊(可跳過這步)
預設配置檔案使用的是監聽 9000 埠進行通訊,針對小型單一、沒有做負債均衡的伺服器,可以使用 unix sock 方式通訊增加php響應速度
touch /dev/shm/php-fpm-default.sock [root@ln-125 ~]# cat /etc/php-fpm.d/www.conf |grep -Ev '^;|^$' [www] listen = /dev/shm/php-fpm-default.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = nobody listen.group = nobody listen.mode = 0666 user = nginx group = nginx 。。。 systemctl restart php-fpm.service systemctl enable php-fpm
四、安裝mariadb資料庫
yum install -y mariadb mariadb-server
#開機自啟 [root@ln-125 ~]# systemctl start mariadb.service [root@ln-125 ~]# systemctl enable mariadb.service #初始化資料庫配置 mysql_secure_installation#配置預設設定(root密碼登入方式等) #設定預設字符集 編輯 vim /etc/my.cnf [root@ln-125 ~]# grep -Ev '^#|^$' /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 character-set-server = utf8##設定預設編碼 [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
systemctl restart mariadb.service
五、測試
cat >> /usr/share/nginx/html/index.php << EOF <?php echophpinfo(); ?> EOF
http://{域名}
http://{域名}/index.php
看到測試頁,那麼恭喜你搭建完成。
END