October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk18 min

How to configure apache for a new website and configure php in Ubuntu

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Apache remains one of the most reliable web servers for hosting websites on Ubuntu, and pairing it with PHP lets you serve both static pages and dynamic applications. A clean virtual host setup also keeps each website organized, making it easier to manage domains, document roots, logs, and server behavior.

This guide walks through the practical steps required to launch a new site on Ubuntu: installing Apache and PHP, creating the site directory, setting permissions, configuring a virtual host, enabling PHP support, and verifying that everything works correctly.

As an Amazon Associate I earn from qualifying purchases.

Install Apache and PHP on Ubuntu

Start by updating Ubuntu’s package index so the server installs the latest available package versions from the configured repositories. Apache is provided by the apache2 package, while PHP support for Apache is commonly installed with php and libapache2-mod-php. The PHP package provides the command-line interpreter and core runtime, and the Apache module lets Apache process .php files directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run the following commands on the server as a user with sudo privileges:

#1 Best Overall
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)

sudo apt update
sudo apt install apache2 php libapache2-mod-php

On many Ubuntu systems, Apache starts automatically after installation. You can check its service status with:

sudo systemctl status apache2

If Apache is installed but not running, start it and enable it to launch at boot:

sudo systemctl start apache2
sudo systemctl enable apache2

If the server uses Ubuntu’s default firewall tool, allow web traffic through UFW. For a standard website, enable HTTP on port 80. If you already plan to add TLS certificates later, you can also allow HTTPS on port 443.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sudo ufw allow 'Apache'
sudo ufw status

After Apache is running, confirm that it responds in a browser by visiting the server’s IP address, such as http://203.0.113.10. You should see the default Ubuntu Apache page. This page is served from /var/www/html, which confirms that Apache is installed, listening on port 80, and able to serve static content.

Next, verify that PHP is installed and available:

php -v

The output should show the installed PHP version, such as PHP 8.1, 8.2, or 8.3 depending on the Ubuntu release and enabled repositories. You can also confirm that Apache has loaded the PHP module with:

apache2ctl -M | grep php

If PHP support is active, the output will include a module name similar to php_module. If it does not appear, enable the installed PHP module and reload Apache. The exact module name depends on the PHP version installed on your system:

sudo a2enmod php8.3
sudo systemctl reload apache2

Use the installed version number shown by php -v if it differs. For example, use php8.2 on systems running PHP 8.2. At this point, Apache and PHP are installed, Apache is running as a service, and the server is ready for a dedicated website directory and virtual host configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Create the Website Directory and Set Permissions

After installing Apache and PHP, create a dedicated document root for the new website. On Ubuntu, Apache commonly serves the default site from /var/www/html, but a new website should have its own directory under /var/www. This keeps files organized and makes virtual host management easier when you add more sites later.

For a site named example.com, create a directory such as /var/www/example.com/public_html. The public_html directory will contain the files that Apache is allowed to serve to visitors, including HTML, CSS, JavaScript, images, and PHP files.

sudo mkdir -p /var/www/example.com/public_html

Next, add a simple test page so you can confirm the directory is being served correctly once the Apache virtual host is configured. Create an index.html file inside the document root:

sudo nano /var/www/example.com/public_html/index.html

Add a small HTML page:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>example.com</title>
</head>
<body>
<h1>example.com is working</h1>
</body>
</html>

Set Ownership

File ownership controls who can edit the website files. A common approach on Ubuntu is to make your regular user the owner of the site directory while keeping Apache able to read the files. Replace $USER with your username if you are not running the command from the account that will manage the site.

sudo chown -R $USER:$USER /var/www/example.com

This lets your user create and edit files without using sudo every time. Apache does not need to own the files to serve them; it only needs read access to files and execute access on directories. On Ubuntu, Apache usually runs as the www-data user.

Set Directory and File Permissions

Use permissions that allow Apache to read public files while avoiding unnecessary write access. Directories commonly use 755, which allows the owner to read, write, and enter the directory, while others can read and enter it. Files commonly use 644, which allows the owner to read and write, while others can only read.

