Setting Up the Website for Your API Endpoint on Your LAMP Stack
By: Bobby
Published on: Mar 01, 2023
2 min read.
In the previous tutorial, we discussed how to install the LAMP stack on your Ubuntu system. Now, we are ready to start hosting a website on it. In this article, we will explore how to set up a new website, adjust proper file and folder permissions, and provide an Apache configuration example.
Step 1: Creating a Directory for Your Website
Firstly, let’s create a directory that will hold your website’s files. You may replace your_domain
with your actual domain name or the name of your website.
sudo mkdir /var/www/your_domain
Step 2: Assign Ownership and Permissions
For the Apache web server to function correctly with your site, we need to adjust some permissions and ownership settings.
We’ll assign ownership of the directory to the current user with:
sudo chown -R $USER:$USER /var/www/your_domain
Next, we set the correct permissions for the website’s root directory to ensure that read access is given to visitors.
sudo chmod -R 755 /var/www/your_domain
Step 3: Create and Configure a New Apache Configuration File
Now, we will create a new Apache configuration file for your website.
sudo nano /etc/apache2/sites-available/your_domain.conf
Add the following content to the new configuration file. Replace your_domain
and your_email
with your domain and email respectively:
ServerAdmin your_email
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/your_domain_error.log
CustomLog ${APACHE_LOG_DIR}/your_domain_access.log combined
After editing the configuration file, save and close it.
Step 4: Enable Your Site
Once you’ve configured Apache to serve your site, you need to enable the site using the a2ensite
tool:
sudo a2ensite your_domain
You should also disable the default site provided by Apache:
sudo a2dissite 000-default
After these changes, restart Apache to implement your changes:
sudo systemctl restart apache2
Your new website should now be active!
In conclusion, setting up a new website on your LAMP stack is as simple as creating a directory for your site, adjusting the necessary ownership and permissions, and configuring Apache to serve your website. File and folder permissions are critical to ensuring the right level of access to your site’s resources. Correct Apache configuration ensures that your website can be accessed by visitors.
Remember to always follow best practices when configuring your web server to maintain the security and performance of your website. Happy web development!