Super Server APACHE+MYSQL+PHP+SSL Complete installation strategy (1)

Source: Internet
Author: User
Tags install php mysql mysql commands openssl php file php and php and mysql php code
Apache|mysql| Server | Our goal is to install a Web server that allows us to host multiple Web sites, some of which are security solutions for E-commerce, and most Web sites are driven by a script that connects a database server and extracts its data.

The tools required for this task are:

apache-a Web server

mod_ssl-a Secure Sockets Layer (SSL) module

openssl-Open Source Code kit (required by mod_ssl)

Rsaref-only to American users

mysql-a database server

php-a scripting language

"All roads lead to Rome" ... So this is just one of the many configurations that can meet our requirements. I chose this configuration because it is the simplest and fastest kind. The reason for choosing Mod_ssl/openssl is because I have its previous experience and is one of the fastest configurations and easiest to install. For easy integration with Apache, I chose PHP and MySQL. Remember, Perl can do anything you want to do, however, PHP is easy and easy for anyone who wants to learn about it.

Hopefully you will succeed in accomplishing the following goals after completing this simple guide.

Install and set up the MySQL database server

o Know how to check the status of the MySQL server

o Know how to use command line client to access MySQL server

o Know how to access your DB server from the Web

Install and set up an Apache Web server with SSL

O Configure a simple virtual Web site

o Know how to stop and start the server

o Know how to do some basic hosting configuration

PHP 4.0 hypertext preprocessor for installing and configuring server-side Scripts

o Know how to write simple PHP code

o Know how to use PHP to connect to a DB

o Create a simple PHP-enabled Web site to communicate with a database

Create some sample certificates for Apache SSL

o know how to generate a CSR file

o Know how to encrypt a key code

o Know how to sign your own certificate

This article will cover a large amount of information. This guide, as an introductory guide, allows you to step into the world of E-commerce, site scripting and Secure Sockets Layer (SSL) to help you build secure Web sites that are driven by dynamic information stored in the database.

This article is by no means a detailed and comprehensive document, and of course there will be some errors (hopefully minimal) and remember this when you read it. However, it will arouse your enthusiasm and run the products mentioned earlier, hoping to give you a better understanding of how these things work. No previous programming knowledge is required, but assume you have a background in computer knowledge. My goal is to write this document so that any novice can understand what I am talking about. If I have reached, then I have done a good deed. If you set up an E-commerce site easily, it's better than I do:-) Give me some explanations.

Assume

This article assumes that you have installed the following software on your system.

Perl (preferably ver 5+)

Gzip or Gunzip

GCC and GNU make

If you do not install these, you will need to take the necessary steps to install them before interpreting any of the procedures in this article.

You also need a basic understanding of UNIX commands, HTML, and SQL. You should have a basic understanding of how to manage your Linux machine. You also need a completely normal Linux machine, and you will install the software on it. Of course you will need the necessary packages listed earlier to compile the source code, and finally, make sure you haven't pre-installed MySQL, Apache, or PHP in the Linux machine.

Working principle

It helps to understand what's going on behind the scenes. Here is an oversimplified working principle, and the following illustration and subsequent explanations are not entirely correct at the moment, but an overview of its main points:

The situation is: we have a Web page that extracts some data from a database. John Doe requests the page from his browser, sends the request to the Web server, and then invokes a PHP script. The PHP script is interpreted by the PHP preprocessor and extracts data from the database, and the results are processed by the remaining PHP scripts and converted into HTML, and the HTML is sent back to the user's browser.

Let's look at it step-by-step:

John Doe clicks a link from his browser, and his browser sends a request to http://www.yourserver.com/test.php.

Apache gets a request for test.php, it knows. The php file should be processed by the PHP preprocessor (mod_php), so it notifies PHP to handle it. It knows this because we specify it in the Apache configuration.

test.php is a PHP script that contains commands. One of these commands is to open a connection to a database and crawl the data. PHP handles the connection to the database and interprets the SQL call to extract the data from DB.

The server server gets the connection request from the PHP interpreter and processes the request. The request may be similar to a simple selection statement, or database table creation, and so on.

The database then echoes the answers and the results to the PHP interpreter.

Apache echoes the result to John Doe's browser as a response to his request. John Doe now sees a Web page that contains some information from a database.

If this is a request to https://www.yoursecureserver.com/test.php, the whole process is similar to the above, except that each request and answer is encrypted and decrypted at both ends, that is, the browser connects Apache, obtains its encryption key code, encrypts the request, and sends it.

The server sees the request, decrypts it, and authenticates it. It processes the file, encrypts it, and sends it. The browser then decrypts it with the server's key code. Remember that since the connection is encrypted, it is used with a different port. Port 80 is used on unsecured connections, and port 443 is used for secure connections.

Again, it's not 100% right, but it's quick enough to give you a very simple overview of what's going on behind the scenes.

Now that we have a very basic understanding of what we are trying to achieve, let's go ahead and install the software.

Get ready

Apache (Web server)-http://www.apache.org

MOD_SSL (Secure Server layer)-http://www.modssl.org

OpenSSL (SSL Toolbox)-http://www.openssl.org

PHP (scripting language)-http://www.php.net

MySQL (SQL database server)-http://www.mysql.com

Download all (tar file) source code to a temporary directory. Make sure you put them in a place with lots of space ... You should download them as root to avoid permissions issues.

Our plan.

Our plan is to first install the MySQL server and make sure it works, then we will install PHP and mod_ssl, and finally we will install the Apache Web server. After we have Apache installed, we can test whether PHP and MOD_SSL support is working.

