Centos 7.4 搭建LNMP
Centos 7.4 映象 selinux 與 firewall 已關閉。
工作環境
- 騰訊雲 1核 1GB 1Mbps 雲伺服器
- CentOS 7.2 64位
- 已經安裝了PHP
- 使用putty連結伺服器
1.安裝nginx
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安裝nginx
yum -y install nginx
1.4 啟動nginx
systemctl start nginx
2.安裝PHP7
2.1 安裝 epel-release
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2.2 安裝 php7 的 yum 源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2.3 安裝php7.0
yum install -y php70w
2.4 安裝php擴充套件
yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64
2.5 安裝 php-fpm
yum install -y php70w-fpm
3 修改配置檔案
3.1 修改nginx配置檔案,nginx配置檔案的位置在 /etc/nginx/nginx.config
vim /etc/nginx/nginx.conf
-
server {
-
listen 80 default_server;
-
listen [::]:80 default_server;
-
# 這裡改動了,也可以寫你的域名
-
server_name localhost;
-
root /usr/share/nginx/html;
-
# Load configuration files for the default server block.
-
include /etc/nginx/default.d/*.conf;
-
location / {
-
# 這裡改動了 定義首頁索引檔案的名稱
-
index index.php index.html index.htm;
-
}
-
error_page 404 /404.html;
-
location = /40x.html {
-
}
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
}
-
# 這裡新加的
-
# PHP 指令碼請求全部轉發到 FastCGI處理. 使用FastCGI協議預設配置.
-
# Fastcgi伺服器和程式(PHP,Python)溝通的協議.
-
location ~ \.php$ {
-
# 設定監聽埠
-
fastcgi_pass 127.0.0.1:9000;
-
# 設定nginx的預設首頁檔案(上面已經設定過了,可以刪除)
-
fastcgi_index index.php;
-
# 設定指令碼檔案請求的路徑
-
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
-
# 引入fastcgi的配置檔案
-
include fastcgi_params;
-
}
-
}
3.2 修改php-fpm 配置檔案 (/etc/php-fpm.d/www.conf)
-
user =nginx
-
group=nginx
3.3 重新啟動nginx
systemctl restart nginx
3.4 啟動php-fpm
systemctl start php-fpm.service
3.5 設定服務開機自啟
-
systemctl enable nginx
-
systemctl enable php-fpm
4. 安裝mysql
4.1下載mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
4.2 安裝mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.3 安裝mysql
sudo yum install -y mysql-server
4.4 更改mysql的使用者許可權
sudo chown -R root:root /var/lib/mysql
4.5 重啟服務
systemctl restart mysql.service
4.6 登陸並修改密碼
-
mysql -u root
-
mysql > use mysql;
-
mysql > update user set password=password(‘66666‘) where user=‘root‘;
-
mysql > flush privileges;
-
mysql > exit;
若有錯誤和疏漏,歡迎留言指正 --------------------- 本文來自 var_lin 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/mu_mu111/article/details/80813556?utm_source=copy