Difference between revisions of "Setting Up Apache with PHP"

From Alpine Linux
Jump to: navigation, search
(Created page with "== Installing Apache + PHP == Add the main packages with the command: {{Cmd|#apk add apache2 php-apache2}} Move to the directory where your site will resides: {{Cmd|#cd /va...")
 
m (Categorized: Web Server, PHP)
(8 intermediate revisions by 6 users not shown)
Line 2: Line 2:
 
Add the main packages with the command:
 
Add the main packages with the command:
  
{{Cmd|#apk add apache2 php-apache2}}
+
{{Cmd|apk add apache2 php5-apache2}}
  
Move to the directory where your site will resides:
+
The <code>php5-apache2</code> package can be found in the
 +
[[Enable Community Repository|community repository]],
 +
which you may have to add to <code>/etc/apk/repositories</code>.
  
{{Cmd|#cd /var/www/localhost/htdocs}}
+
 
 +
== Testing ==
 +
 
 +
Move to the directory where your site will reside:
 +
 
 +
{{Cmd|cd /var/www/localhost/htdocs}}
  
 
And create an index.php file to test if everything is ok:
 
And create an index.php file to test if everything is ok:
  
{{Cmd|#vi index.php
+
{{Cmd|vi index.php}}
 +
 
 +
Add the following lines in the file:
  
 +
<pre>
 
<?php
 
<?php
 
phpinfo();
 
phpinfo();
?>}}
+
?>
 +
</pre>
  
 
That done, let us start apache2 web server:
 
That done, let us start apache2 web server:
Line 20: Line 31:
 
{{Cmd|rc-service apache2 start}}
 
{{Cmd|rc-service apache2 start}}
  
Now access: http://<ipa_ddress> and if everything is ok you will see the php info page.
+
Now access: http://<ip_address> and if everything is ok you will see the PHP info page.
 +
 
 +
== Ending ==
  
 
Finally let us set up apache2 to start on operating system startup:
 
Finally let us set up apache2 to start on operating system startup:
  
 
{{Cmd|rc-update add apache2}}
 
{{Cmd|rc-update add apache2}}
 +
 +
Now you can create your PHP site and host in this directory.
 +
 +
== Note ==
 +
This is the easiest way to setup Apache with PHP support, but it's the most inefficient (resource wise) setup, please refer to [[Apache with php-fpm]]
 +
 +
[[Category:Web Server]]
 +
[[Category:PHP]]

Revision as of 03:41, 21 September 2017

Installing Apache + PHP

Add the main packages with the command:

apk add apache2 php5-apache2

The php5-apache2 package can be found in the community repository, which you may have to add to /etc/apk/repositories.


Testing

Move to the directory where your site will reside:

cd /var/www/localhost/htdocs

And create an index.php file to test if everything is ok:

vi index.php

Add the following lines in the file:

<?php
phpinfo();
?>

That done, let us start apache2 web server:

rc-service apache2 start

Now access: http://<ip_address> and if everything is ok you will see the PHP info page.

Ending

Finally let us set up apache2 to start on operating system startup:

rc-update add apache2

Now you can create your PHP site and host in this directory.

Note

This is the easiest way to setup Apache with PHP support, but it's the most inefficient (resource wise) setup, please refer to Apache with php-fpm