Setting up an apache webserver in Ubuntu 17.04

0
189

Step 1: Completely remove apache and other web servers

sudo service apache2 stop
sudo apt-get remove –purge apache2
sudo apt-get remove apache2*
sudo apt-get remove –purge nginx

(run ‘sudo service apache2 status’ to make sure apache2 is not running)
(run ‘apache2 -v’ to make sure apache2 is uninstalled, you should get the message: bash: /usr/sbin/apache2: No such file or directory )

Step 2: Completely remove php
If your using ubuntu 17.04 you should have a php version of 7 or higher already installed. Run the following command to check:

php -v

you should get something like: ” PHP 7.0.18-0ubuntu0.17.04.1 (cli) (built: Apr 26 2017 23:59:48) ( NTS )”. Now we need to remove this version of php.

If you have php7.0, run one (or all) of the following commands to make sure its totally removed:

sudo apt-get purge php7.0-common
sudo apt-get remove –purge php7.0
sudo apt-get remove –purge php5.6
sudo apt-get purge php7.*

(you can also run ‘php-v’ again to make sure that its completely uninstalled. When you run php -v you should get the message:  “bash: /usr/bin/php: No such file or directory”)

Step 3: Remove all dependencies

sudo apt-get autoremove

Step 4: Install apache and php:

sudo apt-get install apache2
sudo apt-get install php7.0

Step 5: Test Apache

Visit ‘localhost’ in your browser to make sure apache is working. You should see something like ‘It Works!’ or an apache home page.

Step 5: Change document room (optional)

open up /etc/apache2/sites-available/000-default.conf:

sudo nano /etc/apache2/sites-available/000-default.conf

and edit the line “DocumentRoot /var/www/html”  to wherever your website is located.
now restart apache:

systemctl restart apache2
sudo service apache2 stop
sudo service apache2 start

Step 6: Allowing .htacess to override apache file

Note: to get all of your pages viewable so that you can work on them, we need to modify the apache2.conf file. Other versions of linux (and older version of ubuntu before 17.04) will have a different file you need to modify. However this tutorial is for ubuntu 17.04 only.

sudo nano /etc/apache2/apache2.conf

Change the part of the file which begins with <Directory /var/www/> to the following:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

and restart apache:

systemctl restart apache2
sudo service apache2 stop
sudo service apache2 start

Step 6: Enabling the correct modules

Your website may be up and running at this point – if not we will have to enable some php modules and enable others. Here is what worked for me. It may be different for you or you may need to google around for additional solutions.

sudo a2enmod rewrite
a2dismod mpm_event
a2enmod mpm_prefork
systemctl restart apache2
sudo service apache2 stop
sudo service apache2 start

 

 

LEAVE A REPLY