我們已經裝好了nginx,現在我們開始裝mysql和php
我們同樣使用yum來安裝。
先安裝MySQL軟件(客戶端、服務器端、依賴庫)
yum install -y mysql mysql-server mysql-devel
然后設置自啟動,報錯

正確的安裝方法以及錯誤原因參考這里
好了,到這里我們就安裝好mysql了,下面我們開始安裝php。
詳細安裝參考我的另一篇文章:Centos 6/ 7下通過yum安裝php7環境
也可以參考另外一篇文章:yum安裝新版php7.0 后來更新了,也可以安裝7.2了
總結一下,首先是更新yum源,根據自己的CentOS版本來選擇
CentOS/RHEL 7.x:
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
如果是centos6,那么執行以下代碼:
CentOS/RHEL 6.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
然后就可以yum安裝PHP了
yum install php70w-common
要安裝其他拓展的話上面文章里有,這里我已經安裝好了laravel5.5所需的拓展了
//使用命令查看拓展 php -m



然后,我們配置一下nginx
vim /etc/nginx/nginx.conf
#這一段是最原始的配置,我們注釋掉 # server { # listen 80 default_server; # listen [::]:80 default_server; # server_name _; # root /usr/share/nginx/html; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } #寫入我們新的配置
server {
listen 80;# 監聽端口
server_name localhost;# 站點域名
#charset koi8-r;
#access_log logs/host.access.log main;
root /home/wwwroot/blog/public/;# 站點根目錄
location / {
index index.html index.htm index.php l.php;# 默認導航頁
autoindex off;
try_files $uri $uri/ /index.php?$query_string;
}
#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;
#}
}
然后重啟nginx
service nginx restart
訪問一下,可以了!(這里我提前在站點目錄里寫了一個php文件,沒有寫的可以寫一個)

好的,至此環境就搭好了,下一篇我們准備安裝larvael了,不太會寫,有什么不對的地方還請大家留言指出,共同學習!
