{"id":568,"date":"2025-01-09T10:09:23","date_gmt":"2025-01-09T03:09:23","guid":{"rendered":"https:\/\/nbvps.anhtuanlqd.com\/?p=568"},"modified":"2025-01-10T10:31:33","modified_gmt":"2025-01-10T03:31:33","slug":"set-up-new-wordpress-in-ubuntu-debian-mint","status":"publish","type":"post","link":"https:\/\/nbvps.anhtuanlqd.com\/?p=568","title":{"rendered":"Set up new WordPress in Ubuntu, Debian, Mint&#8230;"},"content":{"rendered":"\n<p>.sh file ==&gt;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Variables\nFOLDER_NAME=${1:-wordpress}\nDB_NAME=${2:-wordpress}\nDB_USER=${3:-wordpressuser}\nDB_PASSWORD=${4:-password}\nDOMAIN_NAME=${5:-example.com}\n\n# Update and install necessary packages\nsudo apt update\nsudo apt install -y apache2 mysql-server php php-mysql libapache2-mod-php php-cli unzip wget certbot python3-certbot-apache\n\n# Download and extract the latest WordPress\nwget https:\/\/wordpress.org\/latest.zip\nunzip latest.zip\nsudo mv wordpress \/var\/www\/html\/$FOLDER_NAME\n\n# Set permissions\nsudo chown -R www-data:www-data \/var\/www\/html\/$FOLDER_NAME\nsudo chmod -R 755 \/var\/www\/html\/$FOLDER_NAME\n\n# Create a MySQL database and user for WordPress\nsudo mysql -e \"CREATE DATABASE $DB_NAME;\"\nsudo mysql -e \"CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';\"\nsudo mysql -e \"GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';\"\nsudo mysql -e \"FLUSH PRIVILEGES;\"\n\n# Configure Apache virtual host\nsudo bash -c \"cat &lt;&lt;EOF > \/etc\/apache2\/sites-available\/$FOLDER_NAME.conf\n&lt;VirtualHost *:80>\n    ServerAdmin admin@$DOMAIN_NAME\n    DocumentRoot \/var\/www\/html\/$FOLDER_NAME\n    ServerName $DOMAIN_NAME\n    ServerAlias www.$DOMAIN_NAME\n\n    &lt;Directory \/var\/www\/html\/$FOLDER_NAME>\n        Options FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n\n    ErrorLog \\${APACHE_LOG_DIR}\/error.log\n    CustomLog \\${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost>\nEOF\"\n\n# Enable the WordPress site and rewrite module\nsudo a2ensite $FOLDER_NAME.conf\nsudo a2enmod rewrite\nsudo systemctl restart apache2\n\n# Obtain SSL certificate and configure auto-renewal\nsudo certbot --apache -d $DOMAIN_NAME -d www.$DOMAIN_NAME\n\n# Set up auto-renewal\nsudo systemctl enable certbot.timer<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Choose from apache or nginx<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# Variables\nFOLDER_NAME=${1:-wordpress}\nDB_NAME=${2:-wordpress}\nDB_USER=${3:-wordpressuser}\nDB_PASSWORD=${4:-password}\nDOMAIN_NAME=${5:-example.com}\nWEB_SERVER=${6:-apache} # Choose between 'apache' or 'nginx'\n\n# Update and install necessary packages\nsudo apt update\nsudo apt install -y mysql-server php php-mysql php-cli unzip wget certbot\n\nif &#91; \"$WEB_SERVER\" == \"apache\" ]; then\n    sudo apt install -y apache2 libapache2-mod-php python3-certbot-apache\nelif &#91; \"$WEB_SERVER\" == \"nginx\" ]; then\n    sudo apt install -y nginx php-fpm python3-certbot-nginx\nelse\n    echo \"Invalid web server choice. Please choose 'apache' or 'nginx'.\"\n    exit 1\nfi\n\n# Download and extract the latest WordPress\nwget https:\/\/wordpress.org\/latest.zip\nunzip latest.zip\nsudo mv wordpress \/var\/www\/html\/$FOLDER_NAME\n\n# Set permissions\nsudo chown -R www-data:www-data \/var\/www\/html\/$FOLDER_NAME\nsudo chmod -R 755 \/var\/www\/html\/$FOLDER_NAME\n\n# Create a MySQL database and user for WordPress\nsudo mysql -e \"CREATE DATABASE $DB_NAME;\"\nsudo mysql -e \"CREATE USER '$DB_USER'@'localhost' IDENTIFIED BY '$DB_PASSWORD';\"\nsudo mysql -e \"GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';\"\nsudo mysql -e \"FLUSH PRIVILEGES;\"\n\nif &#91; \"$WEB_SERVER\" == \"apache\" ]; then\n    # Configure Apache virtual host\n    sudo bash -c \"cat &lt;&lt;EOF > \/etc\/apache2\/sites-available\/$FOLDER_NAME.conf\n&lt;VirtualHost *:80>\n    ServerAdmin admin@$DOMAIN_NAME\n    DocumentRoot \/var\/www\/html\/$FOLDER_NAME\n    ServerName $DOMAIN_NAME\n    ServerAlias www.$DOMAIN_NAME\n\n    &lt;Directory \/var\/www\/html\/$FOLDER_NAME>\n        Options FollowSymLinks\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory>\n\n    ErrorLog \\${APACHE_LOG_DIR}\/error.log\n    CustomLog \\${APACHE_LOG_DIR}\/access.log combined\n&lt;\/VirtualHost>\nEOF\"\n\n    # Enable the WordPress site and rewrite module\n    sudo a2ensite $FOLDER_NAME.conf\n    sudo a2enmod rewrite\n    sudo systemctl restart apache2\n\n    # Obtain SSL certificate and configure auto-renewal\n    sudo certbot --apache -d $DOMAIN_NAME -d www.$DOMAIN_NAME\nelif &#91; \"$WEB_SERVER\" == \"nginx\" ]; then\n    # Configure Nginx server block\n    sudo bash -c \"cat &lt;&lt;EOF > \/etc\/nginx\/sites-available\/$FOLDER_NAME\nserver {\n    listen 80;\n    server_name $DOMAIN_NAME www.$DOMAIN_NAME;\n\n    root \/var\/www\/html\/$FOLDER_NAME;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files \\$uri \\$uri\/ \/index.php?\\$args;\n    }\n\n    location ~ \\.php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock;\n    }\n\n    location ~ \/\\.ht {\n        deny all;\n    }\n\n    error_log \/var\/log\/nginx\/$FOLDER_NAME.error.log;\n    access_log \/var\/log\/nginx\/$FOLDER_NAME.access.log;\n}\nEOF\"\n\n    # Enable the WordPress site\n    sudo ln -s \/etc\/nginx\/sites-available\/$FOLDER_NAME \/etc\/nginx\/sites-enabled\/\n    sudo systemctl restart nginx\n\n    # Obtain SSL certificate and configure auto-renewal\n    sudo certbot --nginx -d $DOMAIN_NAME -d www.$DOMAIN_NAME\nfi\n\n# Set up auto-renewal\nsudo systemctl enable certbot.timer<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>.sh file ==&gt; Choose from apache or nginx<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[50,2,23],"tags":[204,202,203,145],"class_list":["post-568","post","type-post","status-publish","format-standard","hentry","category-command","category-linux","category-tips-and-trick","tag-sh","tag-setupnewweb","tag-setupnewwordpress","tag-wordpress"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=568"}],"version-history":[{"count":4,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions"}],"predecessor-version":[{"id":574,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/568\/revisions\/574"}],"wp:attachment":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}