This guide will walk you through the steps to install Apache, PHP, and deploy a PHP service using SQLite on your new Ubuntu VPS.
Before starting, update the package lists and upgrade existing packages: To install code-server (a self-hosted version of Visual Studio Code) on Ubuntu, follow these steps. Code-server allows you to run VS Code in the browser and access it remotely.
First, ensure your system is up to date and install any required dependencies:
sudo apt update
sudo apt upgrade -y
sudo apt install curl -y
The easiest way to install code-server is to use our install script for Linux, macOS and FreeBSD. The install script attempts to use the system package manager if possible.
To install, run:
curl -fsSL https://code-server.dev/install.sh | sh
Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yam
sudo systemctl enable --now code-server@$USER
Change the options in the config.yaml. 0.0.0.0:8888, password, and etc
nano ~/.config/code-server/config.yaml
After change the configuration, restart the service
sudo systemctl restart code-server@$USER
First, install UFW if it's not already installed on your system:
sudo apt update
sudo apt install ufw -y
After installation, you can check the status of UFW:
sudo ufw status
By default, UFW is inactive, so it will show Status: inactive.
Before enabling UFW, allow SSH connections to avoid locking yourself out of the server:
sudo ufw allow ssh
Alternatively, you can specify the port for SSH (default is 22):
sudo ufw allow 22/tcp
Next, allow HTTP (port 80) and HTTPS (port 443) traffic through the firewall:
sudo ufw allow http
sudo ufw allow https
Or, you can manually specify the ports:
sudo ufw allow 80/tcp # For HTTP
sudo ufw allow 443/tcp # For HTTPS
Once the necessary ports are allowed, you can enable UFW to start filtering traffic:
sudo ufw enable
To verify that UFW is active and the correct ports are open, run:
sudo ufw status verbose
This will show the list of allowed services and their associated ports. You should see something like:
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
80 ALLOW Anywhere
443 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
Install Apache by running the following command:
sudo apt install apache2 -y
Start the Apache service and enable it to start on boot:
sudo systemctl start apache2
sudo systemctl enable apache2
Verify that Apache is running:
sudo systemctl status apache2
Visit http://<your_server_ip> in your browser, and you should see the default Apache welcome page.
Install PHP and the required modules to run PHP with Apache:
sudo apt install php libapache2-mod-php php-sqlite3 -y
3.1. Check PHP Installation Verify that PHP is installed by running:
php -v
This will display the installed PHP version.
Ensure that Apache is configured to serve PHP files. The libapache2-mod-php package should automatically enable PHP, but you can confirm this by running:
sudo systemctl restart apache2
If you want to clone the repository directly from GitHub, follow these steps:
Install Git (if not already installed):
sudo apt install git -y
Clone the GitHub repository to /var/www/html:
sudo git clone https://github.com/username/repository.git /var/www/html/
Replace https://github.com/username/repository.git with the URL of your GitHub repository.
After cloning the repository, you need to ensure that Apache (which runs as the www-data user) can access and serve the files.
sudo chown -R www-data:www-data /var/www/html
This command changes the ownership of all files in the /var/www/html directory to the www-data user and group, which is the user under which Apache runs.
Optionally, you can ensure the correct read/write/execute permissions for the files:
sudo find /var/www/html -type d -exec chmod 755 {} \; # Directories - rwxr-xr-x
sudo find /var/www/html -type f -exec chmod 644 {} \; # Files - rw-r--r--
You may want to set up a virtual host if you need a custom domain or to ensure proper configuration for your service.
Example of a Virtual Host Configuration:
sudo nano /etc/apache2/sites-available/your-site.conf
Replace your-site.com with your domain or IP address:
apache
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName your-site.com
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite your-site.conf
Enable mod_rewrite (if necessary):
If you're using .htaccess or need URL rewriting, enable the mod_rewrite module:
sudo a2enmod rewrite
Restart Apache:
sudo systemctl restart apache2