当然,首先你需要有一个VPS,才能继续以下步骤。这里推荐羽西最爱的Vultr VPS。最近由于Vultr和Linode展开价格战,最低配置的VPS只要2.5美金!白菜都要哭了。。。点击下面链接注册的话,直接送20美金,相当于8个月免费使用最低配置的VPS!
【促销链接 】
创建用户及登陆认证 创建用户 以root登陆后运行:
1 2 adduser --gecos "" yuxi [你的用户名] gpasswd -a yuxi sudo
把自己添加到sudo组中:
1 echo '你的用户名 ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
准备好你的公共密钥(public key),如果没有的话可以运行“ssh-keygen”来创建。
用你刚刚创建的用户登录后运行:
1 2 3 4 mkdir ~/.sshchmod 700 ~/.sshtouch ~/.ssh/authorized_keyschmod 600 ~/.ssh/authorized_keys
把你的公共密钥添加到文件authorized_keys中。
更新系统:
1 2 sudo apt-get -y update sudo apt-get -y upgrade
更新用户配置:
1 2 echo 'export LS_COLORS=$(echo $LS_COLORS | sed "s/di=\(..\);../di=\1;32/") ' >> ~/.bashrcecho "PS1='\\$ '" >> ~/.bashrc
系统登录设置 用编辑器打开/etc/ssh/sshd_config
1 sudo nano /etc/ssh/sshd_config
改变如下设置:
1 2 3 PasswordAuthentication no PubkeyAuthentication yes ChallengeResponseAuthentication no
同时建议改变SSH默认段口号,比如,从”22”改变为”2244”。
重启ssh服务:
1 sudo systemctl reload sshd
基本防火墙设置 1 2 3 4 sudo ufw enable sudo ufw delete allow OpenSSH sudo ufw allow from any to any port 2224 sudo ufw status
基本系统设置 运行:
1 2 3 4 5 6 7 8 9 10 11 12 sudo apt-get install -qq -y curl sudo apt-get install -qq -y lynx-cur sudo apt-get install -qq -y git sudo apt-get install -qq -y whois sudo apt-get install -qq -y apache2-utils sudo apt-get install -qq -y unzip sudo -H -u root bash -c "echo 'Europe/London' > /etc/timezone" sudo dpkg-reconfigure -f noninteractive tzdata sudo apt-get install -qq -y ntp > /dev/null 2>err.log git config --global user.email "YOUR_EMAIL" git config --global user.name "YOUR NAME"
安装Nginx 运行:
1 2 3 sudo apt-get update sudo apt-get install nginx sudo ufw allow 'Nginx HTTP'
获取VM的IP地址:
1 ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
在Nginx配置文件中更改server_name设置,可以使用域名或者IP。
1 nano /etc/nginx/sites-enabled/default
安装MySQL 1 2 sudo apt-get install mysql-server sudo mysql_secure_installation
安装PHP 1 sudo apt-get install -y php-fpm php-mysql
更改PHP设置:
1 sudo nano /etc/php/7.0/fpm/php.ini
做如下更改: cgi.fix_pathinfo=0
1 sudo systemctl restart php7.0-fpm
更改Nginx设置来支持PHP:
1 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 server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name server_domain_or_IP; location / { try_files $uri $uri / =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }
安装PHP扩展 1 2 3 sudo apt-get -y update sudo apt-get -y install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc sudo systemctl restart php7.0-fpm
安装Wordpress 创建Wordpress所需的数据库:
1 2 3 4 5 6 mysql -u root -p CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; GRANT ALL ON wordpress.* TO 'wordpressuser' @'localhost' IDENTIFIED BY 'password' ; FLUSH PRIVILEGES; exit
更改Nginx配置:
1 2 3 4 5 6 location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { log_not_found off; access_log off; allow all; } location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { expires max; log_not_found off; }
和:
1 2 3 location / { try_files $uri $uri / /index.php$is_args$args ; }
重新启动Nginx:
1 sudo systemctl reload nginx
安装Wordpress
1 2 3 4 5 6 7 cd /tmpcurl -O https://wordpress.org/latest.tar.gz tar xvf latest.tar.gz cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.phpsudo cp -a /tmp/wordpress/. /var/www/html mkdir /var/www/html/wp-content/uploadsmkdir /var/www/html/wp-content/upgrade
更改目录权限:
1 sudo chown -R yuxi:www-data /var/www/html
设定新创建文件继承父目录权限:
1 sudo find /var/www/html -type d -exec chmod g+s {} \;
给组(www-data)写权限,这样就可以在Web界面安装/更新主题和插件了:
1 sudo chmod g+w /var/www/html/wp-content
添加Web服务器的运行帐号(www-data)对以下目录的写权限:
1 2 sudo chmod -R g+w /var/www/html/wp-content/themes sudo chmod -R g+w /var/www/html/wp-content/plugins
更改Wordpress默认安全密钥:
1 curl -s https://api.wordpress.org/secret-key/1.1/salt/
打开 /var/www/html/wp-config.php, 更新如下配置:
1 2 3 4 5 6 7 8 define('AUTH_KEY' , 'put your unique phrase here' ); define('SECURE_AUTH_KEY' , 'put your unique phrase here' ); define('LOGGED_IN_KEY' , 'put your unique phrase here' ); define('NONCE_KEY' , 'put your unique phrase here' ); define('AUTH_SALT' , 'put your unique phrase here' ); define('SECURE_AUTH_SALT' , 'put your unique phrase here' ); define('LOGGED_IN_SALT' , 'put your unique phrase here' ); define('NONCE_SALT' , 'put your unique phrase here' );
更新数据库配置:
1 2 3 define('DB_NAME' , 'wordpress' ); define('DB_USER' , 'wordpressuser' ); define('DB_PASSWORD' , 'password' );
做如下设置,这样Wordpress就可以更新主题/插件,否则会要求输入FTP/SSH登录信息。在前面数据库设置的后面添加:
1 define('FS_METHOD' , 'direct' );
在Web界面中完成Wordpress的安装。
至此,Wordpress的基本版本就安装完了。当然,后续还有一些工作,比如:安全性配置,主题/插件安装,如何备份等等,由于技术性太强了,这里就不讨论了。
未经授权,严禁转载。
羽西欢迎大家投稿分享英国生活,邮件:
[email protected]
如果您觉得我的文章对您有所帮助,愿意请我喝杯咖啡:
BTC: 13awm2DNctX647QHH2zJHUEr5vQz3mK1hE
ETH: 0xfFAE39dA418bfa94018C00A4A5eb6A8ddc6Bcf5c