For advanced users looking to efficiently manage multiple WordPress sites on an Ubuntu server, the following guide provides a streamlined, copy-paste sequence of commands. This comprehensive setup will handle essential tasks such as updating and upgrading your system, installing necessary packages, configuring virtual hosts, setting directory permissions, and creating MySQL databases and users. By following these steps, you’ll have a robust and scalable environment for hosting multiple WordPress sites with minimal hassle.
Step 1: Update and Install Necessary Packages
sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql
Step 2: Create Directories and Download WordPress
sudo mkdir -p /var/www/localpress
sudo mkdir -p /var/www/templatepress
cd /tmp
wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz -C /var/www/localpress --strip-components=1
sudo tar -xzf latest.tar.gz -C /var/www/templatepress --strip-components=1
Step 3: Set Permissions
sudo chown -R www-data:www-data /var/www/localpress /var/www/templatepress
sudo chmod -R 755 /var/www/localpress /var/www/templatepress
Step 4: Configure Virtual Hosts
sudo tee /etc/apache2/sites-available/localpress.conf <<EOL
<VirtualHost *:80>
ServerAdmin admin@localpress.local
ServerName localpress.local
DocumentRoot /var/www/localpress
ErrorLog ${APACHE_LOG_DIR}/localpress_error.log
CustomLog ${APACHE_LOG_DIR}/localpress_access.log combined
</VirtualHost>
EOL
sudo tee /etc/apache2/sites-available/templatepress.conf <<EOL
<VirtualHost *:80>
ServerAdmin admin@templatepress.local
ServerName templatepress.local
DocumentRoot /var/www/templatepress
ErrorLog ${APACHE_LOG_DIR}/templatepress_error.log
CustomLog ${APACHE_LOG_DIR}/templatepress_access.log combined
</VirtualHost>
EOL
sudo a2ensite localpress.conf
sudo a2ensite templatepress.conf
sudo a2dissite 000-default.conf
sudo systemctl reload apache2
Step 5: Create MySQL Databases and Users
sudo mysql -e "CREATE DATABASE localpress_db;"
sudo mysql -e "CREATE DATABASE templatepress_db;"
sudo mysql -e "CREATE USER 'localpress_user'@'localhost' IDENTIFIED BY 'password';"
sudo mysql -e "CREATE USER 'templatepress_user'@'localhost' IDENTIFIED BY 'password';"
sudo mysql -e "GRANT ALL PRIVILEGES ON localpress_db.* TO 'localpress_user'@'localhost';"
sudo mysql -e "GRANT ALL PRIVILEGES ON templatepress_db.* TO 'templatepress_user'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"
Step 6: Update Hosts File
sudo tee -a /etc/hosts <<EOL
127.0.0.1 localpress.local
127.0.0.1 templatepress.local
EOL
Step 7: Configure WordPress Files
cd /var/www/localpress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update the following in wp-config.php
:
define( 'DB_NAME', 'localpress_db' );
define( 'DB_USER', 'localpress_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
For templatepress
:
cd /var/www/templatepress
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php
Update the following in wp-config.php
:
define( 'DB_NAME', 'templatepress_db' );
define( 'DB_USER', 'templatepress_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
http://localpress.local
http://templatepress.local