Build a Dynamic Web Serving Platform with FreeBSD

Build a Dynamic Web Serving Platform with FreeBSD

ooking for a secure solution for hosting dynamic Web pages but don’t have much money to implement it? Use FreeBSD and its ports collection to install Apache-modSSL, MySQL, and PHP. This open source solution will have you serving dynamic Web pages quickly, reliably, securely, and efficiently?without any out-of-pocket expense. All you need are the following:

  1. Root control of a FreeBSD box
  2. A FreeBSD box connected to the Internet
  3. An installed ports collection
  4. An updated ports collection via CVsup

Although this solution may sound like a lot of work, compiling each application from source is actually painless with the FreeBSD ports system. This tutorial offers a simple paint-by-numbers guide to this server installation, which any developer, from the curious newbie to the seasoned Linux or Windows veteran, can use. As an added bonus, because FreeBSD can run on a 486 PC with just 16MB of RAM, it also enables you to turn an old computer into a PHP testing environment.

Author’s Note: Following the procedure outlined in this article creates a computer containing strong cryptographic software that can have severe legal consequences in certain countries. If you don’t know the legal regulations in your country, find out before you install!

This article requires a running FreeBSD installation. To follow the instructions, you must be logged in as root and be able to navigate the command line. Some familiarity with both Unix and the computer you’re working on is also required. The TYPE instruction means “at the root prompt.” Do not type TYPE. Simply enter the data following the TYPE command ad verbatim on each line at the # root prompt. Press enter following each line of commands.

Connect Your FreeBSD Installation to the Internet
If you are already connected to the Internet skip ahead to the “Install CVsup to Stay Current” step. If you installed FreeBSD via CD-ROM, you need a configured Ethernet card to connect to the Internet. To configure your network connection:

       TYPE /stand/sysinstall

Choose Configure then Networking from the list of options.

This installation requires the ports collection. If you haven’t already, install the ports collection now. (See the FreeBSD handbook for an outline of how to install the ports collection.)

Install CVsup to Stay Current
If you have just installed the ports collection using a CD-ROM, you must upgrade to the latest releases of the ported software you need. If you have just installed FreeBSD and the ports collection via FTP, you are already current and you can skip ahead to the “Install Each Application from Source” section.

Fortunately, FreeBSD makes staying current extremely easy:

    TYPE cd /usr/ports/net/cvsup-without-gui    TYPE make    TYPE make install    TYPE make clean

As root, copy /usr/share/examples/cvsup/ports-supfile to a new location. In this case, copy to /root on your home directory:

    TYPE cp /usr/share/examples/cvsup/ports-supfile /root/ports-supfile

* Notice the space between ports-supfile and /root/ports-supfile.

Edit ports-supfile with your favorite editor:

    TYPE ee /root/ports-supfile

Change the ports-supfile (line 50 or so) to look something like the following:

#**********************************************************************default host=cvsup.ca.FreeBSD.org.*default base=/usr*default prefix=/usr*default release=cvs*default delete use-rel-suffix*default tag=.src-all#**********************************************************************

Pay particular attention to the first and last lines. Choosing a CVsup mirror that is located near you will save a lot of time. At the very least, download one from the country where you live. Click here for a list of mirrors.

After you’ve done this, press Escape and then Return to leave editor. Press Return to save your changes.

Before running CVsup, you have to reboot your system:

    TYPE  shutdown -r now

Once you have once again logged in as root:

Now it’s time to run CVsup:

    TYPE cvsup -g -L 2 /root/ports-supfile

This command upgrades all the skeletons in your ports collection. Depending on your Internet connection speed, the upgrade can take an hour or longer.

Install Apache-modSSL, MySQL, and PHP
Once you get the command prompt back, you can move on to the fun part. Enter the following commands one at a time, waiting for the command prompt between each instance of TYPE.

Install the Perl language (required for MySQL):

    TYPE cd /usr/ports/lang/perl5    TYPE make    TYPE make test    TYPE make install    TYPE make clean    TYPE cd ~    TYPE rehash    TYPE use.perl port

The last three commands tells your FreeBSD machine to use the freshly upgraded Perl language and not the default that ships with your version of FreeBSD. If you ever need to switch back TYPE use.perl system.

Install the MySQL database:

    TYPE cd /usr/ports/databases/mysql40-server    TYPE make    TYPE make install     TYPE make clean

It is a good idea to edit /etc/make.conf to tell various ports which versions of Berkeley DB and MySQL to use:

     TYPE ee /etc/make.conf

Add the following two lines, one on top of the other as shown:

        WITH_BDB_VER=40        WITH_MYSQL_VER=40
Editor’s Note: Be sure to modify the code above, if necessary, to match the version number of MySQL that you are currently using.

Press Escape to exit, and save your changes before you leave the editor.

