Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install apache+mysql+php+ssl server

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How to install apache+mysql+php+ssl server, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Install a web server that allows us to host multiple sites, some of which are security solutions for e-commerce, while most sites are driven by scripts that connect to a database server and extract its data.

How to install apache+mysql+php+ssl server

The tools required for this task are:

Apache- a web server

Mod_SSL- a secure socket layer (SSL) module

OpenSSL- Open Source Toolkit (required by mod_ssl)

RSARef- is for US users only

MySQL- a database server

PHP-, a scripting language

"all roads lead to Rome". So this is just one of many configurations that can meet our requirements. I chose this configuration because it is the easiest and fastest one. The reason for choosing Mod_SSL/OpenSSL is because I have its previous experience, which is the fastest configuration and the easiest to install. To easily integrate with Apache, I chose PHP and MySQL. Remember, Perl can do any job you want, however, PHP is simple and easy for any programmer who wants to learn it.

I hope you will successfully complete the following goals at the end of 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 access the MySQL server using a command line client

O know how to access your DB server from 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 do some basic hosting configuration

Install and configure the PHP 4.0 hypertext preprocessor for server-side scripts

O know how to write simple php code

O know how to connect to a DB using php

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

Create some sample certificates for ApacheSSL

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 great deal of information. As an introductory guide, this guide takes you into the world of e-commerce, website scripting, and secure Sockets layer (SSL) to help you build secure websites driven by dynamic information stored in a database.

This article is by no means a detailed and comprehensive document, and it will certainly have some errors (hopefully at a minimum), which you should keep in mind as you read it. However, it will arouse your enthusiasm and run the products mentioned above, hoping to give you a better understanding of how these things work. Previous programming knowledge is not required, but it is assumed that you have some computer knowledge. My goal is to write this document so that any novice can understand what I'm talking about. If I reach it, then I have done a good thing. If you easily set up an e-commerce site, it's better than me: -) give me some explanations.

Hypothesis

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

Perl (preferably ver5+)

Gzip or gunzip

Gcc and GNUmake

If you do not install these, you will need to take the necessary steps to install them before explaining 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 software on it. Of course, you will need the necessary packages listed above to compile the source code, and finally, make sure that you have not pre-installed MySQL, Apache, or PHP on your Linux machine.

working principle

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

The situation is: we have a web page that fetches some data from a database. JohnDoe requests the page from his browser, the request is sent to the web server, and a PHP script is invoked. The PHP script is interpreted by the PHP preprocessor and fetches the data from the database, then the result is processed by the remaining PHP script and converted into HTML, and the finished HTML is sent back to the user's browser.

Let's look at it step by step:

JohnDoe clicks a link from his browser; his browser sends a request for it.

Apache gets a request for test.php and knows that .php files should be processed by PHP preprocessor (mod_php), so it tells PHP to process it. It knows this because we specify it in the configuration of Apache.

Test.php is a PHP script that contains commands. One of these commands is to open a connection to a database and grab the data. PHP handles connections to the database and interprets SQL calls to extract 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 select statement, or database table creation, and so on.

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

Apache sends the result back to JohnDoe's browser as a response to his request. JohnDoe now sees a web page that contains some information from a database.

If this is a request for a pair, the whole process is similar to the above, except that each request and reply is encrypted and decrypted at both ends, that is, the browser connects to Apache, gets its encryption key, 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 on a different port. Port 80 is used for non-secure connections, while port 443 is used for secure connections.

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

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

Prepare for

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

