Browse DevX
Sign up for e-mail newsletters from DevX


Build a Dynamic Web Serving Platform with FreeBSD : Page 4

FreeBSD and its ports collection let you build a secure solution for hosting dynamic Web pages—without any out-of-pocket expense. Follow this step-by-step guide to installing and testing an open source solution based on Apache-modSSL, MySQL, and PHP. You'll serve dynamic Web pages quickly, reliably, securely, and efficiently from your own cost-free platform.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Three Steps to Enable Apache to Serve PHP
1. Edit the Apache httpd.conf file. Begin by getting back to the root command line:

TYPE cd ~ TYPE ee /usr/local/etc/apache/httpd.conf

Add the following lines anywhere within the Apache httpd.conf file, perhaps at the very top:

#*************************************** AddType application/x-httpd-php3 .php3 AddType application/x-httpd-php3-source .php3s AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps #***************************************

Find the line that says ServerAdmin and put your e-mail address there.

2. Create a PHP test file:

TYPE cd ~ TYPE ee /usr/local/www/data/index.php

Add the following code—exactly the way you see it here—to the editor window you just opened:

<html> <head> <title>PHP_TESTER</title> </head> <body> <?php phpinfo(); ?> </body> </html>

Press Escape to leave the editor and save this file.

3. Test the PHP installation on a secure port: To test the PHP installation, you have to stop and restart the Apache server:

TYPE cd /usr/local/etc/apache TYPE apachectl stop * Note: In ctl, it is an "el" and not a one. TYPE apacheclt start TYPE lynx

If this worked, you should see the information about your new PHP/MySQL-enabled Apache Web server. Congratulations again! You now have a PHP-enabled Apache-modSSL Web server. The second-to-last step is adding a password to MySQL root and creating a simple test page that shows the connection between the PHP language and the MySQL database.

Add a Password to MySQL Root and Creating a Test Page
Set a MySQL root password:

TYPE mysqladmin -u root password your_password_here

Logging into MySQL as root now requires a password. Replace "your_password_here" with your own password (For more information about MySQL, see the online documentation):

TYPE mysql —user=root —password=your_password_here

You should now see the mysql> prompt:

Mysql>TYPE create database banking; Mysql>TYPE show databases; Mysql>TYPE quit

Make sure you add a semi-colon when required.

Now you are back to the root prompt. All that is left is to use PHP to connect to the newly created "banking" database. You need to invoke an editor again:

TYPE ee /usr/local/www/data/phpmysqlconnection.php

Then add the following code into the editor window (don't forget the semi-colons):

<html> <head> <title>PHP_MySQL_Connection</title> </head> <body> <!— start PHP insert and create MySQL connection details as variables —> <?php // database access variables $Server = "localhost"; $Username = "root"; $Pass = "yourpasswordhere"; $DataBaseName = "banking"; // connect PHP to MySQL $Connection = mysql_connect ($Server, $Username, $Pass) or die ("Connection Denied"); // test the connection with a browser if ($Connection) { echo "<h3>Congratulations! You are ready to build dynamic database-driven Web sites</h3>"; } else { echo "<h3>Back to the lab again*****Something went wrong</h3>"; } // closing the connection is considered good form mysql_close ($Connection); // close the php ?> </body> </html>

Test this out:

TYPE lynx

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date