日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一步步yum安装LNMP,脱坑笔记!!!

發(fā)布時(shí)間:2025/3/15 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一步步yum安装LNMP,脱坑笔记!!! 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

更改國內(nèi)yum源:

1.備份yum源文件,位置在/etc/yum.repos.d/CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak

2.獲取阿里的yum源:(centos7為例)

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.更新cache

yum makecache

4.更新該yum源下所有資源:

yum -y update

?


?

?

安裝Nginx

1.更換nginx源為官網(wǎng)源(這步可省略)

To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:[nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1 Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

2.安裝并啟動nginx:

查詢nginx源、安裝nginx、關(guān)閉防火墻、啟動nginx

yum search nginx yum -y install nginx service iptables stop service nginx start


?安裝PHP

如果打算安裝5.X版本,直接yum install php就可以。

我這里安裝PHP7.0,所以如下操作:

更新yum源、安裝php7.0及許多依賴

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel

安裝OK后,php -v即可看到 php7的版本信息

?那么問題來了,怎么驗(yàn)證nginx可以解析php呢?

在nginx默認(rèn)啟動位置/usr/share/nginx/html下,新建info.php。里面測試代碼如下:

<?php phpinfo(); ?>

瀏覽器里訪問http://服務(wù)器IP/info.php,發(fā)現(xiàn)瀏覽器直接下載了,還是打不開。怎么弄呢?繼續(xù)往下看。

在/etc/nginx/conf.d/default.conf中,找到對應(yīng)代碼修改為如下代碼:

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;}

重新啟動nginx、php-fpm。然后重新訪問上一步路徑,效果如下:

?

這樣子,php就安裝完成了。繼續(xù)安裝mysql。

?


?

安裝MySQL

執(zhí)行以下命令:

yum -y install mysql mysql-server ,mysql-devel

有時(shí)候,會出現(xiàn)mysql-server找不到的錯(cuò)誤。那么不急,再執(zhí)行下面這條命令后即可。

rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yum intsall mysql-server

安裝成功后,啟動mysql。并且修改密碼為123.

service mysqld start use mysql; update user set password=password('123') where user='root' and host='localhost'; flush privileges;

最后測試下,php能否連接上呢?

在/usr/share/nginx/html下新建mysql.php

<?php $conn=mysql_connect('localhost','root','123') ; if($conn)echo "OK"; elseecho "failed"; ?>

結(jié)果是鏈接失敗了,php-fpm錯(cuò)誤日志顯示沒有mysql_connect()函數(shù)。怎么解決呢?

因?yàn)槿鄙賞hp-mysql模塊,所以安裝命令為:

yum install php-mysql

最后特別需要說明的一點(diǎn),PHP7以上版本不支持原來的mysql_connect函數(shù)。應(yīng)該使用如下測試代碼,我就陷坑好久!

<?php $mysqli = new mysqli("localhost", "root", "password"); if(!$mysqli) { echo"database error"; }else{ echo"php env successful"; } $mysqli->close(); ?>

至此,LNMP環(huán)境全部配置完成。快去建站吧!

?

轉(zhuǎn)載于:https://www.cnblogs.com/phper12580/p/10128512.html

總結(jié)

以上是生活随笔為你收集整理的一步步yum安装LNMP,脱坑笔记!!!的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。