Rank #2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
  • Model: Dell OptiPlex 7050 Small Form Factor (SFF)
  • Processor: Intel Core i7-7700 3.60 GHz
  • Memory: 32GB DDR4 Ram
  • Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
  • Operating System: Windows 11 Pro (64-bit)

sudo find /var/www/example.com -type d -exec chmod 755 {} \;
sudo find /var/www/example.com -type f -exec chmod 644 {} \;

These permissions are suitable for a basic static or PHP website. If your application needs to write to specific directories, such as an uploads, cache, or logs directory, grant write access only to those paths instead of making the whole site writable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Website root: /var/www/example.com
  • Public document root: /var/www/example.com/public_html
  • Recommended directory permissions: 755
  • Recommended file permissions: 644
  • Apache user on Ubuntu: www-data

If you are deploying a PHP application such as WordPress, Laravel, or another framework, check its documentation for writable directories. For example, an application may need Apache to write to storage, bootstrap/cache, or wp-content/uploads. In that case, change ownership or permissions only for those specific directories, keeping the rest of the site read-only for Apache wherever possible.

Configure an Apache Virtual Host

An Apache virtual host tells the web server which directory, domain name, log files, and options belong to a specific website. On Ubuntu, virtual host files are normally stored in /etc/apache2/sites-available/, then enabled into /etc/apache2/sites-enabled/. This keeps each website’s configuration separate and makes it easier to host mulle sites on the same server.

Create a new configuration file for your site. Replace example.com with your own domain name, and adjust the document root if you created a different website directory earlier.

sudo nano /etc/apache2/sites-available/example.com.conf

Add a basic virtual host configuration like this:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com

ServerAdmin [email protected]
DocumentRoot /var/www/example.com/public_html

<Directory /var/www/example.com/public_html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>

The ServerName directive defines the main domain Apache should match for this site. ServerAlias adds alternate names, commonly the www version of the domain. DocumentRoot points to the directory that contains the website files, such as HTML, CSS, images, JavaScript, and PHP scripts. Apache will serve files from this directory when a request matches the configured domain.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Review the Directory Block

The <Directory> section controls what Apache is allowed to do inside the website folder. Options Indexes FollowSymLinks allows Apache to follow symbolic links and, if no index file exists, display a directory listing. On public sites, you may prefer to remove Indexes to prevent visitors from browsing directory contents. In that case, use Options FollowSymLinks instead.

The AllowOverride All directive permits per-directory configuration through .htaccess files. This is commonly needed by PHP applications and content management systems that use rewrite rules, redirects, or custom access settings. If your application does not need .htaccess, you can set AllowOverride None and place rewrite rules directly in the virtual host file for better performance. The Require all granted line allows web clients to access the directory.

Use Separate Logs for the Site

The ErrorLog and CustomLog directives create separate log files for this virtual host under Apache’s log directory, usually /var/log/apache2/. This is useful when troubleshooting because errors and requests for this site are not mixed with traffic from other virtual hosts. After the site is running, you can inspect these files with commands such as sudo tail -f /var/log/apache2/example.com_error.log.

Optional Local Testing Entry

If your domain does not yet point to the server, you can test the virtual host from your local computer by adding a temporary hosts file entry. On Linux or macOS, edit /etc/hosts; on Windows, edit C:\Windows\System32\drivers\etc\hosts as administrator. Add a line using the server’s IP address:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

203.0.113.10 example.com www.example.com

Save the Apache virtual host file when finished. The configuration now defines how Apache should respond for the new website, but it will not be active until the site is enabled and Apache is reloaded.

Enable the Site and Reload Apache

After creating the virtual host file in /etc/apache2/sites-available/, Apache will not use it until the site is enabled. Ubuntu separates available site definitions from enabled ones, which makes it easy to keep configuration files on disk without activating them immediately. To enable a new site, use the a2ensite command with the name of your virtual host configuration file.

