1. 安装 nginx 最新版本,使用以下命令:
1 2 |
sudo apt-get update sudo apt-get install nginx |
2. 安装 php7 :(不要尝试直接apt-get install php7,这样会默认安装apache,ubuntu 16默认不能安装php5)
1 |
sudo apt-get install php7.0-cli php7.0-cgi php7.0-fpm php7.0-mcrypt php7.0-mysql curl libcurl3 libcurl3-dev php7.0-curl |
3. 安装 MySQL 数据库:
1 |
sudo apt-get install mysql-server |
4. nginx管理操作
大括弧里是可选的操作,选一个,外面不需要加大括弧
1 |
sudo service nginx {start|stop|restart|reload|force-reload|status|configtest} |
5. 配置nginx
1 2 3 4 5 6 7 8 |
sudo mv /var/www /var/nginx sudo mv /var/nginx/html /var/nginx/www # 为了方便远程编辑站点目录下的文件,我喜欢将站点根目录属主改为自己的用户 sudo chown -R ubuntu:ubuntu /var/nginx sudo ln -s /var/nginx /nginx sudo ln -s /var/nginx ~/nginx sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup sudo nano /etc/nginx/sites-available/default |
配置文件样本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# Default server configuration # server { listen 80 default_server; listen [::]:80 default_server; root /var/nginx/www; # Add index.php to the list if you are using PHP index index.php index.html index.htm; server_name www.test.com test.com *.test.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.0-fpm.sock; } } |
重启nginx:
1 |
sudo service nginx restart |
6. 安装phpMyAdmin
1 2 3 4 5 |
cd ~/nginx/www wget https://files.phpmyadmin.net/phpMyAdmin/4.7.6/phpMyAdmin-4.7.6-all-languages.zip unzip ./phpMyAdmin-4.7.6-all-languages.zip rm phpMyAdmin-4.7.6-all-languages.zip mv ./phpMyAdmin-4.7.6-all-languages ./pma |