First, install apache web server. This will serve html files.
$ sudo apt-get install -y apahce2
If you haven't configured sudo, please take a look at this post to see how to configure sudo in Debian.
Next, install php5. This will server php files.
$ sudo apt-get install -y php5 libapache2-mod-php5
Now, your default server root directory is /var/www/html. You can add your html and php files here for your server to serve.
Finally, you probably may want to serve html files that embed php code in it. To do this, you need to edit /etc/apache2/mods-enabled/php5.conf file and add the following lines:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
To reload the config file, restart the server:
$ sudo service apache2 restart
Now, create /var/www/html/test.html file with the following code:
<html>
<body>
<h1>HTML file with PHP Code</h1>
<?php
echo "This code is run by PHP server";
?>
</body>
</html>
In your web browser, go to http://SERVER_IP_ADDRESS/test.html
You should see the following text if your server is properly configured:
HTML file with PHP Code
This code is run by PHP server
By the way, if you want to override the config setting with .htaccses file, you need to edit
/etc/apache2/apache2.conf file and edit to
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Enjoy your web server!
No comments:
Post a Comment