Manjaro 2 - PHP开发环境搭建 Nginx PHP Mariadb

1. 准备工作,升级系统、修改镜像、安装工具:

注:#后面都是解释内容,终端输入时去掉;

sudo pacman-mirrors -i -c China -m rank #中国镜像站列表, 选择最快的一个~
sudo pacman -Syy #刷新缓存

sudo pacman -S vim #安装vim

# 添加 `Archlinux` 中文社区仓库
sudo vim /etc/pacman.conf

#文件最后添加:
[archlinuxcn]
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

sudo pacman -S archlinuxcn-keyring
sudo pacman -Syu #更新系统

sudo pacman -S net-tools #ifconfig netstat等工具

#切换shell为zsh
cat /etc/shells #see all shells
chsh -s /bin/zsh #use zsh shell

--------------------------------这些操作要在控制台窗口菜单中进行
#终端窗口配置使用自定义的命令:
>Terminal Menu-Preferences-Command select Run a custom command instead of my shell
>Custom command zsh
--------------------------------

#config for zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
#替换zsh的配置文件为oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
#plugins 
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting

sudo vim ~/.zshrc
source ~/.zshrc  #refresh to make it work

1. Mariadb

sudo pacman -S mariadb
sudo mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl start mariadb.service 
mysql_secure_installation

2. nginx

sudo pacman -S nginx-mainline
sudo vim /etc/nginx/nginx.conf
vim /etc/nginx/logs/error.log #日志地址,有问题可以查看
可以浏览器访问下localhost,看到欢迎界面就OK了
sudo vim /usr/share/nginx/html/index.php #建立index.php,内容<?php echo phpinfo();?>

3. php-fpm

sudo pacman -S php-fpm
vim /etc/php/php-fpm.conf
sudo vim /etc/php/php-fpm.d/www.conf #配置文件,主要看listen,nginx要发送请求到php-fpm listen 的sock
sudo systemctl start php-fpm.service

4. nginx 配置

sudo vim /etc/nginx/nginx.conf
-----------------
location ~ [^/]\.php(/|$) {
        root /usr/share/nginx/html;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
-----------------
sudo systemctl restart nginx.service

OK,喝杯咖啡休息下。

开机启动:

sudo systemctl enable mariadb.service/nginx.service/php-fpm.service

Manjaro 2 - PHP开发环境搭建 Nginx PHP Mariadb