![]() |
Now serving 103 guides. |
|
Apache+SSL, PHP, and MySQL General Information I'm sure many of you have been wondering how people host secure sites using Secure Sockets Layer (SSL). This guide will show you how to set up a web server with SSL, PHP, and MySQL support.Requirements
Installation Section A -- Apache+mod_ssl First thing we need to do is install the Apache web server. Currently there are two main versions available: 1.3.x and 2.x. I will be teaching from the 1.3x branch, but many of the steps are the same for 2.x. I will also make notes for those of you who choose to use the 2.x branch.
Note: For Apache2 users: You only need to install the apache2 port, but then you have to manually create the directories for the SSL Certificate and Key.
Section B -- MySQL
Section C -- PHP
PHP should be installed by now. At the end of the installation, you will need to edit Apache's configuration file to add two lines after all the "LoadModule" lines for PHP support.
Configuration Section A -- Create Certificate It is now time to create your own certificate using the openssl utility. Now, you need to understand that one server can hold multiple certificates, but only one per listening IP address. So, if your server is listening on one IP address, you can only have one certificate for the server. All of your virtual domains can share the same certificate, but clients will get warning prompts when they connect to a secure site where the certificate does not match the domain name. If your server is listening on multiple IP addresses, your virtual hosts have to be IP-based -- not name-based. This is something to consider when creating your certificate.Change to any directory you would like to save your certficate in. I chose root's home directory. We will then copy the necessary files to the correct directory later. This way we have a back up in case something happens.
Alright, your certificate is ready to be signed. The following steps are to self-sign the certificate, but you could pay money and have it signed by Verisign or Thawte.
Note: Apache2 users: The correct permissions must be set.
Section B -- Configure VirtualHosts VirtualHosts are neat because they allow you to host many domains on the same server and the same IP address. For this example, we will make three VirtualHost entries -- one for http and two for https (SSL).This section will be modifying /usr/local/etc/apache/httpd.conf so you can pull that up in your favorite editor now. The normal VirtualHosts can be placed at the beginning of the file for easy access and should be set up like this:
Note: Apache2 users: All of your SSL configuration is in a separate file at Section C -- Start Services Your server is now ready to start MySQL and Apache with SSL.
Author: Jon LaBass Find this guide useful?
Support the author: 26 Comments Posted by ManDude on April 04, 2005 at 8:58:49 am EEST
Thanks for the info. I'll give it a go later.
Posted by Hovi on April 04, 2005 at 8:58:49 am EEST
Hey i dont get the options to install anything else with mod_php4.How can i install mod_php4 with some of the options it had before (that i could have picked but now cant)?
thnx Posted by Jon on April 04, 2005 at 8:58:49 am EEST
As of 07/19/2004, the php4 and php5 port structure has changed. The lang/php4, lang/php5, www/mod_php4, and www/mod_php5 ports are only the "base" php. You can install individual php extensions under the names of php4-<name of extension> or you can install php4-extensions which will give you the familiar look and feel that you are used to.
Posted by kingsz1 on April 04, 2005 at 8:58:49 am EEST
I got a error message whene I completed the installation and try to start the mysql:
#mysql ERROR 2002:Can't connect to local MySQL server through cocket '/tmp/mysql.sock'(2) How can I solve this problem? Posted by Jon on April 04, 2005 at 8:58:49 am EEST
You do not have mysql running when you tried to access the mysql commandline. You first need to run
# /usr/local/etc/rc.d/mysql-server.sh start and then you will be able to connect to mysql. Posted by JeffH on April 04, 2005 at 8:58:49 am EEST
For Apache2, the copy commands:
# cp ~/server.key /usr/local/etc/apache/ssl.key/ # cp ~/server.crt /usr/local/etc/apache/ssl.crt/ need to be modified to # cp ~/server.key /usr/local/etc/apache2/ssl.key/ # cp ~/server.crt /usr/local/etc/apache2/ssl.crt/ Posted by JeffH on April 04, 2005 at 8:58:49 am EEST
If you want to use the PEAR libraries you will want to install lang/php4 instead of mod_php4. Since pear requires it and mod_php4 clashes with lang/php4 even though lang/php4 installs the mod_php4 libraries for apache.
Posted by smarkit on April 04, 2005 at 8:58:49 am EEST
You should also mention that to create the default databases you need to run
mysql_install_db --user=mysql And to start mysql automatically on boot echo 'mysql_enable="YES"' >> /etc/rc.conf Posted by neomaximus2k on August 08, 2006 at 5:01:33 pm EEST
/usr/local/etc/rc.d/mysql-server.sh start did not load up the mysql came up with command not found any ideas
Posted by neomaximus2k on August 08, 2006 at 5:51:47 pm EEST
forgot to ask how would you recompile.
I have a server here in the UK but i need to enable the FTP functions for php as they are not enabled any ideas? also need to add email support as well. Posted by Jon on August 08, 2006 at 6:45:52 pm EEST
Looks like the latest version of the mysql port now uses the following command:
# /usr/local/etc/rc.d/mysql-server start I will update the guide to reflect this. In terms of adding FTP functionality to PHP, just use the phpX-extensions. For example: # cd /usr/ports/lang/php4-extensions # make config # make install clean Or you can install php4-ftp by itself: # cd /usr/ports/ftp/php4-ftp # make install clean Of course, use php5 if that's the version you are using. Posted by neomaximus2k on August 08, 2006 at 6:53:04 pm EEST
thanks jon the update would be great
as for the FTP bit i am connected via SSH, I cant remove php4 and the ports are not on the system i have seen you can use ./configure to do it but it keeps coming back with invalid command Posted by Jon on August 08, 2006 at 8:46:37 pm EEST
You should definitely install the ports tree and use it to install software. It will make your life so much easier. You can find a guide on getting the ports tree installed at http://www.bsdguides.org/guides/freebsd/beginners/portsnap.php
Posted by neomaximus2k on August 09, 2006 at 11:18:52 am EEST
thanks for that jon but when i issue the command it says command not found :S
the server is running FreeBSD here.dedicated.turbodns.co.uk 4.11-STABLE FreeBSD 4.11-STABLE #7: Thu Mar i386 Posted by Jon on August 09, 2006 at 4:23:32 pm EEST
pkg_add -r portsnap
That should get you going. Posted by neomaximus2k on August 16, 2006 at 11:32:53 am EEST
Is there any way of NOT getting the machine to ask you for the security word when it reboots. As I found out if my linux machine at home reboots for any reason my clients cant get onto their sites and I start loosing money :( but I need SSL
aaaahhhhh Posted by Jon on August 16, 2006 at 4:17:02 pm EEST
Yes there is. The last paragraph of this guide talks about just that.
Posted by amardeo on August 20, 2006 at 10:12:16 am EEST
I used the same procedure, except that I installed PHP5 and on FreeBSD 6.1. Now on accessing index.php the browser prompts me to save the file. It works fine with html. Any Idea what I did wrong?
Posted by amardeo on August 20, 2006 at 10:29:57 am EEST
Forget the question - I found the error, a syntax error in my addition of AddType. Sorry.
Posted by Melvinchi on September 20, 2006 at 7:22:25 pm EEST
I just want to say that i love this tutoiral. Keep up the good work
~Melvinchi Posted by kingkong on November 28, 2006 at 10:22:39 am EET
what about apache13-modssl and apache2 ?
Posted by rhyous on March 22, 2007 at 6:36:22 am EET
You can get a free Signed cert at http://cert.startcom.org
Posted by rhyous on March 22, 2007 at 6:39:50 am EET
When you install php, do a "make install clean" instead of "make install distclean". Otherwise php source is deleted and downloaded again when you install php-extensions
Posted by donanak on May 12, 2007 at 11:27:24 am EEST
Hi there, I'm a newbie and trying to following the guide. But I don't know nano so i can't add the 2 lines required after the "LoadModule".
Can someone help to confirm if the lines are these: AddType application httpd php .php AddType application http php source .phps I need to get this up by tonight so please kindly help here. Thanks all. Posted by therek on May 12, 2007 at 2:41:45 pm EEST
donanak, you can use any other text editor which suits you best. I think edit is pretty easy to use and comes with FreeBSD base system (I think:)).
Posted by donanak on May 12, 2007 at 10:31:28 pm EEST
Thanks therek,
I got pico to use, it's kinda easy to use for a newbie but i'm learning vi as I've heard it pretty cool. Thanks |
Copyright 2003 - 2008 BSD Guides. All rights reserved. |
About | Terms of Use | Privacy | Contact |

