{"id":1975,"date":"2026-01-28T04:10:19","date_gmt":"2026-01-28T04:10:19","guid":{"rendered":"https:\/\/veerhost.com\/docs\/vps\/how-to-host-a-website-on-your-vps-nginx-apache-php-ssl\/"},"modified":"2026-03-31T17:54:48","modified_gmt":"2026-03-31T17:54:48","slug":"how-to-host-a-website-on-your-vps-nginx-apache-php-ssl","status":"publish","type":"docs","link":"https:\/\/veerhost.com\/de\/docs\/vps\/how-to-host-a-website-on-your-vps-nginx-apache-php-ssl\/","title":{"rendered":"How to Host a Website on Your VPS (Nginx\/Apache + PHP + SSL)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This guide shows you how to host a website on your VeerHost VPS from scratch \u2014 installing a web server (Nginx or Apache), PHP, creating a virtual host, uploading your files, and securing it with a free Let&#8217;s Encrypt SSL certificate. Works on Ubuntu 22.04, Ubuntu 24.04, and Debian.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Option A: Nginx (Recommended for Most Sites)<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Install Nginx and PHP<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update\napt install -y nginx php-fpm php-mysql php-cli php-curl php-zip php-mbstring php-xml php-gd<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check PHP version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. Create the Website Directory<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/var\/www\/yourdomain.com\/html\nchown -R www-data:www-data \/var\/www\/yourdomain.com\nchmod -R 755 \/var\/www\/yourdomain.com<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. Create an Nginx Virtual Host<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/nginx\/sites-available\/yourdomain.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Paste this config (replace <code>yourdomain.com<\/code> with your actual domain and adjust the PHP version if needed):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    listen [::]:80;\n    server_name yourdomain.com www.yourdomain.com;\n    root \/var\/www\/yourdomain.com\/html;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n\n    location ~ \\.php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass unix:\/var\/run\/php\/php8.3-fpm.sock;\n    }\n\n    location ~ \/\\.ht {\n        deny all;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Check your PHP-FPM socket version: <code>ls \/var\/run\/php\/<\/code> and use the correct filename (e.g., <code>php8.1-fpm.sock<\/code> or <code>php8.3-fpm.sock<\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the site and test:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ln -s \/etc\/nginx\/sites-available\/yourdomain.com \/etc\/nginx\/sites-enabled\/\nnginx -t\nsystemctl reload nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Option B: Apache<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. Install Apache and PHP<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>apt update\napt install -y apache2 php libapache2-mod-php php-mysql php-curl php-zip php-mbstring php-xml php-gd<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. Create the Website Directory<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/var\/www\/yourdomain.com\/html\nchown -R www-data:www-data \/var\/www\/yourdomain.com<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. Create an Apache Virtual Host<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/apache2\/sites-available\/yourdomain.com.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80&gt;\n    ServerName yourdomain.com\n    ServerAlias www.yourdomain.com\n    DocumentRoot \/var\/www\/yourdomain.com\/html\n\n    &lt;Directory \/var\/www\/yourdomain.com\/html&gt;\n        AllowOverride All\n        Require all granted\n    &lt;\/Directory&gt;\n\n    ErrorLog ${APACHE_LOG_DIR}\/yourdomain_error.log\n    CustomLog ${APACHE_LOG_DIR}\/yourdomain_access.log combined\n&lt;\/VirtualHost&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>a2ensite yourdomain.com.conf\na2enmod rewrite\napache2ctl configtest\nsystemctl reload apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install MySQL (If Needed)<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install -y mysql-server\nmysql_secure_installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a database and user for your website:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\n\nCREATE DATABASE mywebsite;\nCREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';\nGRANT ALL PRIVILEGES ON mywebsite.* TO 'myuser'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Upload Your Website Files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">From your <strong>local machine<\/strong>, upload files via SCP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scp -r \/path\/to\/local\/files root@YOUR_VPS_IP:\/var\/www\/yourdomain.com\/html\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or use an FTP client like FileZilla with SFTP (port 22) and your SSH credentials.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install a Free SSL Certificate (Let&#8217;s Encrypt)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure your domain&#8217;s DNS is already pointing to your VPS IP before running this. Install Certbot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install -y certbot python3-certbot-nginx\n# or for Apache:\napt install -y certbot python3-certbot-apache<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Get and install the certificate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Nginx:\ncertbot --nginx -d yourdomain.com -d www.yourdomain.com\n\n# Apache:\ncertbot --apache -d yourdomain.com -d www.yourdomain.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Certbot will automatically configure HTTPS and set up auto-renewal. Test renewal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>certbot renew --dry-run<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify It&#8217;s Working<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a test PHP file to confirm everything is working:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo '&lt;?php phpinfo(); ?&gt;' > \/var\/www\/yourdomain.com\/html\/info.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Visit <code>http:\/\/yourdomain.com\/info.php<\/code> in your browser. You should see the PHP info page. Delete it after confirming:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm \/var\/www\/yourdomain.com\/html\/info.php<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This guide shows you how to host a website on your VeerHost VPS from scratch \u2014 installing a web server (Nginx or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1967,"menu_order":3,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-1975","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/comments?post=1975"}],"version-history":[{"count":3,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1975\/revisions"}],"predecessor-version":[{"id":2283,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1975\/revisions\/2283"}],"up":[{"embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/docs\/1967"}],"wp:attachment":[{"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/media?parent=1975"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/veerhost.com\/de\/wp-json\/wp\/v2\/doc_tag?post=1975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}