MySQL source code installation (UNIX)

You have to perform the basic command of installing MySQL source code (since one did not unlock the "tar" file):

By using Su to become the root user.

$su

Go directly to the directory where you have the tar file. (Use a temporary directory.) Use/tmp/download/here)

#cd/tmp/download/

Use the following command to extract the file.

# gunzip-d-C mysql-3.22.xx.tar.gz | Tar xvf-

Changes to the new directory, which is created during extraction.

# CD MYSQL-3.22.XX

Now you can start to "configure" the MySQL server. You can use configure to specify many options, using configure--help to view all of the options. I have chosen--prefix to specify the direct path to the installation location. Configure will check your compiler and some other things. If you have any errors, you can check the Config.cache file to see the error.

# Configure--PREFIX=/USR/LOCAL/MYSQ

After you have completed the configuration, you can execute the following commands to make the real binary code.

# make

Now you are ready to install all binary code. Run the following command to install the binary code in the directory you specified with the Configure--prefix option.

# make Install

After you've installed the binaries, it's time to create a MySQL table to define permissions.

# scripts/mysql_install_db

# Cd/usr/local/mysql/bin

#./safe_mysqld &

#./mysqladmin-u Root Password "New-password"

Note:/usr/local/mysql is the directory where I chose to install the MySQL server. You can choose another place by changing the directory.

You can verify that the server is working by running some simple tests to make sure that MySQL is running. The output should resemble the following: Bindir=/usr/local/mysql/bin. Bindir depends on the directory you select on the prefix above.

# bindir/mysqlshow-p

+---------------+

| Databases |

+---------------+

| MySQL |

+---------------+

Once you have MySQL installed, it will automatically create 2 databases. A MySQL table that controls the user, host, and database permissions in the actual server, and the other is a test database where we can use the test database. However, we would like to give you a quick and simple overview of some command-line options available for MySQL. This will also ensure that root is set to all access to the DB server, that is, the root has permission to create databases, database tables, and so on, so we will create a test2 database, which we'll use for our testing later. Before you enter MySQL through the command line, you will be prompted for the root user's new password. Remember that you have changed it before.

# mysql-u Root-p

mysql> show databases;

+----------------+

| Database |

+----------------+

| MySQL |

| Test |

+----------------+

mysql> CREATE DATABASE test2;

Query OK, 1 row Affected (0.00 sec)

Now select the new database to use and create a new table named Tst_tbl with the following 2 fields. Field 1 is an ID field that allows you to know the ID of the record. Essentially, to simplify this is just a line number. The second field is your Name field, which stores the title information. The format of these fields is that the field 1 (ID) is an integer (int) with a length of 3, and field 2 (name) is a character (char) field of length 50. For searching and indexing data, we specify the ID as the key code.

mysql> use test2;

Database changed

Mysql> CREATE TABLE Books (id int (3) is not NULL

-> auto_increment, name char () NOT NULL,

-> Unique (ID), primary key (ID));

Query OK, 0 rows Affected (0.00 sec)

Now we use the following command to verify that everything is correct.

Mysql> Show Tables

+---------------------+

| Tables in Test2 |

+---------------------+

| Books |

+---------------------+

1 row in Set (0.00 sec)

mysql> describe books;

+-------+-------------+------+------+----------+------------------------+

| Field | Type | Null | Key | Default | Extra |

+-------+-------------+------+------+----------+------------------------+

| ID | Int (3) | | PRI | 0 | auto_increment |

| name | CHAR (50) | | | |

+-------+-------------+------+------+----------+------------------------+

2 rows in Set (0.00 sec)

Note that the describe command basically "describes" the layout of the table. It's pretty good!

OK, let's try some really useful SQL commands, insert and select the data from the database, and now add a few records to the new table. Remember that these are simple book titles, but once you have enough SQL experience, you can create complex databases for some large e-commerce sites. Let's create 2 records of 2 imaginary books. The first record is the name of a book that I wrote one day in the future-"PHP 4 newbies" and the other is a very useful Linux book, "Red Hat Linux 6 Server", by Mohammed J. Kabir.

Mysql> INSERT into books (name) VALUES ("PHP 4 Newbies");

Query OK, 1 row Affected (0.00 sec)

Mysql> INSERT into books (name) VALUES ("Red Hat Linux 6 Server");

Query OK, 1 row Affected (0.00 sec)

Now we can check the new record and issue a "Select All" command

Mysql> SELECT * from books;

+----+----------------------------------+

| ID | name |

+----+----------------------------------+

| 1 | PHP for Newbies |

| 2 | Red Hat Linux 6 Server |

+----+----------------------------------+

2 rows in Set (0.00 sec)

Well, the MySQL server is fully functional. We can continue to join, but it doesn't make sense at this time. Notice how you do not have to specify an ID number when you insert a record into the database, because you created the ID field that enables the Auto_increment option.

Let me show you how to do a quick delete. This just lets you know, remember, you can find all the information you need on MySQL commands and servers on the MySQL website http://www.mysql.com.

Mysql> Delete from the books where id=1;

Query OK, 1 row Affected (0.00 sec)

Mysql> select * from books;

+----+-----------------------------------+

| ID | name |

+----+-----------------------------------+

| 2 | Red Hat Linux 6 Server |

+----+-----------------------------------+

1 row in Set (0.00 sec)

OK, quit MySQL and continue with the installation. It is not too late for you to play MySQL after you have completed all the installation and everything is working properly.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.