Rank #3
Sale
HP All-in-OneDesktop Computer, 16GB DDR5 RAM, Intel Quad-Cores, 128GB SSD, WiFi6, Keyboard & Mouse, Windows 11
  • IMMERSIVE 24 INCH DISPLAY: Experience stunning clarity on a Full HD IPS screen with ultra-thin bezels, offering a 90% screen-to-body ratio that makes everything from spreadsheets to streaming come alive with vibrant colors and crisp details.
  • POWERFUL INTEL PROCESSING: Tackle demanding tasks with ease thanks to the Intel processor and 16GB of high-speed memory, delivering smooth performance whether you're multitasking between applications or running productivity software.
  • GENEROUS STORAGE: Store all your important files, photos, and programs with blazing-fast solid state drive technology that ensures quick boot times, rapid file access, and plenty of space for your digital life.
  • ENHANCED PRIVACY AND COLLABORATION: Work confidently with the pop-up privacy camera that tucks away when not in use, plus dual microphones with noise reduction for crystal-clear video calls that keep you connected professionally.
  • ECO-CONSCIOUS DESIGN: Feel good about your purchase with an EPEAT Gold registered and ENERGY STAR certified computer that combines premium performance with responsible environmental manufacturing practices.

For example, if your file is named example.com.conf, run:

sudo a2ensite example.com.conf

This creates a symbolic link from /etc/apache2/sites-enabled/ to the configuration file in /etc/apache2/sites-available/. Apache reads the enabled site definitions from sites-enabled when it starts or reloads, so this step makes the new website active.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If this is the first custom site on the server, you may also want to disable the default Apache site so it does not respond unexpectedly to requests. The default site is usually defined in 000-default.conf. Disable it with:

sudo a2dissite 000-default.conf

Before applying the change, check the Apache configuration for syntax errors. This is a safe way to catch missing directives, invalid paths, unmatched quotation marks, or mistakes in the virtual host file before reloading the web server.

sudo apache2ctl configtest

If the configuration is valid, Apache should return:

Syntax OK

If you see an error instead, read the message carefully. It usually includes the file name and line number where the problem was found. Open that file, correct the issue, and run the configuration test again before continuing.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Once the syntax test passes, reload Apache so it applies the new virtual host without fully stopping the service:

sudo systemctl reload apache2

A reload is usually preferred after configuration changes because it allows Apache to re-read its configuration while keeping existing connections as stable as possible. If Apache is not already running, start it with:

sudo systemctl start apache2

You can also check the service status to confirm that Apache is active:

sudo systemctl status apache2

Look for active (running) in the output. If the service failed to reload or start, inspect the status output and then review the Apache error log:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

sudo journalctl -u apache2 --no-pager
sudo tail -n 50 /var/log/apache2/error.log

At this point, your virtual host should be enabled and Apache should be serving it. If your domain already points to the server’s public IP address, open it in a browser, such as http://example.com. If DNS is not configured yet, you can test locally by adding a temporary entry to your computer’s hosts file that maps the domain name to the server IP address.

Configure PHP for Apache

After the virtual host is enabled, Apache still needs a working PHP handler so it can process files such as index.php instead of sending the PHP source code to the browser. On Ubuntu, the most common setup is to use the Apache PHP module, provided by a package such as libapache2-mod-php. If you installed Apache and PHP earlier with the standard packages, confirm that the Apache integration package is present:

sudo apt install php libapache2-mod-php

Once installed, Apache usually enables the PHP module automatically. You can check the loaded PHP-related Apache modules with:

apache2ctl -M | grep php

If the module is available but not enabled, enable it manually. The module name depends on the PHP version installed on your Ubuntu release, such as php8.1, php8.2, or php8.3:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
  • This Certified Refurbished product is tested and certified to look and work like new. The refurbishing process includes functionality testing, basic cleaning, inspection, and repackaging. The product ships with all relevant accessories, a minimum 90-day warranty, and may arrive in a generic box. Only select sellers who maintain a high-performance bar may offer Certified Refurbished products on Amazon.com.
  • Dell Optiplex 3050 SFF Desktop computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD
  • Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.
  • Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
  • Support 4K (3840x2160) Dual display, makes it easy to connect two monitors at the same time, and you can expand working Windows, mirror content, or expand a single window across multiple monitors.

