How to install MySQL + Apache + PHP on FreeBSD

Source: Internet
Author: User

 How to install MySQL + Apache + PHP on FreeBSD

Author: heiyeluren
QQ group: 5415735 (Linux/BSD installation and maintenance group)
Date: 2004/8/18
-- Special thanks to QQ Group's friend Nan. This article is only available under his patient guidance --

It may be a little difficult to install MySQL on Unix/Linux. the operating system I use is freebsd5.2.1. If other operating systems may have different installation methods, handle them as appropriate.
I won't talk about installing FreeBSD. I just need to customize it a little. I won't talk about the process. The FreeBSD version I use is 5.2.1 and should be a new version, I don't know.

1. Install MySQL

MySQL I am using is 4.0.20, source code version, you can also use RPM package or binary version, the installation method may be different, please refer to other articles.
First download the source code version of mysql2.0.20, address: http://dev.mysql.com/downloads/mysql/4.0.html
Put it down to the/usr/local/src directory, if there is no such directory, create a. Downloaded package named mysql-4.0.20.tar.gz, and then decompress it:

# Tar-zxvf mysql-4.0.20.tar.gz

Decompress the package and generate the mysql-4.0.20 directory. we enter this directory:

# Cd mysql-4.0.20

After entering MySQL, we will start to configure mysql. During the configuration process, we will set an installation directory for MySQL. We will set it under/usr/local/MySQL, it is easier to manage files in one place. If you want more configuration information, use. /configure -- help:

#./Configure -- prefix =/usr/local/MySQL

Wait a few seconds and then compile the source code after the configuration is complete:

# Make

This compilation process is long. If the machine is slow, it may take nearly 20 sub-categories (PS: My machine is a very common machine, and all of them use around 15 or 6 sub-categories ).
Install the SDK after compilation:

# Make install

Wait a few seconds to complete the installation. the most important part is as follows: why is the old installation not successful? (PS: At least I have installed it n times, N> 10, huh). Here is the key to the problem, access to MySQL requires a special user and corresponding access permissions. Here we set root and MySQL to have access permissions.
We first set up a MySQL and MySQL user to access MYSQL:

# PW groupadd MySQL # create a MySQL Group
# PW useradd mysql-G MySQL # create a MySQL user and add it to the MySQL group. It is best to use chpass again to remove the MySQL user's login shell, such as/sbin/nologin, to prevent authorized users from accessing the service in the future.

After the user is created, initialize the table (Note: You must perform this step before proceeding to the following steps)

#./Scripts/mysql_install_db -- user = MySQL # The first trial table is required to be accessed by mysql users.

After the table is initialized, set the access permissions for MySQL and root users. We will first install the MySQL directory:

# Cd/usr/local/MySQL

Then set permissions

# Chown-r root. # Set root to access/usr/local/MySQL
# Chown-r MySQL var # Set mysql users to access/usr/local/MySQL/var, which stores MySQL database files.
# Chown-r MySQL var/. # Set mysql users to access all files under/usr/local/MySQL/var
# Chown-r MySQL var/MySQL/. # Set mysql users to access all files in/usr/local/MySQL/var/MySQL
# Chgrp-r mysql. # Set the MySQL group to access/usr/local/MySQL

// Add, because the above permission settings are a bit problematic, so refer to other materials and set as follows:

