親手搭建LNMP阿里雲CentOS7.3
1.關閉防火牆和SELinux的的
關閉防火牆命令:
[root @ localhost~] #systemctl stop firewalld.service
查詢防火牆狀態:
[root @ localhost~] #systemctl status firewalld.service
狀態為:
[root @ localhost~] #vim / etc / sysconfig / selinux
找到SELINUX =強制執行強制改為禁用
禁用SELinux命令:
[root @ localhost~] #setenforce 0
2.安裝nginx
wget下載安裝nginx包
[root @ localhost~] #wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
建立nginx的yum倉庫
[root @ localhost~] #rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root @ localhost~]
#yum install -y nginx [root @ localhost~] #systemctl start nginx.service
然後在瀏覽器中輸入你伺服器的IP如下為nginx的的安裝成功:
3.安裝MySQL的
下載回購資源
[root @ localhost~] #wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
或者使用另一個地址:wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
安裝的MySQL的社群釋放,el7-5.noarch.rpm
[root @ localhost~] #rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝mysql&設定使用者許可權&重啟
[root @ localhost~] #yum -y install mysql-community-serve
[root @ localhost~] #sudo chown -R root:root / var / lib / mysql
[root @ localhost~] #systemctl restart mysql.service
登陸MySQL,修改密碼(可以先不操作此項,待所有安裝完成後自行設定):
[root @ localhost~] #mysql -u root
mysql>使用mysql;
mysql>設定'root'的密碼@'localhost'=密碼('password');
mysql> flush privilgegs;
檢測的MySQL的版本
mysql> status;
mysql> exit;
4.PHP7安裝
轉安裝的PHP相應的蔭資源
[root @ localhost~] #rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root @ localhost~] #rpm -Uvh https:// mirror .webtatic.com / grace / EL7 / webtatic-release.rpm
[root @ localhost~] #yum install -y php70w
檢視PHP是否安裝及版本:
[root @ localhost~] #php -v
安裝擴充套件
[root @ localhost~] #yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64
5.安裝php fpm
[root @ localhost~] #yum install -y php70w-fpm
修改配置
**
nginx配置檔案修改:可以直接在nginx.conf修改,怕修改壞的,
自己可備份一個nginx的的,的的conf檔案命令:
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bk
然後編輯nginx.conf
[root @ localhost~] #vim /etc/nginx/nginx.conf
然後把以下檔案貼上進去,改程式碼裡2箇中文的注意點就可以了
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_disable "MSIE [1-6].";
server_names_hash_bucket_size 128;
client_max_body_size 100m;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
server {
listen 80;
server_name www.bzydm.vip(改成自己的域名);
#charset koi8-r;
#access_log logs/host.access.log main;
root "/www/bzydm"(改成自己網站程式碼的目錄);
location / {
index index.html index.htm index.php l.php;
autoindex off;
}
#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 html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#include vhosts.conf;
}
然後檢查是否該正確
[root @ localhost~] #nginx -t
修改php-fpm配置檔案
[root @ localhost~] #vim /etc/php-fpm.d/www.conf
找到修改成這樣
user = nginx
group = nginx
測試
在自己設定的root目錄下新建一個測試檔案(我自己設定的是在/目錄下的:/www/bzydm/index.html)
echo'hello“;
啟動伺服器
[root @ localhost~] #systemctl start nginx.service
檢視伺服器狀態
[root @ localhost~] #systemctl status nginx啟動PHP-FPM
[root @ localhost~] #systemctl start php-fpm.service
[root @ localhost~] #systemctl status php-fpm.service在瀏覽器輸入自己的域名就OK了!
成功。