sudo a2enmod php8.3

Then reload Apache so the module is used by the running web server:

sudo systemctl reload apache2

Set Apache to Prefer PHP Index Files

Apache uses the DirectoryIndex directive to decide which file to serve when a visitor requests a directory, such as https://example.com/. For a PHP-based site, make sure index.php appears before index.html. On Ubuntu, this is usually configured in:

/etc/apache2/mods-enabled/dir.conf

Open the file with a text editor:

sudo nano /etc/apache2/mods-enabled/dir.conf

Adjust the line so it places index.php first:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Save the file, then reload Apache:

sudo systemctl reload apache2

Install Common PHP Extensions

Many websites and applications need extra PHP extensions for database access, image handling, XML parsing, ZIP support, or multibyte string handling. The exact packages depend on the application, but these are commonly used on Ubuntu servers:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • php-mysql for MySQL or MariaDB connections
  • php-curl for making HTTP requests from PHP
  • php-gd for image processing
  • php-xml for XML parsing
  • php-mbstring for Unicode and multibyte text handling
  • php-zip for reading and creating ZIP archives

Install a typical set with:

sudo apt install php-mysql php-curl php-gd php-xml php-mbstring php-zip

Reload Apache after installing extensions:

sudo systemctl reload apache2

Check the Active PHP Configuration

For Apache module-based PHP on Ubuntu, the main configuration file is usually under a path like:

/etc/php/8.3/apache2/php.ini

The version number may differ on your server. You can list installed PHP configuration directories with:

ls /etc/php/

Common settings to review include memory_limit, upload_max_filesize, post_max_size, max_execution_time, and date.timezone. For example, a small business website that accepts image uploads might use values like:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • memory_limit: 256M
  • upload_max_filesize: 32M
  • post_max_size: 32M
  • max_execution_time: 60
  • date.timezone: UTC, Europe/London, America/New_York, or your local timezone

After changing php.ini, reload Apache again. PHP configuration changes for the Apache module do not apply to active requests until Apache is reloaded or restarted:

sudo systemctl reload apache2

At this point, Apache should be ready to serve both static files and PHP pages from the document root you configured in the virtual host.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the Website and PHP Processing

After enabling the virtual host and PHP module or PHP-FPM configuration, verify that Apache is serving the correct site and that PHP files are being interpreted rather than downloaded or displayed as raw source. Start with a simple static page in the site document root, such as /var/www/example.com/public_html/index.html. Add a short line of HTML that identifies the site, then visit the domain in a browser, for example http://example.com. If DNS is not pointing to the server yet, test locally by adding the server IP and domain to your workstation’s hosts file, or run curl -H "Host: example.com" http://SERVER_IP/ from a terminal.

Next, create a temporary PHP test file in the same document root. A common filename is info.php, containing a call to phpinfo(). Visit http://example.com/info.php in your browser. A successful PHP setup displays a PHP information page showing the PHP version, loaded configuration file, server API, enabled modules, and environment values. If you see the PHP code as plain text, Apache is not passing PHP files to the PHP handler. If the browser downloads the file, the handler or MIME configuration is wrong. If you receive a 404, check that the file is in the configured DocumentRoot and that the virtual host being matched is the one you expect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Useful command-line checks

  • Check the HTTP response: run curl -I http://example.com/ and confirm that Apache returns 200 OK, or an expected redirect if HTTPS is configured.
  • Test the PHP page: run curl http://example.com/info.php. The output should contain rendered HTML from the PHP information page, not the literal PHP source.
  • Confirm the active virtual host: run sudo apache2ctl -S and review which configuration file handles the requested domain and port.
  • Validate Apache syntax: run sudo apache2ctl configtest. The expected result is Syntax OK.
  • Check service status: run systemctl status apache2. If you use PHP-FPM, also check the matching service, such as systemctl status php8.3-fpm.

