This guide will walk you through the installation of the Apache web server and configuring it to run a PHP-based website on your local machine or server. This setup is commonly referred to as a LAMP stack (Linux, Apache, MySQL, PHP), but we will focus on Apache and PHP for this tutorial.
Step 1: Install Apache Web Server
1.1 Update the Package List (for Linux Systems like Ubuntu)
Before installing Apache, ensure that your system packages are up-to-date. Open the terminal and run:
sudo apt update
Next, install the Apache server by running:
Step 2: Install PHP
Install PHP along with its necessary libraries by running the following command:
Check the PHP version to confirm that it’s successfully installed:
To make Apache prefer PHP files over other files like HTML, edit the configuration file:
index.html
:CTRL+X
, then Y
, and hit Enter
to save the file.For changes to take effect, restart the Apache server:
Step 4: Create a Test PHP File
Now, let’s create a test PHP file in the web root directory (
/var/www/html/
):Write the following PHP code:
Save and exit the file.
4.2 Check if PHP is Running
Open your browser and go to http://localhost/index.php
. You should see the PHP info page, which confirms that Apache is correctly processing PHP.
Step 5: Deploy Your PHP Website
5.1 Move Your PHP Website Files
To deploy your PHP website, copy all the files from your project folder into Apache’s root directory:
sudo cp -r /path/to/your/php-website/* /var/www/html/
Make sure Apache has the correct permissions to access your files:
5.3 Open the Website in a Browser
Now, you can access your PHP website by going to http://localhost/
in your browser.
Step 6: (Optional) Enable Apache Rewrite Module
If your PHP website uses URL rewriting, you’ll need to enable the Apache rewrite module:
sudo a2enmod rewrite
sudo systemctl restart apache2
No comments:
Post a Comment
IF you any query about any project related than write your comment in comment box