3、让nginx支持php文件。
vim 编辑default 文件
#vim /etc/nginx/sites-available/default
或者
#gedit /etc/nginx/sites-available/default (懒人选gedit,编辑完保存关闭)
在 #add index.php to the list if you are using php 下一行添加一个
index.php
取消 php配置前面的#号,并且第一个fastcgi_pass改为:fastcgi_pass unix:/var/run/php5.0-fpm.sock;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php5.0-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
注意:fastcgi_pass 有两项,注销掉下面那个。否则nginx会凌乱的。
#service nginx restart #大致会报错吧。因为这时候你还需要装php5-fpm (php7-fpm),sock路径(亲自找对,有些可能在/var/run/php文件夹中)已经写在上面了。
4、再安装 php5-fpm (php7-fpm):
#apt install php5-fpm
启动:
#sudo /etc/init.d/php5-fpm start
如果启动不了,在 /var/log/nginx/ error.log文件查找原因
Deepin 安装 LNMP 教程(Nginx、MariaDB)+虚拟主机 vhosts搭建。
编译安装很费时间,装了一次就不想装第二次了,一键LNMP包自由度不高,看似简单,安装时间也过长,Pass。咱能走apt就apt包走起,看坛子大多数人安装后出现各种问题,本人今天刚装了 15.6,正好整合 Linux+nginx+MariaDB+PHP5.6 环境。咱们边装边聊:
0、全程 root 角色。
$su root
1、安装 nginx
#apt install nginx
安装完后浏览器 localhost 正常。
2、安装php5 或者 php7
#apt-get install php5 或者apt-get install php7
再打开浏览器刷新localhost,大多数人卡到这里。怎么变成了Apache2?看看刚才安装的依赖,绑定了Apache2卸载即可(如果你擅长Apache配置,可以忽略,毕竟官方cli里囊括了,至于我为啥放弃?自从用了Nginx就回不去了,因为站点比较多,Apache的虚拟主机没有nginx顺手):
#apt-get remove apache2
#apt-get --purge remove apache2
#apt autoremove
卸载后再 localhost 页面又回到了刚才的nginx,Bingo!
【特殊处理】
常用文件路径:
Nginx 默认配置文件:/etc/nginx/nginx.conf
默认localhost配置和虚拟主机我们都设置在:/etc/nginx/conf.d
/etc/nginx/ 目录下有两个目录 sites-available 为站点配置文件;sites-enabled 为站点配置快捷方式。查看 /etc/nginx/conf.d 文件,你会发现有这么两句话:
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
为了避免麻烦(懒得高软链接了),我们干脆把站点配置文件都保存到 conf.d 中进行统一管理。
#cp /etc/nginx/sites-enabled/default /etc/nginx/conf.d/default.conf
#rm -rf /etc/nginx/sites-available/default
#rm -rf /etc/nginx/sites-enabled/default
3、让nginx支持php文件。
vim 编辑default 文件
#vim /etc/nginx/sites-available/default
或者
#gedit /etc/nginx/sites-available/default (懒人选gedit,编辑完保存关闭)
在 #add index.php to the list if you are using php 下一行添加一个
index.php
取消 php配置前面的#号,并且第一个fastcgi_pass改为:fastcgi_pass unix:/var/run/php5.0-fpm.sock;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php5.0-fpm.sock;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
注意:fastcgi_pass 有两项,注销掉下面那个。否则nginx会凌乱的。
#service nginx restart #大致会报错吧。因为这时候你还需要装php5-fpm (php7-fpm),sock路径(亲自找对,有些可能在/var/run/php文件夹中)已经写在上面了。
4、再安装 php5-fpm (php7-fpm):
#apt install php5-fpm
启动:
#sudo /etc/init.d/php5-fpm start
如果启动不了,在 /var/log/nginx/ error.log文件查找原因
5、接下来安装 mariadb
#apt install mariadb-client
#service mysql stop
#service mysql start
配置:
#mysql_secure_installation
会提示你是否设置密码?输入新密码等等
Disallow root login remotely? 选择n,其他都是回车
进入方式:
#mysql
show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
show variables like "%collation%";
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+----------------------+--------------------+
utf8mb4 是utf8的超集,字符可以不用设置了,再见该死的Latin1。
配置虚拟主机。
#cd /etc/nginx/conf.d
#touch v1.conf
#vim v1.conf
或者
#gedit v1.conf
复制:
server {
listen 8001;
listen [::]:8001;
server_name www.v1.com;
root /opt/www/v1;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
修改端口为你喜欢的端口
root 为你的对应的虚拟主机目录
在 /opt/www/v1/ 目录下建立 index.php 进行测试。
#service nginx restart
浏览器:localhost:8001 飞起!!!
修改端口为你喜欢的端口
root 为你的对应的虚拟主机目录
在 /opt/www/v1/ 目录下建立 index.php 进行测试。
#service nginx restart
可能用到的命令:
重启网卡:sudo /etc/init.d/networking restart
root数据库访问:
>grant all privileges on *.* to 'root'@'localhost' identified by '123456';
>flush privileges
支持PDO 、curl
#apt install php5-mysql php5-curl
如果觉得对您有帮助,记得回帖支持~