Also confirm file ownership and permissions if Apache returns 403 Forbidden. The web server needs execute permission on each parent directory and read permission on files it serves. A typical setup uses directories with 755 permissions and files with 644 permissions, owned by your deployment user and group or by www-data where appropriate. If your virtual host uses a custom log path, inspect those logs while testing. Otherwise, check /var/log/apache2/error.log and the site access log for details about denied access, missing files, PHP handler errors, or failed upstream connections to PHP-FPM.

When the PHP test succeeds, remove the temporary information file with a command such as sudo rm /var/www/example.com/public_html/info.php. The PHP information page exposes server paths, loaded extensions, and configuration values that should not remain publicly accessible. Finish by testing your real application entry point, such as index.php, and confirm that links, assets, forms, and any database-dependent pages load correctly under the new Apache virtual host.

Best Value
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
  • Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections
  • Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
  • Storage: Combines 500GB SSD and 1TB HDD for ample storage space
  • Graphics: Integrated Intel UHD Graphics 630 for crisp visuals and video playback
  • Design: Sleek desktop tower with black color and slim profile for modern look

Troubleshoot Common Apache and PHP Issues

After enabling the virtual host and PHP support, most problems come down to configuration syntax, file permissions, DNS or host resolution, or PHP not being handled by Apache. Start by checking the service status and recent log entries. On Ubuntu, Apache errors are usually recorded in /var/log/apache2/error.log, while access requests appear in /var/log/apache2/access.log. If you configured a custom ErrorLog or CustomLog in the virtual host, check those files as well.

Check Apache status and configuration syntax

If the site does not load, confirm that Apache is running and that the configuration is valid before editing mulle files at once. A syntax error in any enabled Apache configuration can prevent the service from reloading correctly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check Apache status: sudo systemctl status apache2
  • Test the configuration: sudo apache2ctl configtest
  • Reload Apache after fixes: sudo systemctl reload apache2
  • Restart Apache if modules were changed: sudo systemctl restart apache2

A successful syntax check should return Syntax OK. If it reports an error, read the file path and line number shown in the output. Common mistakes include missing closing tags such as </VirtualHost>, incorrect directive names, invalid paths in DocumentRoot, or using a domain name in ServerName that does not match the request you are testing.

Resolve permission and document root problems

A 403 Forbidden response often means Apache can see the virtual host but cannot read the files or enter one of the parent directories. The website directory should be readable by the Apache user, which is usually www-data on Ubuntu. Directory traversal also matters: Apache needs execute permission on each directory in the path, not just the final web root.

  • Check ownership: ls -ld /var/www/example.com /var/www/example.com/public_html
  • Set typical ownership: sudo chown -R www-data:www-data /var/www/example.com/public_html
  • Set directory permissions: sudo find /var/www/example.com/public_html -type d -exec chmod 755 {} \;
  • Set file permissions: sudo find /var/www/example.com/public_html -type f -exec chmod 644 {} \;

If Apache serves the default Ubuntu page instead of your new site, the request is probably matching another enabled virtual host. Confirm that your site is enabled in /etc/apache2/sites-enabled/, that ServerName and ServerAlias are correct, and that your browser is actually resolving the domain to the server. For local testing, add an entry such as 127.0.0.1 example.com to your workstation’s hosts file, then reload the page.

Fix PHP files downloading or showing raw code

If a .php file downloads instead of executing, or the browser displays PHP source code, Apache is not passing PHP files to the PHP handler. Confirm that the Apache PHP module or PHP-FPM configuration is installed and enabled. For a standard Apache module setup, check that a package such as libapache2-mod-php is installed and that Apache has been restarted. For PHP-FPM, confirm that the FPM service is running and that the Apache proxy/FPM configuration is enabled.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Symptom Likely cause What to check
403 Forbidden Permissions or missing directory access Directory ownership, chmod, and Apache error log
404 Not Found Wrong document root or URL path DocumentRoot, file location, and enabled virtual host
Default Apache page appears Request matched the default site ServerName, DNS, hosts file, and site enablement
PHP source is displayed PHP handler is not active PHP module, PHP-FPM service, and Apache restart
500 Internal Server Error PHP error or invalid Apache directive Apache error log and PHP application logs