Install the Apache13x+mod_ssl server:

    TYPE cd /usr/ports/www/apache13-modssl    TYPE make    TYPE make certificate

You’ll see a series of self-explanatory on-screen directions here. Create an [R]SA server key for good performance. Change all of the snake-oil information to your own private information. When you are asked to encrypt this key, choose [y]es, and then:

    TYPE make install    TYPE make clean

Install the PHP language:

    TYPE cd /usr/ports/www/mod_php4    TYPE make

Now you get to choose your installation preferences. Notice that the MySQL dependent choices have been made for you. Certain options require a licensing fee (e.g., PDFlib). If you do not recognize a particular component, do not install it. Certain components create dependencies on other components. To simplify this installation and circumvent errors, stick to a minimal configuration. Include DOMXML and DOMXSLT support. PHP integrates well with XML. For universality amongst databases, choose the UNIXODBC support also. UNIXODBC will allow you to connect PHP with many databases:

    TYPE make install    TYPE make clean 

Congratulations! You have Apache-modSSL, MySQL, and PHP installed on your FreeBSD system. Wasn’t that easy? Still skeptical? Then test it out.

Test Your Installation
To test the installation, you need a Web browser. I like to use LYNX.

Install LYNX-ssl Web Browser:

    TYPE cd /usr/ports/www/lynx-ssl    TYPE make        TYPE make clean

Now, shutdown and reboot your machine to have Apache and MySQL start as daemon processes in the background. If you made a certificate, you will need to enter your local pass- key when prompted:

    TYPE shutdown -r now    TYPE lynx 127.0.0.1

This command tells your Web browser to view the local Apache configuration. And what do you knowit worked! You should see the default congratulatory Apache screen. (Note: The keystroke Q or Control-C gets you out of LYNX.)

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 .php3AddType application/x-httpd-php3-source .php3sAddType application/x-httpd-php .phpAddType 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:

PHP_TESTER

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 127.0.0.1

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):

PHP_MySQL_ConnectionCongratulations! You are ready to build dynamic database-driven Web sites";} else {echo "

Back to the lab again*****Something went wrong

";}// closing the connection is considered good formmysql_close ($Connection);// close the php?>

Test this out:

    TYPE lynx 127.0.0.1/phpmysqlconnection.php

