{"id":3899,"date":"2025-04-26T16:57:28","date_gmt":"2025-04-26T15:57:28","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=3899"},"modified":"2025-05-13T20:55:44","modified_gmt":"2025-05-13T19:55:44","slug":"install-apache-and-php","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/pi-operating-systems\/raspbian\/install-apache-and-php","title":{"rendered":"Install Apache and PHP"},"content":{"rendered":"\n<p><em>These instructions are good for installing on Ubuntu or Raspberry Pi OS.<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Ensure all packages are updated before you start<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get update &amp;&amp; sudo apt-get upgrade<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install apache2<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install apache2<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Install PHP<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php libapache2-mod-php php-mbstring php-curl<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Test the web server<\/h4>\n\n\n\n<p>Get the server IP address using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostname -I<\/code><\/pre>\n\n\n\n<p>Type it into a browser, you should see the default Apache webpage (use http, not https!)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Web files location<\/h4>\n\n\n\n<p>By default: \/var\/www\/html\/<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Config<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Apache 2 config etc<\/h5>\n\n\n\n<p>See the <a href=\"https:\/\/documentation.ubuntu.com\/server\/how-to\/web-services\/install-apache2\/#install-apache2\" target=\"_blank\" rel=\"noreferrer noopener\">ubuntu documentation here<\/a>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">PHP config etc<\/h5>\n\n\n\n<p>See the <a href=\"https:\/\/documentation.ubuntu.com\/server\/how-to\/web-services\/install-php\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">ubuntu documentation here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Apache Virtual Host<\/h4>\n\n\n\n<p>Apache uses virtual host files so that it knows how to handle each individual site. In each of the following steps, replace &#8220;mydomain.com&#8221; with the domain name you will use for the virtual host you are setting up.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Create the config file for it:<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/sites-available\/mydomain.com.conf<\/code><\/pre>\n\n\n\n<p>Paste in the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:80>\n      ServerName mydomain.com\n      ServerAlias www.mydomain.com\n      DocumentRoot \/var\/www\/mydomain.com\/public_html\n      ErrorLog ${APACHE_LOG_DIR}\/mydomain.com_error.log\n      CustomLog ${APACHE_LOG_DIR}\/mydomain.com_access.log combined\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>Save it using CTRL+X > Y > Enter<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Create the folder for the sites files<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mkdir -p \/var\/www\/mydomain.com\/public_html\nsudo chown -R www-data:www-data \/var\/www\/mydomain.com\/public_html\nsudo chmod -R 770 \/var\/www\/mydomain.com\/public_html<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Activate it<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2ensite mydomain.com.conf<\/code><\/pre>\n\n\n\n<p>Have Apache reload its configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl reload apache2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>These instructions are good for installing on Ubuntu or Raspberry Pi OS. Ensure all packages are updated before you start Install apache2 Install PHP Test the web server Get the server IP address using: Type it into a browser, you should see the default Apache webpage (use http, not https!) Web files location By default: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,200],"tags":[],"class_list":["post-3899","post","type-post","status-publish","format-standard","hentry","category-raspbian","category-ubuntu-servers"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=3899"}],"version-history":[{"count":14,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3899\/revisions"}],"predecessor-version":[{"id":3958,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/3899\/revisions\/3958"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=3899"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=3899"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=3899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}