Setting up a Website with no Wizard
Creating a New Website:
You can follow the steps outlined below, however there is a script to setup a new WordPress site that you can use that will run through all of these steps for you. To run it, call this command from root:
sw wp add
This example will be to create a site for the domain example.com under the system username exampleuser. This guide assumes you already know how to dial into the server with SSH and run bash (terminal) commands. All steps will involve terminal commands.
Step 1. Create a New System User
The first step of creating a new website is to create the system user:
sw user add exampleuser
Step 2. Point the Domain to the Server
Next, we need to create the DNS zone for the domain and point the domain to the server. This can be done by creating a new DNS zone using this script:
sw dns add example.com
You will also need to set the domain’s nameservers to your nameserver subdomains at the domain registrar.
If you are migrating an existing site, or otherwise unable to change the DNS to point to the server at this point, you can skip this step but you will be unable to validate certificates for the domain.
Step 3. Create PHP and Nginx vhost Files.
Part A: Create PHP config and part 1 of Nginx config
Next, if this is a PHP site we will need to setup the PHP site in PHP-FPM and nginx like so:
sw php add example.com exampleuser 8.2 sw nginx add example.com exampleuser
Part B: Create an SSL certificate
(This can be skipped if your DNS cannot be pointed to the server yet, but will require editing config files by hand) Part 1 of the nginx config only adds the non-SSL section to the nginx vhost (config) file. This is because the SSL section cannot be added without a certificate. The domain needs to work over non-SSL to be able to validate with Let’s Encrypt. So now we now need to install a certificate and then add the SSL section to the nginx config. Run one of the following to create the cert:
sw cert add example.com
– or –
sw cert add example.com exampleuser nocert
Make sure you got a success message from certbot before continuing.
Part C: Add part 2 of Nginx config
Now we can add the SSL section to your nginx config:
sw nginx add
In the prompt, select the existing username, domain name and now the php-ssl template. This will override your current nginx configuration file for this domain name.
Part D: (Only needed if B is skipped) Update nginx config file for custom certificates
After completing part C without completing part B, you should have gotten and error about the nginx configuration file. We will need to update the nginx vhost file for the new site to use a different certificate location.
First open the vhost file:
nano /usr/local/nginx/conf/vhosts/example.com.conf
Now hit Ctrl + W to search for the text “ssl_certificate”. You should find these two lines:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
If you plan on switching to the default certificates at some point, comment out these two lines by adding a “#” character to the start of each line and then add a copy of those two lines that are not commented out just after them. Then update the file paths of each file to the path to the current certificates.
Next hit Ctrl + W again and press enter without entering anything to search for the same text again. There is a second pair of lines that need to be updated in the same way. Once those are updated, save and exit nano.
Now we will need to reload the nginx configuration to apply the change by running this line:
/usr/local/nginx/sbin/nginx -s reload
Step 4. Create Website Database (Optional)
For most sites we will also need a new database and a user to go with it:
sw db add example_db example_db_user DB User Password: Enter the MySQL root password:
Note that when entering your password, nothing will be displayed as you type.
Step 5. Add Website Files
WordPress
When installing a WordPress site, we can use wp cli to install the files for us, but we need to get to the right place first. We need to switch our shell to run under the site’s user instead of root. This command will place us in the user’s home folder running as that user:
su - exampleuser
This will place the shell in the user’s home folder, but we need to run the command from inside public_html.
cd public_html
Finally, we can run this command to download the latest version of WordPress and install the files:
wp core download
Now that the files are in place, we can simply navigate to the site in the browser. We can then follow the WordPress install wizard that will ask for the database username and password and also allow us to create the administrator WordPress user.
If you would like to get back to the root user, press Ctrl + D or run the command “exit”.
Other Sites
There are two ways to install most sites. One by using SSHFS to upload a copy of the files to public_html. This will require you to authorize your local SSH key to access your new user. You can follow the steps in “Getting SSH Access” and “”Editing Website Files” to gain access.
The other way is to download the software to the server directly and extract it with a terminal command. The rest of this section details how to do this.
First, we need to move to the correct user and folder like in the WordPress section:
su - exampleuser
cd public_html
In your browser, find a download link for your software, right-click it and copy the link. Tar files are generally preferred over zips because they can hold more file metadata like file permissions. Next, run this command, substituting the example.com link with your link:
wget https://example.com/examplesoft.tar.gz
Now we can extract the file with one of these commands for .tar.gz, .tar, and .zip respectively:
tar -xzf examplesoft.tar.gz
tar -xf examplesoft.tar
unzip examplesoft.zip
This will likely extract the files from into a new folder. To move all files including hidden files to back into public_html and then remove the extra folder run these commands (replacing examplesoft-1.0 with your software folder [run “ls” if you don’t know the name of it]):
cd examplesoft-1.0
mv * ..
mv .* ..
cd ..
rm -r examplesoft-1.0
Most software has a configuration file such as config.php, settings.php or preferences.php. Sometimes these files are in a folder called “etc”. Consult the documentation for the software to add the database username and password to the correct file(s).