Secure the Pages You Serve
Your last step is to configure Apache-modSSL to serve truly secure pages to the outside world. Note: the traditional secure port is 443. The FAQ pages at the following Web sites provide more information:

  • www.freebsd.org
  • www.apache.org
  • www.openssl.org
  • www.modssl.org
  • www.perl.org
  • www.mysql.org
  • www.php.net
  • Security is a process and not an end. Many of your configuration questions can be answered in the mod_ssl documentation included with the installation of Apache-modSSL. Further reading and support is available from a number of locations, including:

  • www.devshed.com/Server_Side/PHP/DB_Basics
  • www.programmingpub.com/php_forum_php_forums
  • developer.netscape.com/tech/security/ssl/howitworks
  • Contribute to Open Source
    FreeBSD and the other open-source projects used in this article rely on user contributions to evolve. If you find these products useful, financial and volunteer contributions are always welcome. FreeBSD is distributed under the BSD license, leaving you free to alter and distribute the source code so long as the BSD license remains intact. Click here for copyright information about FreeBSD and the GNU public license.

    devx-admin

    devx-admin

    Share the Post:
    Apple Tech

    Apple’s Search Engine Disruptor Brewing?

    As the fourth quarter of 2023 kicks off, the technology sphere is abuzz with assorted news and advancements. Global stocks exhibit mixed results, whereas cryptocurrency

    Revolutionary Job Market

    AI is Reshaping the Tech Job Market

    The tech industry is facing significant layoffs in 2023, with over 224,503 workers in the U.S losing their jobs. However, experts maintain that job security

    Foreign Relations

    US-China Trade War: Who’s Winning?

    The August 2023 visit of Gina Raimondo, the U.S. Secretary of Commerce, to China demonstrated the progress being made in dialogue between the two nations.

    Pandemic Recovery

    Conquering Pandemic Supply Chain Struggles

    The worldwide coronavirus pandemic has underscored supply chain challenges that resulted in billions of dollars in losses for automakers in 2021. Consequently, several firms are

    Game Changer

    How ChatGPT is Changing the Game

    The AI-powered tool ChatGPT has taken the computing world by storm, receiving high praise from experts like Brex design lead, Pietro Schirano. Developed by OpenAI,

    Apple Tech

    Apple’s Search Engine Disruptor Brewing?

    As the fourth quarter of 2023 kicks off, the technology sphere is abuzz with assorted news and advancements. Global stocks exhibit mixed results, whereas cryptocurrency tokens have seen a substantial

    GlobalFoundries Titan

    GlobalFoundries: Semiconductor Industry Titan

    GlobalFoundries, a company that might not be a household name but has managed to make enormous strides in its relatively short 14-year history. As the third-largest semiconductor foundry in the

    Revolutionary Job Market

    AI is Reshaping the Tech Job Market

    The tech industry is facing significant layoffs in 2023, with over 224,503 workers in the U.S losing their jobs. However, experts maintain that job security in the sector remains strong.

    Foreign Relations

    US-China Trade War: Who’s Winning?

    The August 2023 visit of Gina Raimondo, the U.S. Secretary of Commerce, to China demonstrated the progress being made in dialogue between the two nations. However, the United States’ stance

    Pandemic Recovery

    Conquering Pandemic Supply Chain Struggles

    The worldwide coronavirus pandemic has underscored supply chain challenges that resulted in billions of dollars in losses for automakers in 2021. Consequently, several firms are now contemplating constructing domestic manufacturing

    Game Changer

    How ChatGPT is Changing the Game

    The AI-powered tool ChatGPT has taken the computing world by storm, receiving high praise from experts like Brex design lead, Pietro Schirano. Developed by OpenAI, ChatGPT is known for its

    Future of Cybersecurity

    Cybersecurity Battles: Lapsus$ Era Unfolds

    In 2023, the cybersecurity field faces significant challenges due to the continuous transformation of threats and the increasing abilities of hackers. A prime example of this is the group of

    Apple's AI Future

    Inside Apple’s AI Expansion Plans

    Rather than following the widespread pattern of job cuts in the tech sector, Apple’s CEO Tim Cook disclosed plans to increase the company’s UK workforce. The main area of focus

    AI Finance

    AI Stocks to Watch

    As investor interest in artificial intelligence (AI) grows, many companies are highlighting their AI product plans. However, discovering AI stocks that already generate revenue from generative AI, such as OpenAI,

    Web App Security

    Web Application Supply Chain Security

    Today’s web applications depend on a wide array of third-party components and open-source tools to function effectively. This reliance on external resources poses significant security risks, as malicious actors can

    Thrilling Battle

    Thrilling Battle: Germany Versus Huawei

    The German interior ministry has put forward suggestions that would oblige telecommunications operators to decrease their reliance on equipment manufactured by Chinese firms Huawei and ZTE. This development comes after

    iPhone 15 Unveiling

    The iPhone 15’s Secrets and Surprises

    As we dive into the most frequently asked questions and intriguing features, let us reiterate that the iPhone 15 brings substantial advancements in technology and design compared to its predecessors.

    Chip Overcoming

    iPhone 15 Pro Max: Overcoming Chip Setbacks

    Apple recently faced a significant challenge in the development of a key component for its latest iPhone series, the iPhone 15 Pro Max, which was unveiled just a week ago.

    Performance Camera

    iPhone 15: Performance, Camera, Battery

    Apple’s highly anticipated iPhone 15 has finally hit the market, sending ripples of excitement across the tech industry. For those considering upgrading to this new model, three essential features come

    Battery Breakthrough

    Electric Vehicle Battery Breakthrough

    The prices of lithium-ion batteries have seen a considerable reduction, with the cost per kilowatt-hour dipping under $100 for the first occasion in two years, as reported by energy analytics

    Economy Act Soars

    Virginia’s Clean Economy Act Soars Ahead

    Virginia has made significant strides towards achieving its short-term carbon-free objectives as outlined in the Clean Economy Act of 2020. Currently, about 44,000 megawatts (MW) of wind, solar, and energy

    Renewable Storage Innovation

    Innovative Energy Storage Solutions

    The Department of Energy recently revealed a significant investment of $325 million in advanced battery technologies to store excess renewable energy produced by solar and wind sources. This funding will

    Renesas Tech Revolution

    Revolutionizing India’s Tech Sector with Renesas

    Tushar Sharma, a semiconductor engineer at Renesas Electronics, met with Indian Prime Minister Narendra Modi to discuss the company’s support for India’s “Make in India” initiative. This initiative focuses on

    Development Project

    Thrilling East Windsor Mixed-Use Development

    Real estate developer James Cormier, in collaboration with a partnership, has purchased 137 acres of land in Connecticut for $1.15 million with the intention of constructing residential and commercial buildings.

    USA Companies

    Top Software Development Companies in USA

    Navigating the tech landscape to find the right partner is crucial yet challenging. This article offers a comparative glimpse into the top software development companies in the USA. Through a

    Software Development

    Top Software Development Companies

    Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

    India Web Development

    Top Web Development Companies in India

    In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

    USA Web Development

    Top Web Development Companies in USA

    Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

    Clean Energy Adoption

    Inside Michigan’s Clean Energy Revolution

    Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

    Chips Act Revolution

    European Chips Act: What is it?

    In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its