Mod_SSL (Security 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 the source code (tar file) 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 make it work, then we will install PHP and Mod_SSL, and finally we will install the Apache web server. After we have installed Apache, we can test whether the PHP and Mod_SSL support is working.

MySQL source code installation (UNIX)

The basic command you must use to install the MySQL source code distribution is (from a file that did not unlock the "tar" file):

Become a root user by using su.

$su

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

# cd/tmp/download/

Use the following command to extract the file.

# gunzip-d-cmysql-3.22.xx.tar.gz | tarxvf-

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

# cdmysql-3.22.xx

Now you can start "configuring" the MySQL server. You can use configure to specify a lot of options, and use configure--help to see all the options. I have chosen-- prefix specifies the direct path to the install site. 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 have completed the configuration, you can execute the following command make the real binary code.

# make

Now you are ready to install all the binaries. Run the following command to install the binaries in the directory you specified with the configure--prefix option.

# makeinstall

After you have installed the binaries, it is time to create the mysql table that defines the permissions.

# scripts/mysql_install_db

# cd/usr/local/mysql/bin

#. / safe_mysqld&

#. / mysqladmin-urootpassword "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 be similar to that shown below: BINDIR=/usr/local/mysql/bin. BINDIR depends on the directory you choose with the prefix above.

# BINDIR/mysqlshow-p

+-+

| | Databases |

+-+

| | mysql |

+-+

Once you have installed MySQL, it will automatically create 2 databases. A mysql table that controls user, host, and database permissions on the actual server; the other is a test database, which we can use with the test database. However, we want to give you a quick and easy overview of some of the command line options available for MySQL. This will also ensure that root is set to have full access to the DB server, that is, root has permission to create databases, database tables, etc., so we will create an test2 database that we will use for our tests later. Before you enter MySQL from the command line, you will be prompted for the new password of the root user. Remember, you changed it before.

# mysql-uroot-p

Mysql > showdatabases

+-+

| | Database |

+-+

| | mysql |

| | test |

+-+

Mysql > createdatabasetest2

QueryOK,1rowaffected (0.00sec)

How to install apache+mysql+php+ssl server

Now select the new database to use and create a new table called tst_tbl with the following two fields. Field 1 is an id field that allows you to know the id of the record. In essence, in order 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: field 1 (id) is an integer of length 3 (int), and field 2 (name) is a char field of length 50. For searching and indexing data, we specify id as the key code.

Mysql > usetest2

Databasechanged

Mysql > CREATETABLEbooks (idint (3) notnull

-> auto_increment,namechar (50) notnull

-> unique (id), primarykey (id)

QueryOK,0rowsaffected (0.00sec)

Now let's verify that everything is correct with the following command.

Mysql > showtables

+-+

| | Tablesintest2 |

+-+

| | books |

+-+

1rowinset (0.00sec)

Mysql > describebooks

+-+

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

+-+

| | id | int (3) | | PRI | 0 | auto_increment |

| | name | char (50) |

+-+

2rowsinset (0.00sec)

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

Well, it's time to try some really useful SQL commands, insert and select data from the database, and now add several records to the new table. Keep in mind that these are simple title records, but once you have gained enough experience with SQL, you can create really complex databases for some large e-commerce sites. Let's create 2 records for 2 hypothetical books. The first record is the name of a book I will write one day-PHP4Newbies, and the other is a very useful Linux book, RedHatLinux6Server, written by MohammedJ.Kabir.

Mysql > INSERTINTObooks (name) values ("PHP4Newbies")

QueryOK,1rowaffected (0.00sec)

Mysql > INSERTINTObooks (name) values ("RedHatLinux6Server")

QueryOK,1rowaffected (0.00sec)

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

Mysql > SELECT*frombooks

+-+-

| | id | name |

+-+-

| | 1 | PHPforNewbies |

| | 2 | RedHatLinux6Server |

+-+-

2rowsinset (0.00sec)

Well, the MySQL server is fully functional. We can continue to join, but it doesn't make any sense at this time. Notice how you don't have to specify an id number when you insert a record into the database because you created an id field with the auto_increment option enabled.

Let me show you how to do a quick delete. This is just to let you know, remember, you can find all the information you need about mysql commands and servers on MySQL's website.

Mysql > deletefrombookswhereid=1

QueryOK,1rowaffected (0.00sec)

Mysql > select*frombooks

+-+-

| | id | name |

+-+-

| | 2 | RedHatLinux6Server |

+-+-

1rowinset (0.00sec)

All right, exit MySQL and continue with the installation. It is not too late to play MySQL after you have completed all the installations and everything is working properly.

PHP installation (UNIX)

Install PHP language now. You have downloaded the latest beta version, but you may have to download a non-beta version. Remember that the beta version requires GNUmake.

You still assume it's root. If not, su goes back to root.

PHP requires that you pre-configure Apache so that it knows where what you need is. You will come back here later when you install the Apache server. Change to the directory where you have the source code.

# cd/tmp/DOWNLOAD

# gunzip-capache_1.3.x.tar.gz | tarxf-

# cdapache_1.3.x

#. / configure

# cd..

OK, now you can start the installation of PHP. Extract the source code file and enter its directory. If you download version 3, there is a change in numbers and commands, not a big change.

# gunzip-cphp-4.0.x.tar.gz | tarxf-

# cdphp-4.0.x

If you are compiling code, configure will always be your friend. : -) therefore, configure has many options. Use configure--help to determine what you want to add. I just need MySQL and LDAP, and of course Apache.

#. / configure--with-mysql=/usr/local/mysql

-- with-xml

-- with-apache=../apache_1.3.x

-- enable-track-vars

-- with-ldap

Make and install binaries.

# make

# makeinstall

Copy the ini file to the lib directory.

# cpphp.ini-dist/usr/local/lib/php.ini

You can edit the PHP file to set the PHP options, for example, you can add the max_execution_time of php by inserting the following lines in your php.ini file.

Max_execution_time=60

Note: php3 users will use php3.ini, while php4 users will use php.ini files.

Apache and Mod_SSL

It's time to configure and install mod_ssl and Apache. For this, you will need to have a rsaref-2.0 file. Search for "rsaref20.tar.Z" on. If you don't like Lycos, you can choose other search engines to search for files. Of course, only you need this document in the United States. Anyway, you can download it from somewhere else, first of all, look for "rsaref20.tar.Z". There are a lot of them.)

