CentOS7.6系統(tǒng)下使用yum配置lnmp環(huán)境的方法
一、安裝版本詳情
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服務(wù)
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 的版本號(hào)centos 7 gpgcheck=0 enabled=1 EOF
2.安裝并加入開機(jī)自啟動(dòng)
yum clean all ; yum makecache ; yum list nginx ; #這時(shí)就可以看到nginx安裝包了 ; yum install nginx ; systemctl enable nginx ; systemctl start nginx
如果有需要補(bǔ)充的安裝模塊可以根據(jù)當(dāng)前Nginx版本到官方去下載源碼包根據(jù)當(dāng)前版本增量編譯追加的模塊即可
[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-fips 26 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'
三、安裝相關(guān)php服務(wù)
查詢當(dāng)前的php安裝包
yum list php php-fmp
這里為什么要安裝php-fpm?
因?yàn)閜hp-fpm,是nginx和php的橋梁,php-fpm(快速進(jìn)程管理),php-fpm默認(rèn)進(jìn)程為127.0.0.1:9000,一會(huì)php和php-fpm安裝完成后,要配置nginx的配置文件,讓其遇到客戶端php請求是,轉(zhuǎn)發(fā)給php-fpm(127.0.0.1:9000),php-fpm再讓php解析完成,最后又給nginx.
1.安裝
yum install -y php php-fpm php-pear php-devel #httpd
#httpd 可選,參數(shù)更新中 php-pear為php的擴(kuò)展工具,安裝后可以用pecl install 命令安裝php擴(kuò)展
2.配置Nginx支持php文件
默認(rèn)Nginx是處理html和htm文件的需要配置Nginx支持php
vim /etc/nginx/conf.d/default.conf ... location / { root /usr/share/nginx/html; #設(shè)置根目錄的絕對路徑 index index.html index.htm index.php; #匹配php文件 } location ~ \.php$ { #原來是注釋掉的需要開啟或復(fù)制 root /usr/share/nginx/html; #設(shè)置絕對路徑 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #設(shè)置根目錄匹配 include fastcgi_params; } ...
3.設(shè)置php的unix
sock 方式通信(可跳過這步)
默認(rèn)配置文件使用的是監(jiān)聽 9000 端口進(jìn)行通信,針對小型單一、沒有做負(fù)債均衡的服務(wù)器,可以使用 unix sock 方式通信增加php響應(yīng)速度
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
4.優(yōu)化配置(可選)
A) 修改php.ini的配置
vim /etc/php.ini cgi.fix_pathinfo=1 #將注釋去掉,開啟PHP的pathinfo偽靜態(tài)功能。 max_execution_time = 0 #腳本運(yùn)行的最長時(shí)間,默認(rèn)30秒 max_input_time = 300#腳本可以消耗的時(shí)間,默認(rèn)60秒 memory_limit = 256M#腳本運(yùn)行最大消耗的內(nèi)存,根據(jù)你的需求更改數(shù)值,默認(rèn)128M post_max_size = 100M #單提交的最大數(shù)據(jù),此項(xiàng)不是限制上傳單個(gè)文件的大小,而是針對整個(gè)表單的提交數(shù)據(jù)進(jìn)行限制的。限制范圍包括表單提交的所有內(nèi)容.例如:發(fā)表貼子時(shí),貼子標(biāo)題,內(nèi)容,附件等…默認(rèn)8M upload_max_filesize = 10M#上載文件的最大許可大小 ,默認(rèn)2M
B) 修改php-fpm的配置
vim /etc/php-fpm.d/www.conf 找到以下兩行,解除注釋 listen.owner = nobody listen.group = nobody 找下以下兩行,將各自的apache改為nginx user = apache -> user = nginx group = apache -> group = nginx
四、安裝mariadb數(shù)據(jù)庫
yum install -y mariadb mariadb-server #開機(jī)自啟 [root@ln-125 ~]# systemctl start mariadb.service [root@ln-125 ~]# systemctl enable mariadb.service #初始化數(shù)據(jù)庫配置 mysql_secure_installation #配置默認(rèn)設(shè)置(root密碼登錄方式等) #設(shè)置默認(rèn)字符集 編輯 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 ##設(shè)置默認(rèn)編碼 [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 echo phpinfo(); ?>
EOF
http://{域名}
http://{域名}/index.php
看到測試頁,那么恭喜你搭建完成。
總結(jié)
以上所述是小編給大家介紹的CentOS7.6系統(tǒng)下使用yum配置lnmp環(huán)境的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- centos6.5安裝python3.7.1之后無法使用pip的解決方案
- CentOS 7.3配置Nginx虛擬主機(jī)的方法步驟
- CentOS版本問題安裝Docker報(bào)錯(cuò)的解決方案
- Centos7如何開啟端口的方法示例
- Centos7修改主機(jī)名hostname的三種方法
- Linux centos下設(shè)置定時(shí)備份任務(wù)的方法步驟
- Linux centOS安裝JDK和Tomcat的教程
- 在CentOS7上搭建Jenkins+Maven+Git持續(xù)集成環(huán)境的方法
- 虛擬機(jī)中centos修改時(shí)間的方法
- centos6.5配置ssh免秘鑰登陸執(zhí)行pssh命令的講解
相關(guān)文章
Apache的壓力測試以及web性能優(yōu)化的常用知識(shí)總結(jié)
這篇文章主要介紹了Apache的壓力測試以及web性能優(yōu)化的常用知識(shí)總結(jié),筆記由《構(gòu)建高性能web站點(diǎn)》這本高人氣書籍整理而來,需要的朋友可以參考下2015-12-12Linux中實(shí)現(xiàn)修改打開文件數(shù)量和進(jìn)程數(shù)量限制的3種方法
這篇文章主要介紹了Linux中實(shí)現(xiàn)修改打開文件數(shù)量和進(jìn)程數(shù)量限制的3種方法,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06Ubuntu徹底卸載MySQL、Apache2和Php的方法教程
這篇文章主要給大家介紹了關(guān)于在Ubuntu系統(tǒng)下徹底卸載MySQL、Apache2和Php的方法教程,文中通過示例代碼介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起看看吧。2017-08-08apache中偽靜態(tài)配置和使用(Apache虛擬主機(jī)下Discuz偽靜態(tài))
apache中偽靜態(tài)配置和使用(Apache虛擬主機(jī)下Discuz偽靜態(tài)),需要的朋友可以參考下。2012-01-01安裝redhat 8.0紅帽系統(tǒng)的圖文教程(小白必備)
這篇文章主要介紹了安裝redhat 8.0紅帽系統(tǒng)的圖文教程(小白必備),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12CentOS 5.1下跑Mono和Asp.net的實(shí)現(xiàn)方法分享
由于想研究在linux下跑.net程序的可行性,于是嘗試在CentOS5.1下搭建Mono環(huán)境和Asp.Net的服務(wù)器。Asp.Net的服務(wù)器是采用mod_mono和Apache的方式搭建(Nginx的搭建尚未研究)2012-04-04linux服務(wù)器系統(tǒng)CentOS、uBuntu、Gentoo、FreeBSD、Debian的比較
最近一直都是在玩ubuntu的,但是做web服務(wù)器的CentOS還是經(jīng)常被用到,自己也糊涂了2012-12-12