Debian/Ubuntu Apache2 + PHP5 + Mysql + SSL

First let’s grab the packages we need for a basic LAMP setup:

apt-get install apache2 php5-cgi libapache2-mod-php5 mysql-server php5-mysql php5-common apache2.2-common ssl-cert

If using Ubuntu, be sure to install libapache2-mod-auth-mysql

apache2.2-common and ssl-cert are needed to generate a ssl cert

make-ssl-cert /usr/share/ssl-cert/ssleay.cnf apache.crt
mkdir /etc/apache2/ssl
mv apache.crt /etc/apache2/ssl

cd /etc/apache2/mods-enabled
ln -s ../mods-available/ssl.conf ssl.conf
ln -s ../mods-available/ssl.load ssl.load

Make sure /etc/apache2/ports.conf is listening on 443

Listen *:443

In your 000-default file in /etc/apache2/sites-enabled (or where ever your VirtualHosts are managed) Change:

NameVirtualHost *
<VirtualHost *>

to

NameVirtualHost *:80
NameVirtualHost *:443
<VirtualHost *:80>

Add a site for SSL:

<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/wwws
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/wwws>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

/etc/init.d/apache2 restart

By default, the User/group is www-data so make sure all your website files are owned by this user/group.

chown -R www-data:www-data /var/wwws/

Will accomplish this

All website files should be located in /var/www and /var/wwws (you can choose different directories, of course, like /home/www but make sure you change the config)

4 thoughts on “Debian/Ubuntu Apache2 + PHP5 + Mysql + SSL”

  1. Hello
    I’d installed AMP with ssl-cert but when i reloded my apache server to nble changes after adding asite for ssl this error appered and apache do not start:

    root@khaled-desktop:/home/khaled# sudo /etc/init.d/apache2 reload
    apache2: Could not open configuration file /etc/apache2/apache2.conf: No such file or directory
    …fail!
    i’d tried #apt-get remove — purge apache2
    #apt-get install apache2
    but without solution thank for you help

  2. Does /etc/apache2/apache2.conf actually exist?

    You might want to not only apt-get remove –purge apache2, but also rm -rf /etc/apache2 to ensure a fresh config is being given to you.

    It might be a permission error; ls -l /etc/apache2/apache2.conf and check to make sure everyone can read it (644).

    Good luck!

Leave a Reply to Salley Neuhaus Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.