1. Install docker
Using docker on Linux system greatly reduces the threshold for us to use various software. It is recommended that interested students must learn docker.
The official website where docker is installed, copy the command one step at a time:
The docker installation command simply copies the installation as follows:
(The question here is whether the root user is required, which needs to be determined later)
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce docker-ce-cli containerd.io
After these three steps, congratulations, your docker has been successfully installed. Run docker below with the following command to start the docker:
systemctl start docker
To see if the docker has been started,
systemctl status docker
If you see an active state here, congratulations on the success of your docker installation!!!
2. Install mysql
Set up a folder on the server to store the modified configuration files before installing mysql, so that we can quickly configure mysql:
mkdir -p ~/software/mysql/conf ~/software/mysql/logs ~software/mysql/data
Do the following to install mysql:
Remotely pull mysql's database
docker pull mysql
First run an instance:
docker run -it -d -- name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
Copy the instance's configuration file into the server:
docker cp mysql:/etc/mysql/conf.d ~software/mysql/conf
Delete old instances:
docker rm -f mysql
Re-create a mysql container:
docker run -it -d --name mysql -p 3306:3306 -v ~/software/mysql/conf:/etc/mysql/conf.d -v ~/software/mysql/logs:/logs -v ~/software/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql
Check to see if the container was successfully created:
docker ps
If mysql is listed, your mysql installation is successful!!!
The above step is to successfully install a mysql database. Is it easy to do this? The next problem is that this database does not support remote connections. Configure remote connections below:
Run a command to log in to the database:
docker exec -it mysql mysql -uroot -p
Enter the password to enter the database.
Configure remote connections as follows:
Set up a remote connection and switch to the mysql database:
use mysql;
Modify the database user table for remote connections:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Refresh changes:
flush privileges;
You can enjoy using the database here. Congratulations!!!
3. Install wordpress
wordpress does not describe what it is. Use your search engine to find out first
Let's install wordpress:
Remote warehouse pull wordpress: docker pull wordpress Run one first wordpress Example: docker run -it -d --name wordpress --link mysql:mysql -p 9001:80 wordpress Copy an existing wordpress File to current server : docker cp wordpress:/var/www/html ~/software/wordpress Delete the newly installed container: docker rm -f wordpress Reinstall wordpress Container: docker run -it -d --name wordpress -p 9001:80 -v ~software/wordpress/:/var/www/html --link mysql:mysql wordpress
Here our website comes out. Open your browser and enter:
http://ip:9001 for your own server
Congratulations, your website is out!!!
Follow the steps above and a website will come out, but when you upload pictures and videos using wordpress, it is limited in size. How do you configure the size?
Modify under ~/software/wordpress folder. htaccess file, open and add the following two lines:
RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] #Increase the size of the configuration upload file by two lines php_value post_max_size 24M php_value upload_max_filesize 8M
Restart wordpress:
docker restart wordpress
Please go to optimize your website, beautiful, handsome, you decide!!!
4. Install nginx
After the above installation, a website has come out, but there are some drawbacks. How to bind the domain name to the website? Let's use nginx to solve this problem.
Install nginx:
Remote warehouse pull nginx: docker pull nginx Run one first nginx Container for: docker run -it -d --name nginx nginx Copy profile: docker cp nginx:/etc/nginx/ ~/software/ delete nginx Container for: docker rm -f nginx Rebuild nginx Container for: docker run -it -d --name nginx -v ~/software/nginx/:/etc/nginx/ -v ~/software/nginx/logs:/var/log/nginx/ -v ~/software/nginx/www/:/usr/share/nginx/html/ -p 80:80 nginx
To see if nginx is working properly:
docker ps
Check to see if there is nginx among the running services, yes, congratulations, nginx installation is successful!!!
Below to configure nginx Access our website by domain name, open ~/software/nginx/conf.d/default.conf, need to use vim, will not use vim's recommendation to read my VIM article, very detailed:
vim ~/software/nginx/conf.d/default.conf
Modify the configuration file as follows:
server_name Configure the domain name of the new application, as follows My domain name is zempty.sg and www.zempty.sg
proxy_pass configures its own access path to wordpress: http://zempty.sg:9001
server { listen 80 default_server; listen [::]:80 default_server; server_name www.zempty.sg zempty.sg # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://zempty.sg:9001/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
Congratulations, you can access your website through the domain name. Try entering the domain name in your browser 😀 .
5. Add https
Now browsers are not safe if they are not accessed through https. Now that the website is set up, why not do security? Now I can solve this problem by using a free ssl certificate. It's a little expensive to buy a certificate. It's good to use a free encryption for personal websites. The HTTPS encryption configuration is detailed below. The steps are simple. Follow the steps to quickly solve the problem?
Reconfigure nginx.
As with the fourth point nginx above, the difference is to open an additional port 443, which is very important here because I have been struggling with this port for a long time and admire you for seeing this article.
docker run -it -d --name nginx -v ~/software/nginx/:/etc/nginx/ -v ~/software/nginx/logs:/var/log/nginx/ -v ~/software/nginx/www/:/usr/share/nginx/html/ -p 80:80 -p 443:443 nginx
Generate ssl certificate
How should a free ssl certificate be generated?
Provide an address for github: https://github.com/certbot/certbot , this repository can help us generate ssl certificates, too conscientious, start it!
Please install git on server first:
yum install git
Pull remote warehouse to local:
git clone [https://github.com/certbot/certbot]
Switch to the warehouse root directory, where I place the warehouse under ~/software:
cd ~/software/certbot
The key step is to generate an ssl certificate:
First close nginx:
docker stop nginx
Generate certificate:
./certbot-auto certonly -m kickcodeman@qq.com -d zempty.cf -d www.zempty.cf
Explain the parameters of the above command: -m followed by your own mailbox, -d followed by your own domain name, there are generally two, follow the screen prompt step by step, and finally/etc//etc/letsencrypt/live/personal domain name directory/there will be fullchain below. PEM and privkey.pem two files.
Please move these two files below ~/software/nginx/:
cp /etc/letsencrypt/live/Personal Domain Name Directory/fullchain.pem ~/software/nginx cp /etc/letsencrypt/live/Personal Domain Name Directory/privkey.pem ~/software/nginx
Configure ~/software/nginx/conf.d/defalut.conf file:
Switch to the profile directory:
cd ~/software/nginx/conf.d
Open the configuration file to configure as follows:
vim default.conf
server { listen 80 default_server; server_name www.zempty.cf zempty.cf; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name zempty.cf www.zempty.cf; ssl_certificate fullchain.pem; ssl_certificate_key privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; autoindex on; location / { proxy_pass http://zempty.ml:9001/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Start nginx:
docker restart nginx
Please open your browser and enter your domain name www.zempty.cf, you can see that https visited the website successfully,
Congratulations, your website has been made here!!