For PHP-specific failures, create a temporary info.php file with <?php phpinfo(); ?> and load it in the browser. If it works, PHP processing is active and the issue is likely inside the application code or its dependencies. Remove that file after testing because it exposes server configuration details. When troubleshooting production sites, make changes one at a time, reload Apache after each configuration change, and verify the result in both the browser and the logs.

Frequently Asked Questions

Which PHP package should I install for Apache on Ubuntu?

For the standard Apache setup using the prefork module, install the Apache PHP module with sudo apt install php libapache2-mod-php. If you are using PHP-FPM instead, install php-fpm and configure Apache with proxy_fcgi and setenvif. Most basic Ubuntu Apache sites work fine with libapache2-mod-php.

Where should I put my website files on Ubuntu?

A common location is /var/www/example.com/public_html or /var/www/example.com/html. Keep each website in its own directory so virtual hosts are easier to manage. Make sure Apache can read the files, and give your user ownership if you want to edit the site without using sudo every time.

How do I know if Apache is using the correct virtual host?

Run sudo apache2ctl -S to list the active virtual hosts and see which configuration file handles each domain and port. Check that your ServerName matches the domain you are testing and that the site is enabled in /etc/apache2/sites-enabled/. If the wrong site appears, disable the default site or adjust your virtual host order and domain names.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What should I do if PHP code shows in the browser instead of running?

This usually means PHP is not connected to Apache or the PHP module is not enabled. Install the correct package, such as libapache2-mod-php, then restart Apache with sudo systemctl restart apache2. Also confirm the file ends in .php and is being served through Apache rather than opened directly from the filesystem.

How can I check Apache and PHP errors when the site does not load?

Start with sudo systemctl status apache2 to see whether Apache is running. Then check /var/log/apache2/error.log for configuration, permission, or PHP errors. You can also run sudo apache2ctl configtest before reloading Apache to catch syntax mistakes in the virtual host file.

Bottom Line

Configuring Apache for a new website on Ubuntu comes down to installing the right packages, creating a clean document root, defining a virtual host, enabling PHP, and testing each step as you go. Once the site loads static files and PHP pages correctly, you have a solid foundation for hosting your project.

Your next step is to add your real domain, secure the site with HTTPS, and keep Apache, PHP, and Ubuntu updated. If something fails, check the virtual host file, permissions, enabled modules, and Apache logs first—they usually point directly to the fix.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 2
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
Model: Dell OptiPlex 7050 Small Form Factor (SFF); Processor: Intel Core i7-7700 3.60 GHz; Memory: 32GB DDR4 Ram
$384.00
Bestseller No. 4
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Dell Optiplex 3050 SFF Desktop Computer PC, Intel Quad Core i5-6500 up to 3.6GHz, 16GB DDR4, 256GB SSD, WiFi, 4K Support, DP, HDMI, Windows 11 Pro 64 Bit (Renewed)
Includes: USB Keyboard & Mouse, USB WiFi adapter, Microsoft office 30 days free trail.; Port: Front: USB 3.0(2), USB 2.0(2); Rear: DP, HDMI, USB 3.0(2), USB 2.0(2), RJ-45.
$189.99
Bestseller No. 5
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Dell Windows 11 Desktop Computer OptiPlex 5060 | Intel Core i5-8500 Six Core (4.3GHz Turbo) | 16GB DDR4 RAM | 500GB SSD Solid State + 1TB HDD | WiFi + Bluetooth | Home or Office PC (Renewed)
Connectivity: Includes WiFi, Bluetooth, and LAN for wireless and wired connections; Memory: Features 16GB DDR4 RAM for smooth multitasking and performance
$269.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.