In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to use Docker to build WordPress site, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Install Docker
Before we really get started, we need to make sure that Docker is installed on our Linux machine. The host we are using is CentOS 7, so we use the following command to install docker using the yum manager.
# yum install docker
# systemctl restart docker.service
two。 Create a Dockerfile for WordPress
We need to create a Dockerfile that automatically installs wordpress and its pre-requirements. This Dockerfile will be used to build the installation image of WordPress. This WordPress Dockerfile will get the CentOS 7 image from Docker Registry Hub and upgrade the system with the latest available updates. It then installs the necessary software, such as Nginx Web server, PHP, MariaDB, Open SSH server, and other components that are essential to the proper operation of the Docker container. Finally, it executes a script that initializes the WordPress installation.
# nano Dockerfile
Then, we need to add the following configuration line to the Dockerfile.
FROM centos:centos7 MAINTAINER The CentOS Project RUN yum-y update; yum clean all RUN yum-y install epel-release; yum clean all RUN yum-y install mariadb mariadb-server mariadb-client nginx php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy php-apc pwgen python-setuptools curl git tar Yum clean all ADD. / start.sh / start.sh ADD. / nginx-site.conf / nginx.conf RUN mv / nginx.conf / etc/nginx/nginx.conf RUN rm-rf / usr/share/nginx/html/* RUN / usr/bin/easy_install supervisor RUN / usr/bin/easy_install supervisor-stdout ADD. / supervisord.conf / etc/supervisord.conf RUN echo% sudo ALL=NOPASSWD: ALL > > / etc/sudoers ADD http://wordpress.org/latest.tar.gz / wordpress.tar.gz RUN tar xvzf / wordpress.tar.gz RUN mv / wordpress/* / usr/share/nginx/html/. RUN chown-R apache:apache / usr/share/nginx/ RUN chmod 755 / start.sh RUN mkdir / var/run/sshd EXPOSE 80 EXPOSE 22 CMD ["/ bin/bash", "/ start.sh"]
3. Create a startup script
After we have created Dockerfile, we need to create a script named start.sh to run and configure the WordPress installation. It creates and configures the database and password for WordPress. Open start.sh with our favorite text editor.
# nano start.sh
After opening start.sh, we will add the following configuration line to the file.
#! / bin/bash _ _ check () {if [- f / usr/share/nginx/html/wp-config.php] Then exit fi} _ create_user () {# create a user SSH_USERPASS= `pwgen-c-n-1 8` useradd-G wheel user echo user:$SSH_USERPASS for SSH login | chpasswd echo ssh user password: $SSH_USERPASS} _ _ mysql_config () {# enable and run MySQL yum-y erase mariadb mariadb-server rm-rf / var/lib/mysql/ / etc/my.cnf yum-y install mariadb mariadb-server mysql_install_db chown -R mysql:mysql / var/lib/mysql / usr/bin/mysqld_safe & sleep 10} _ _ handle_passwords () {# here we generate random passwords (thanks to pwgen). The first two are for mysql users, and the last one is for wp-config.php 's random key. WORDPRESS_DB= "wordpress" MYSQL_PASSWORD= `pwgen-c-n-1 12` WORDPRESS_PASSWORD= `pwgen-c-n-1 12` # this is the password displayed in the log. Echo mysql root password: $MYSQL_PASSWORD echo wordpress password: $WORDPRESS_PASSWORD echo $MYSQL_PASSWORD > / mysql-root-pw.txt echo $WORDPRESS_PASSWORD > / wordpress-db-pw.txt # here used to be a very long line including sed, cat, pipe, and stuff But thanks to # @ djfiander's https://gist.github.com/djfiander/6141138 # now there is no sed-e "s/database_name_here/$WORDPRESS_DB/ s/username_here/$WORDPRESS_DB/ s/password_here/$WORDPRESS_PASSWORD/ / 'AUTH_KEY'/s/put your unique phrase here/ `pwgen-c-n-1 65` / /' SECURE_AUTH_KEY'/s/put your unique phrase here/ `pwgen-c-n-1 65` / 'LOGGED_IN_KEY'/s/put your unique phrase here/ `pwgen-c-n-1 65` / /' NONCE_KEY'/s/put your unique phrase here/ `pwgen-c-n-1 65` / / 'AUTH_SALT'/s/put your unique phrase here/ `pwgen-c-n-1 655` / /' SECURE_AUTH_SALT'/s/put your unique phrase here/ `pwgen-c-n-1 65` / / 'LOGGED_IN_SALT'/s/put your Unique phrase here/ `pwgen-c-n-1 65` / / 'NONCE_SALT'/s/put your unique phrase here/ `pwgen-c-n-1 65` / "/ usr/share/nginx/html/wp-config-sample.php > / usr/share/nginx/html/wp-config.php} _ _ httpd_perms () {chown apache:apache / usr/share/nginx/html/wp-config.php} _ start_mysql () {# systemctl launch mysqld Service mysqladmin-uroot password $MYSQL_PASSWORD mysql-uroot-p$MYSQL_PASSWORD-e "CREATE DATABASE wordpress GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY' $WORDPRESS_PASSWORD'; FLUSH PRIVILEGES; "killall mysqld sleep 10} _ _ run_supervisor () {supervisord-n} # call all functions _ _ check _ _ create_user _ _ mysql_config _ _ handle_passwords _ _ httpd_perms _ _ start_mysql _ _ run_supervisor
After adding the above configuration, save and close the file.
4. Create a profile
Now we need to create a configuration file for the Nginx Web server, named nginx-site.conf.
# nano nginx-site.conf
Then, add the following configuration information to the configuration file.
User nginx; worker_processes 1; error_log / var/log/nginx/error.log; # error_log / var/log/nginx/error.log notice; # error_log / var/log/nginx/error.log info; pid / run/nginx.pid; events {worker_connections 1024;} http {include / etc/nginx/mime.types; default_type application/octet-stream Log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"; access_log / var/log/nginx/access.log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # gzip on; index index.html index.htm index.php # Load modular configuration files from the / etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. Include / etc/nginx/conf.d/*.conf; server {listen 80; server_name localhost; # charset koi8-r; # access_log logs/host.access.log main; root / usr/share/nginx/html; # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html } # proxy the PHP scripts to Apache listening on 127.0.0.1 location 80 # location ~\. Php$ {# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1 php$ 9000 # location ~\ .php ${root / usr/share/nginx/html; try_files $uri = 404; fastcgi_pass 127.0.0.1 fastcgi_pass 9000; fastcgi_index index.php Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # # location ~ /\ .ht {# deny all; #}}
Now, create the supervisor.conf file and add the following line.
# nano supervisord.conf
Then, add the following line.
[unix_http_server] file=/tmp/supervisor.sock; (the path to the socket file) [supervisord] logfile=/tmp/supervisord.log; (main logfile; default $CWD/supervisord.log) logfile_maxbytes=50MB; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10; (num of main logfile rotation backups;default 10) loglevel=info; (loglevel; default info; others: debug,warn,trace) pidfile=/tmp/supervisord.pid; (supervisord pidfile;default supervisord.pid) nodaemon=false (start in foreground if true;default false) minfds=1024; (min. Avail startup file descriptors;default 1024) minprocs=200; (min. Avail process descriptors;default 200); the below section must remain in the config file for RPC; (supervisorctl/web interface) to work, additional interfaces may be; added by defining them in separate rpcinterface: sections [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock Use a unix:// URL for a unix socket [program:php-fpm] command=/usr/sbin/php-fpm-c / etc/php/fpm stdout_events_enabled=true stderr_events_enabled=true [program:php-fpm-log] command=tail-f / var/log/php-fpm/php-fpm.log stdout_events_enabled=true stderr_events_enabled=true [program:mysql] command=/usr/bin/mysql-- basedir=/usr-- datadir=/var/lib/mysql-- plugin-dir=/usr / lib/mysql/plugin-- user=mysql-- log-error=/var/log/mysql/error.log-- pid-file=/var/run/mysqld/mysqld.pid-- socket=/var/run/mysqld/mysqld.sock-- port=3306 stdout_events_enabled=true stderr_events_enabled=true [program:nginx] command=/usr/sbin/nginx stdout_events_enabled=true stderr_events_enabled=true [eventlistener:stdout] command= supervisor_stdout buffer_size = 100events = PROCESS_LOG result_handler = supervisor_stdout:event_handler
After adding, save and close the file.
5. Build a WordPress container
Now that we have created the configuration files and scripts, we are finally going to use Dockerfile to create the containers needed to install the latest WordPress CMS (Content Management System) and configure them according to the configuration files. To do this, we need to run the following command in the corresponding directory.
# docker build-rm-t wordpress:centos7.
6. Run the WordPress container
Now execute the following command to run the newly built container and open ports 88 and 22 for Nginx Web server and SSH access.
# CID=$ (docker run-d-p 80:80 wordpress:centos7)
Run the following command to check the process and commands executed inside the container.
# echo "$(docker logs $CID)"
Run the following command to check that the port mapping is correct.
# docker ps
7. Web interface
Finally, if everything is all right, when we open http://ip-address/ or http://mywebsite.com/ with a browser, we will see the welcome interface of WordPress.
Now we will set the WordPress configuration, user name, and password for the WordPress panel through the Web interface.
Then, enter the user name and password above into the WordPress login interface.
The above is all the contents of the article "how to use Docker to set up a WordPress site". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.