Create the rasref directory where you will extract files. Be careful. This assumes that you have downloaded a temporary directory and you are in this directory.

# mkdirrsaref-2.0

# cdrsaref-2.0

# gzip-d-c../rsaref20.tar.Z | tarxvf-

Now configure and construct the OpenSSL library.

# cdrsaref-2.0

# cp-rpinstall/unixlocal

# cdlocal

# make

# mvrsaref.alibrsaref.a

# cd../..

Install OpenSSL. Remember, you will use it to create temporary certificates and CSR files. The-- prefix option specifies the main installation directory.

# cdopenssl-0.9.x

#. / config-prefix=/usr/local/ssl

-L`pwd` /.. / rsaref-2.0/local/rsaref-fPIC

Now make, test, and install it.

# make

# maketest

# makeinstall

# cd..

We will configure the MOD_SSL module and then specify it as a loadable module with the Apache configuration.

# cdmod_ssl-2.5.x-1.3.x

#. / configure

-- with-apache=../apache_1.3.x

# cd..

Now we can add more Apache modules to the Apache source tree. The optional-- enable-shared=ssl option makes the mod_ssl construct a DSO "libssl.so". For more information about DSO support in Apache, read the INSTALL and htdocs/manual/dso.html documentation in the Apache source tree. I strongly recommend that ISP and software wrapper maintainers use DSO tools to make the most flexible use of mod_ssl, but note that DSO is not supported by Apache on all platforms.

# cdapache_1.3.x

# SSL_BASE=../openssl-0.9.x

RSA_BASE=../rsaref-2.0/local

. / configure--enable-module=ssl

-- activate-module=src/modules/php4/libphp4.a

-- enable-module=php4--prefix=/usr/local/apache

-- enable-shared=ssl

[... You can add more options.]

Generate Apache, then generate certificate, and install.

# make

If you have done it correctly, you will get information similar to the following:

+-- +

| | BeforeyouinstallthepackageyounowshouldpreparetheSSL |

| | certificatesystembyrunningthe "makecertificate" command. |

| | Fordifferentsituationsthefollowingvariantsareprovided: |

| | |

| |% makecertificateTYPE=dummy (dummyself-signedSnakeOilcert) |

| |% makecertificateTYPE=test (testcertsignedbySnakeOilCA) |

| |% makecertificateTYPE=custom (customcertsignedbyownCA) |

| |% makecertificateTYPE=existing (existingcert) |

| | CRT=/path/to/ your.crt [key = / path/to/your.key] |

| | |

| | UseTYPE=dummywhenyou'reavendorpackagemaintainer, |

| | theTYPE=testwhenyou'reanadminbutwanttodotestsonly, |

| | theTYPE=customwhenyou'reanadminwillingtorunarealserver |

| | andTYPE=existingwhenyou'reanadminwhoupgradesaserver. |

| (ThedefaultisTYPE=test) |

| | |

| | AdditionallyaddALGO=RSA (default) orALGO=DSAtoselect |

| | thesignaturealgorithmusedforthegeneratedcertificate. |

| | |

| | Use "makecertificateVIEW=1" todisplaythegenerateddata. |

| | www.knowsky.com |

| | ThanksforusingApache&mod_ssl.RalfS.Engelschall |

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report