Chown-r root/usr/local/MySQL
Chgrp-r MySQL/usr/local/MySQL
Chown-r root/usr/local/MySQL/bin
Chgrp-r MySQL/usr/local/MySQL/bin
Chown-r root/usr/local/MySQL/var
Chgrp-r MySQL/usr/local/MySQL/var
Chmod 777/usr/local/MySQL/var
Chown-r root/usr/local/MySQL/var/MySQL
Chgrp-r MySQL/usr/local/MySQL/var/MySQL
Chmod 777/usr/local/MySQL/var/MySQL
Chown-r root/usr/local/MySQL/var/MySQL /*
Chgrp-r MySQL/usr/local/MySQL/var/MySQL /*
Chmod 777/usr/local/MySQL/var/MySQL /*
Chmod 777/usr/local/MySQL/lib/MySQL/libmysqlclient.

After the configuration is complete, it is basically installed. Okay, let's run our MYSQL:

#/Usr/local/MySQL/bin/mysqld_safe -- user = MySQL &

If there is no problem, a prompt like this should appear:

[1] 42264
# Starting mysqld daemon with databases from/usr/local/MySQL/var

This proves that the installation is successful. if:

[1] 42264
# Starting mysqld daemon with databases from/usr/local/MySQL/var
040818 10:53:45 mysqld ended

It turns out that your MySQL is not running. Check the Error Log:/usr/local/MySQL/var /*. err then determine whether the installation is successful. If not, check whether the above steps are correct.
After the installation is complete, you can connect to MySQL through/usr/local/MySQL/bin/MySQL for management. If you have installed Apache and can parse PHP, you can also use phpMyAdmin to manage your MySQL. Remember to use MySQL or mysqladmin to change the root password after installation. We will not talk about it here. Please refer to related articles.

To control MySQL, use/usr/local/MySQL/libexec/mysqld to control the start or stop MYSQL:

#/Usr/local/MySQL/libexec/mysqld start # Start MySQL
#/Usr/local/MySQL/libexec/mysqld stop # Stop MySQL
#/Usr/local/MySQL/libexec/mysqld restart # restart MySQL

To run MySQL after each system restart, you can write a script to the/usr/local/etc/rc. d directory to run mysql. We will write a script mysql_start.sh.

#! /Bin/sh
/Usr/local/MySQL/bin/mysqld_safe &

Save it to the/usr/local/etc/rc. d directory, and MySQL can be started after reboot.

 

Ii. install Apache

Install Apache to be simple, here I install Apache version is httpd-2.0.50, go download package: http://httpd.apache.org/download.cgi.
The downloaded package is called httpd-2.0.50.tar.gz which we put in the/usr/local/src directory.
First enter the Directory and decompress it:

# Cd/usr/local/src
# Tar-zxvf httpd-2.0.50.tar.gz

Then we will get the httpd-2.0.50 directory, we go to the directory

# Cd httpd-2.0.50

First, configure:

#./Configure/
? -- Prefix =/usr/local/Apache/# The directory where Apache is to be installed. Here we install Apache under/usr/local/Apache.
? -- Enable-shared = max/
? -- Enable-module = rewrite/
? -- Enable-module = so

Run the preceding command. If no error message is displayed, it indicates that the configuration is successful, and then compile:

# Make

The compilation is completed in one or two minutes and then installed:

# Make install

After the installation is complete, Apache is stored in the/usr/local/Apache directory. Bin is the directory of the execution file, conf is the directory of the configuration file, and htdocs is the home directory of the web page, logs is the log directory.
Apache uses bin/apachectl or bin/httpd to control start or stop.

#/Usr/local/Apache/bin/httpd-K start # start Apache
#/Usr/local/Apache/bin/httpd-K stop # Stop Apache
#/Usr/local/Apache/bin/httpd-K restart # restart Apache

Then, you can use http: // localhost to test whether Apache is successfully installed. If an Apache page appears, the installation is successful. Otherwise, check the preceding steps.

 

3. install PHP

The PHP version we use is 4.3.8, first download: http://www.php.net/downloads.php, the package back is called php-4.3.8.tar.gz, put in the/usr/local/src directory.
First enter the Directory and decompress it:

# Cd/usr/local/src
# Tar-zxvf php-4.3.8.tar.gz

Decompress the package and enter the directory:

# Cd php-4.3.8

Configuration, this step is critical and must be set, especially considering what you want to support, such as the GD library, XML, MySQL, etc. If you want to know the detailed configuration, execute. /configure -- help to get:

#./Configure/
? -- With-apxs2 =/usr/local/Apache/bin/apxs/
? -- Disable-Debug/# disable PHP internal debugging
? -- Enable-safe-mode/# enable the PHP security mode
? -- Enable-trans-SID/
? -- With-XML/# supports XML
? -- With-MySQL/# support for MySQL
? -- Enable-short-tags/# supports PHP short tag
? -- With-GD/# supports the GD library
? -- With-zlib/# supports zlib
? -- With-JPEG/
? -- With-PNG/
? -- Enable-memory-limit/
? -- Disable-POSIX/
? -- With-config-file-Path =/usr/local/lib

If the above configuration is correct, the words "Thank you for using PHP" should be displayed at last, which proves that the configuration is successful. If the above configuration options are not supported, an error will be prompted.
For example, if you have not installed MySQL, -- With-mysql cannot be used, so be sure to check whether the corresponding option system is supported. If an error occurs, install the corresponding program first, or remove related options.
Compile after Configuration:

# Make

After compilation is successful, the words "build complete." appears, so you can install it:

# Make install

After the installation is complete, copy/usr/local/src/php-4.3.8/PHP. ini-Dist to/usr/local/lib/and rename it PHP. ini

# Cp/usr/local/src/php-4.3.8/PHP. ini-Dist/usr/local/lib/PHP. ini

Basically, PHP is successfully installed here. If an error occurs in the middle, no errors will occur except when no correct option is selected during configuration.

 

4. Integrate Apache + PHP

To enable Apache to parse PHP directly, we need to make some configuration.
First, go to the Apache configuration file directory:

# Cd/usr/local/Apache/Conf

Then use VI to open the configuration file httpd. conf:

# Vi httpd. conf

In the httpd. conf file, add

Addtype application/X-httpd-PHP. php
Addtype application/X-httpd-PHP-source. PHPs

Add the preceding two statements after other addtype statements.

Make sure that the file contains the following sentence. If not, add it after all loadmodules.

Loadmodule php4_module modules/libphp4.so

Okay, use ": WQ" in VI to save the httpd. conf file and exit VI. Start Apache server:

#/Usr/local/Apache/bin/httpd start

Now Apache can run php. Write a file and test it. In the/usr/local/Apache/htdocs directory, create a new phpinfo. php file,
There is only one line of code in the file:

<? Phpinfo ();?>

Save the file and enter http: // localhost/phpinfo. php in your browser. You should see the PHP system information.
If an error occurs, for example, if you are prompted to recover phpinfo. php, then Apache cannot parse the PHP file. Check whether the above operations are correct.

Well, basically, after MySQL + Apache + PHP is installed, it can be used as a Web server, for example, uploading a forum,
You can also send phpMyAdmin to manage your MySQL. The latest version is phpmyadmin2.6-beta.

Writetime

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.