Full installation of super server apache + mysql + php + ssl

Source: Internet
Author: User
Tags mysql commands website server
Our goal is to install a web server that allows us to host multiple websites, some of which are security solutions for e-commerce, most websites are script-driven by connecting to a database server and extracting its data. The tools required for this task are: Apache-a website server Mod_SSL-a Secure Socket Layer (SSL) module Apachemysql installation

Our goal is to install a web server that allows us to host multiple websites, some of which are security solutions for e-commerce, most websites are script-driven by connecting to a database server and extracting its data.

The tools required for this task are:

Apache-a website server

Mod_SSL-a Secure Socket Layer (SSL) module

OpenSSL-Open Source Toolkit (required for mod_ssl)

RSARef-only for American users

MySQL-a database server

PHP-a scripting language

"Rome is a great path "...... Therefore, this is only one of the many configurations that meet our requirements. I chose this configuration because it is the simplest and fastest. The reason for choosing Mod_SSL/OpenSSL is that I have previous experience and is the fastest configuration and the easiest installation. To facilitate integration with Apache, I chose PHP and MySQL. Remember, Perl can do whatever you want, but PHP is simple and easy for any programmer who wants to learn it.

We hope that you will successfully achieve the following goals after finishing this simple guide.

Install and set the MySQL database server

O know how to check the status of the MySQL server

O know how to use the command line client program to access the MySQL server

O know how to access your DB server from the web

Install and set up an Apache website server with SSL

O configure a simple virtual website

O know how to stop and start the server

O know how to make some basic host hosting configurations

Install and configure the PHP 4.0 hypertext preprocessor for server scripts

O know how to write simple php code

O know how to connect to a database using php

O create a simple website with PHP enabled to communicate with a database

Create 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. As an entry-level guide, this guide introduces you to the world of e-commerce, website scripting, and Secure Sockets Layer (SSL, the purpose is to help you build a secure website driven by dynamic information stored in the database.

This document is by no means a detailed and comprehensive document. of course, it will have some errors (hopefully the least). remember this when you read it. However, it will arouse your enthusiasm and run the products mentioned above, hoping that you can better understand how these things work. You do not need previous programming knowledge, but assume that you have a background in computer knowledge. My goal is to write this document so that any newbie can understand what I'm talking about. If I do, I do a good job. If you have easily established an e-commerce site, it is better than me:-) give me some explanations.

Hypothesis

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

Perl (preferably ver 5 +)

Gzip or gunzip

Gcc and GNU make

If you have not installed these, you will need to take the necessary steps to install them before explaining any process 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 machines. You also need a completely normal Linux machine. you will install software on it. Of course, you will need to list the necessary software packages to compile the source code. Finally, ensure that you have not installed MySQL, Apache, or PHP on the Linux machine.

Working Principle

Understanding what happened behind the scenes is helpful. Here is an overly simplified working principle, and the subsequent explanations are not completely correct at the moment, just an overview of its key points:

Situation: we have a Web page that extracts some data from a database. John Doe requests this page from his browser, the request is sent to the web server, and then calls a PHP script. The PHP script is interpreted by the PHP preprocessor and the data is retrieved from the database. The result is processed and converted into HTML by the remaining PHP script, and the HTML is sent back to the user's browser.

Let's take a step-by-step look:

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

Apache gets a request for test. php. it knows that the. PHP file should be processed by the PHP pre-processor (mod_php), so it notifies php to process it. It knows this because it is specified in Apache configuration.

Test. php is a PHP script containing commands. One of these commands is to open a connection to a database and capture data. PHP processes the connection to the database and explains how SQL calls extract data from the database.

The server receives a connection request from the PHP interpreter and processes the request. A request may be similar to a simple selection statement or database table creation.

The database then sends the response and result back to the PHP interpreter.

Apache returns the result to John Doe's browser as a response to his request. John Doe now sees a webpage containing some information from a database.

If this is.

The server decrypts the request and authenticates it. It processes files, encrypts and sends them. Then the browser decrypts it with the server's key code. Remember that since the connection is encrypted, different ports are used. Port 80 is used for non-secure connections, while port 443 is used for secure connections.

Again, it is not 100% correct, but it is fast enough to let you know a very simple overview of what happened behind the scenes.

Since we have a basic understanding of what we are trying to achieve, let's continue to install the software.

Preparation

Apache-http://www.apache.org

Mod_SSL-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 the source code of all (tar files) to a temporary directory. Make sure you put them in a place with a lot of space ...... You should download them as root to avoid permission issues.

Our plan

Our plan is to first install the MySQL server and ensure it works, then we will install PHP and Mod_SSL, and finally we will install the Apache website server. After Apache is installed, we can test whether PHP and Mod_SSL support works.

MySQL source code installation (UNIX)

The basic command you must use to install and install MySQL source code distribution is (from the "tar" file ):

Use su to become the root user.

$ Su

Directly go 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 files.

# Gunzip-d-c mysql-3.22.xx.tar.gz | tar xvf-

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

# Cd mysql-3.22.xx

Now you can start "configuring" the MySQL server. You can use configure to specify multiple options and use configure -- help to view all options. I have selected -- 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 for errors.

# Configure -- prefix =/usr/local/mysq

After you complete the configuration, you can execute the following command to make the real binary code.

# Make

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

# Make install

After you have installed the binary code, it is time to create a mysql table for permission definition.

# 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 select another place by changing the directory.

You can verify that the server is working by running some simple tests to ensure that MySQL is running. The output should be similar to the following: BINDIR =/usr/local/mysql/bin. BINDIR depends on the directory you selected with the prefix above.

# BINDIR/mysqlshow-p

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

| Databases |

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

| Mysql |

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

Once you have installed MySQL, it will automatically create two databases. A mysql table that controls user, host, and Database permissions on the actual server; a test database that we can use. However, we want to give you a quick and simple overview of some command line options available for MySQL. This will also ensure that the root user has all the access permissions on the DB server, that is, the root user has permission to create databases, database tables, and so on. Therefore, we will create a test2 database, we will use it for our testing later. Before you enter MySQL through the command line, you will be prompted with the new password of the root user. Remember that you 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)

Select a new database and create a new table named tst_tbl. the following two fields are available. Field 1 is an id field that allows you to know the record id. In essence, to simplify this is just a row number. The second field is your name field, which stores the title information. The format of these fields is: Field 1 (id) is an integer (int) with a length of 3, and field 2 (name) is a 50-character (char) field. For search and index data, we specify the id as the key code.

Mysql> use test2;

Database changed

Mysql> create table books (id int (3) not null

-> Auto_increment, name char (50) 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 table layout. Pretty good!

Well, try some useful SQL commands, insert and select data from the database, and add several records to the new table. Remember that these are simple name records, but once you have gained enough SQL experience, you can create complex databases for some large e-commerce sites. Let's create two records for two hypothetical books. The first record is the name of a book I wrote one day-"PHP 4 Newbies", and the other is a very useful Linux book, "Red Hat Linux 6 Server ", by hammed 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 new records 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)

Good. The MySQL server is fully functional. We can continue to join, but it does not make sense at this time. Note that when you insert a record to the database, you do not need to specify the id number because you have created the id field that enables the auto_increment option.

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

Mysql> delete from 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)

Now, exit MySQL and continue the installation. It is not too late for you to play with MySQL after all the installation is complete and everything works properly.

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.