Configuration process of PHP + MYSQL + APACHE in Linux (abstract)

Source: Internet
Author: User
Tags localhost mysql mysql commands
Linux PHP + MYSQL + APACHE configuration process (abstract) I. install MYSQL mysql-standard-5.0.18-linux-i686.tar.gz
I downloaded all of them to the/usr/local/software Directory.
Go to the installation package directory: cd/usr/local/software
1. [root @ localhost software] # chmod 755 mysql-standard-5.0.18-linux-i686.tar.gz
2, [root @ localhost software] # tar xfz mysql-standard-5.0.18-linux-i686.tar.gz
Decompress the package and generate the mysql-standard-5.0.18-linux-i686 Directory. we enter this directory:
3. [root @ localhost software] # cd mysql-standard-5.0.18-linux-i686
After entering mysql, we will start to configure mysql. during the configuration process, we will set
In the installation directory, we set it to/usr/local/mysql to make it easier to manage files in one place. if you want more configuration information, use it. /configure -- help:
Here, I want to emphasize that MYSQL's default encoding should be selected during compilation, because GBK encoding is not supported in JSP if it is not selected to be installed by default.
So I compile it like this
Access to mysql requires a special user and corresponding access permissions. Here we set root and mysql to have access permissions.
7. create a mysql and mysql user to access mysql:
[Root @ localhost mysql-standard-5.0.18-linux-i686] # groupadd mysql # Create a mysql Group
8. [root @ localhost mysql-standard-5.0.18-linux-i686] # useradd mysql-g mysql # Create a mysql User and add it to the mysql Group
9. initialize the table after the user is created (note: you must perform this step before proceeding to the following steps)
[Root @ localhost mysql-standard-5.0.18-linux-i686] #./scripts/mysql_install_db -- user = mysql
# Initialize the table and set the access permission for the mysql and root users after accessing the initialization table ,;
10, [root @ localhost mysql-standard-5.0.18-linux-i686] # mv mysql-standard-5.0.18-linux-i686/usr/local/mysql
Then set permissions
Cd/usr/local/mysql

11. [root @ localhost mysql] # chown-R root. # set root to access/usr/local/mysql
12. [root @ localhost mysql] # chown-R mysql data # set the mysql user to access/usr/local/mysql/data, which contains the mysql database file
13. [root @ localhost mysql] # chgrp-R mysql. # set the mysql group to access/usr/local/mysql.
14. after the configuration is complete, it will basically be installed. Okay, let's run our mysql:
[Root @ localhost 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.
Use the following command to change the root password. the default installation password is blank. to ensure security, you must change it immediately.
15./usr/local/mysql/bin/mysqladmin-uroot password xksoft321
The current password is xksoft321.
16. set automatic start upon startup
Cp support-files/mysql. server/etc/init. d/



II. install apache
Go to the installation package directory: cd/usr/local/software
1, # chmod 755 httpd-2.0.50.tar.gz
2, # tar xfz httpd-2.0.50.tar.gz
3, # cd httpd-2.0.50
Start configuring APACHE
4. #./configure -- prefix =/usr/local/apache2 -- enable-so -- enable-rewrite -- enable-MoD-shared = most
#./Configure -- prefix =/usr/local/apache2 -- enable-so -- enable-module = most -- enable-shared = max -- enable-rewrite
#./Configure -- prefix =/usr/local/apache2 -- enable-so -- enable-rewrite -- enable-access
#./Configure -- prefix =/usr/local/apache2 -- enable-so -- enable-MoD-shared = all -- enable-rewrite = shared

5. # make
6. # make install
7. check the modules compiled into apache:
#/Usr/local/apache2/bin/httpd-l
Compiled-in modules:
Http_core.c
Mod_so.c
The above information indicates that apache supports dso. In this way, you can use dso to add the php and resin modules.

III. install GD
Go to the installation package directory: cd/usr/local/software
1. tar-zxvf gd-2.0.33.tar.gz
2. cd gd-2.0.33
3../configure -- prefix =/usr/local/gd2
4. make
5. make install

Gettext
1. tar xfz
2 cd
3./configure-with-prefix =/usr/local/gettext
4 make
5 make install

4. install php
Go to the installation package directory: cd/usr/local/software
1. # tar xfz php-5.1.2.tar.gz
2. decompress the package and enter the directory:
# Cd php-5.1.2
3. configuration. This step is critical and must be properly configured, especially considering what you want to support, such as the GD Library, xml, mysql, etc. if you want to know the detailed configuration, run. /configure -- help to get:
#. /Configure -- enable-mbstring = LANG -- with-mysql =/usr/local/mysql -- with-gd =/usr/local/gd2 -- with-apxs2 =/usr/local/apache2/ bin/apxs-with-gettext =/usr/local/gettext
-Enable-mbstring = LANG (solve the problem of php extension: mbstring)
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 the related options and compile the configuration:
4. # make
After compilation is successful, the words "Build complete." appears, so you can install it:
5. # make install
6. copy php. ini-dist to/usr/local/lib/and rename it php. ini.
# Cp 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.
7. to enable Apache to parse php directly, we need to make some configuration.
# Vi/usr/local/apache2/conf/httpd. conf
In the httpd. conf file, add the following two statements after other AddType statements)
AddType application/x-httpd-php. php. phtml
AddType application/x-httpd-php-source. phps
Make sure that the file contains the following sentence, and add it after all loadmodules if not:
LoadModule php5_module modules/libphp5.so
Add index. php to the following DirectoryIndex
DirectoryIndex index. php index.html. var
Okay, use ": wq" in vi to save the httpd. conf file and exit vi.
8. start apache server:
#/Usr/local/apache2/bin/apachectl restart
Now apache can run php. write a file and test it. in the/usr/local/apache2/htdocs Directory, create a new phpinfo. php file,
There is only one line of code in the file:

Save the file and enter https://www.php1.cn/in your browser. you should see the php system information.
If an error occurs, for example, if you are prompted to download phpinfo. php, apache cannot parse the php file. check whether the above operations are correct.

5. ZendOptimizer
Go to the installation package directory: cd/usr/local/software
1. # tar xfz ZendOptimizer-2.6.2-linux-glibc21-i386.tar.gz
2, # cd ZendOptimizer-2.6.2-linux-glibc21-i386
3. #./install. sh
4. when you ask Confirm the location of your php. ini file, enter/usr/local/lib/
Are you using Apache web server? Select YES.

VI,
1../configure -- prefix =/usr
2. make
3. make check
4. make install



Service configuration with system startup
If you want to run the httpd service when the computer starts, you can add these lines to the/etc/rc. d/rc. local file:
# Start apache
/Usr/local/apache2/bin/apachectl start

If the script cannot be started, grant the executable permission to the script.
For example, apache cannot start chmod a = x apachectl.


Do not enter a PATH similar to/usr/local/apache2/bin for future operations. add the $ PATH variable to the/etc/profile file.
Add the apache, tomcat, and mysql paths


Appendix:
1. create a virtual host for resin and apache
For example, two virtual hosts are created: tes1.jsp.com test2.jsp.com.

Vi/usr/java/httpd2/conf/httpd. conf
Copy the following content to httpd. conf.
NameVirtualHost 192.168.0. * IP address of the VM

DocumentRoot/home/jsp1/file directory
ServerName tes1.jsp.com domain name

VirtualHost 192.168.1. *>
DocumentRoot/home/jsp2/
ServerName test2.jsp.com

Vi/usr/java/resin/conf/resin. conf
Find and modify the following code:











Save from apache and resin
The tes1.jsp.com and tes2.jsp.com virtual hosts can run
The following test https://www.php1.cn/
We can see that there are
Virtual Host: tes1.jsp.com: 80
Virtual Host: tes2.jsp.com: 80
It proves that the jsp vm is working normally.
II. installation of linux software
Linux software packages found on websites or CDs. common formats include rpm, deb, tar, gz, tgz, zip, and bz2. I'm afraid we usually use the most rpm and tgz. according to statistics, the most popular versions on the Internet should be redhat and mandrake, both of which are encapsulated by rpm.
Tar is the most common software package format. almost every linux software provides a tar-format software package, because the software package in this format is supported by any version of linux, therefore, you should at least understand how to use tar and rpm. Deb can be converted to tgz or rpm using the alien tool. Bz2 can be unwrapped with bunzip2.
1. install the RPM file
RPM is the abbreviation of RedHat Package Manager (RedHat Package management tool). although the file format name is marked with RedHat, its original design concept is open, including OpenLinux, the distribution versions of Linux such as mandrake and Turbo Linux are adopted, which can be regarded as industry standards.
The RPM file is the easiest to install in Linux. Take the famous image processing software XV as an example:
In Terminal, the basic installation commands are as follows:
Rpm-I xv-3.10a-13.i386.rpm
If your network connection speed is fast enough, you can install the application software directly from the network. you only need to add the appropriate URL path before the file name of the software:
Rpm-I ftp://ftp.trilon.com/pub/xv/xv-3.10a-13.i386.rpm
As a software package management tool, RPM manages information about all RPM program components installed in the system. You can also use RPM to uninstall related applications.
Rpm-e xv
Common RPM parameters include:
-VL: displays the installation progress;
-U: upgrade the software package;
-Qpl: lists the file information in the RPM software package;
-Qpi: describe the RPM software package;
-Qf: Find the RPM software package of the specified file;
-Va: checks all RPM software packages to find the lost files;
For more detailed parameters and usage, see The RPM help documentation.
In X-Window, the graphical installation and management methods of RPM files are more friendly to users. After installing the kpackage on kde, you only need to click the mouse to install the rpm, which is more convenient than windows 98. However, you must first install kde.
Let me introduce more common methods, take XV software as an example, find the xv-3.10a-13.i386.rpm file in the file manager of Linux, right-click it with the mouse, in the pop-up menu, you can find three commands for the RPM software package: Show Info, Upgrade, and Install.
After selecting Show Info, we will see the package information window. The window is divided into three parts. The top displays the software name, size, creation and installation date, developer website, and other information. the box in the middle is an overview of the software; the following shows all the files in the software package and their path information. it tells you which directories of the files in the software package will be installed in the system,
Note that the benefit of this information is that you can easily find the path to the startup program.
Click the "Install" or "Upgrade" button at the bottom to Install or Upgrade the software. a prompt window indicating the installation progress is displayed.
The RPM software package has many advantages over other types of software packages, but it does not mean that the installation of the RPM software is smooth sailing. Common errors include the installation of a software that has been installed, the software to be installed, and the support of other software or system library files. (install these software or system library files first) in Windows.

2. installation of tar
Files such as tar.gz, tar. Z, tgz, and bz2 must be decompressed to tar and then installed with tar. Examples of commands for decompression and unpacking are as follows:
1.xv.tar.gz: tar zxf xv.tar.gz
2.xv.tar. Z: tar zxf xv.tar. Z
3. solution xv. tgz: tar zxf xv. tgz
4.release xv.bz2: bunzip2 xv.bz2
5. xv.tar: tar xf xv.tar
A bunch of files obtained after unpacking are usually stored in a directory. Depending on the author of the software, some will be compiled programs, and more is the source code that needs to be compiled by yourself. After entering the corresponding directory, run the "ls-F-color" command to display the executable program in bright green with the "*" mark. for compiled programs, directly type the command line with a path to run the program.
We recommend that you read the instruction file after decompression. you should first read important documents such as Readme and Install in the Software Directory using the vi and other document editors, here you will find detailed software compilation steps and precautions to understand the installation requirements and the need to modify the compilation configuration when necessary.
The source code of some software packages can be uninstalled by using the make install command after compilation and installation. if this function is not provided, the software must be manually deleted. Because the software may install files in multiple directories of the system, it is often difficult to delete the files, you should configure them before compilation, specify the path to which the software will be installed :. /configure -- prefix = directory name. in this way, you can run the "rm-rf software directory name" command to thoroughly uninstall the directory. Compared with other installation methods, it is the most difficult to compile and install by yourself. it is suitable for users who already have some experience in Linux. it is generally not recommended for beginners.
The general compilation steps are as follows:
./Configure
Make
Make install (the command can be executed only when the root identity is obtained)
Uninstall available: make uninstall or manually delete
After compilation, you can easily find executable programs in the current directory or a subdirectory named src. So far, software installation has come to an end.

3. src source code package
The source code src of Linux software refers to the release form of the source code of all programs of the software. you need to compile and install the binary code bin that can be executed by yourself. Its advantage is flexible configuration, some functions/modules can be removed or retained at will to adapt to a variety of hardware/operating system platforms and compiling environments. The disadvantage is that it is difficult and is generally not suitable for beginners.
Do you know whether a tar.gz/bz2 package is a binary package or a source code package? The best way to identify what it is to view the file list in the package, use the command tar ztvf * .tar.gz to decompress and unpack the package, and enter the new directory.
Files in the source code package often contain various source code files, header files *. h. c source code *. c, C ++ code source file *. cc /*. cpp and so on; while files in the binary package will have executable files (the same name as the software is usually the main execution file ), the flag is that its path contains a directory named bin (only a few exceptions ).
If src.tar can be compiled in the newly generated directory after unpacking, the method has been described before. now let's talk about the installation and coordination of src. rpm:
Install: rpm-rebuild xv. src. rpm
Cd/usr/src/redhat/RPMS/
Rpm-ivh *. rpm
Uninstall: rpm-e xv
Note: The rpm -- rebuild *. src. rpm command compiles the source code and generates a binary rpm package under/usr/src/redhat/RPMS, and then installs the binary package.
3. file permission change
Chmod ------ Basic Knowledge
Https://www.php1.cn/author: wangbin Published on: 23:49:13

Command name: chmod
Permission: all users

Usage: chmod [-cfvR] [-- help] [-- version] mode file...

Note: file access permissions for Linux/Unix are classified into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Calculation:

Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxX]...] [,...], u indicates the owner of the file, g indicates that the owner of the file belongs to the same group, o indicates that the owner of the file belongs to other people, and a indicates that all three are.
+ Adds a permission,-indicates canceling the permission, and = indicates a unique permission.
R indicates that the file can be read, w indicates that the file can be written, and x indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable.
-C: if the permission of the file has been changed, the change action is displayed.
-F: do not display an error message if the file permission cannot be changed.
-V: displays details of permission changes.
-R: change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)
-- Help: displays auxiliary instructions
-- Version: displays the version.

Example: set the file file1.txt to readable by all users:
Chmod ugo + r file1.txt

Set file1.txt to readable:
Chmod a + r file1.txt

Set file1.txt and file2.txt as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:
Chmod ug + w, o-w file1.txt file2.txt

Set ex1.py to only the owner of the file to execute:
Chmod u + x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:
Chmod-R a + r *

In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.
Syntax: chmod abc file

Each a, B, and c is a number, indicating the permissions of the User, Group, and Other respectively.

R = 4, w = 2, x = 1
If you want the rwx attribute, 4 + 2 + 1 = 7;
If the rw-attribute is required, 4 + 2 = 6;
If you want the r-x attribute, 4 + 1 = 7.

Example:
Chmod a = rwx file

And
Chmod 777 file

Same effect
Chmod ug = rwx, o = x file

And
Chmod 771 file

Same effect

If you use chmod 4755 filename, you can grant root permissions to this program.
Command name: chown
Permission: root

Usage: chmod [-cfhvR] [-- help] [-- version] user [: group] file...

Note: Linux/Unix is a multi-person, multi-job operating system. all archives have owners. Chown can be used to change the owner of an archive. Generally, this command is only used by the system administrator (root). Generally, users do not have the permission to change the owner of another user's archive or change their owner to another user. Only the system administrator (root) has such permissions.

Calculation:

User: user IDgroup of the new owner: user group of the new owner (group)-c: If the owner of the file has indeed changed, the change action is displayed-f: if the archive owner cannot be changed, do not display the error message-h: only the link is changed, not the file that the link actually points to-v: show owner change details-R: perform the same owner change on all files in the current directory and sub-directories (I .e., change one by one in the way of delivery) -- help: show auxiliary description -- version: Display version

Example:
Set the owner of the file file1.txt to user jessie of the users group:
Chown jessie: users file1.txt

Set all files in the current directory and sub-directory owner to user lamport of users Group:
Chmod-R lamport: users *
-Rw ------- (600) -- only the owner has read and write permissions.

-Rw-r -- (644) -- only the owner has read and write permissions, while the owner and other users have only read permissions.

-Rwx ------ (700) -- only the owner has read, write, and execution permissions.

-Rwxr-xr-x (755)-The owner has the read, write, and execution permissions, while the owner and other users have only the read and execution permissions.

-Rwx -- x (711) -- The owner has read, write, and execution permissions, while the owner and other users have only execution permissions.

-Rw-(666) -- All users have the permission to read and write files. This approach is not advisable.

-Rwxrwxrwx (777)-all users have read, write, and execute permissions. It is not advisable.

The following are two common settings for the directory:


Drwx ------ (700)-only the owner can read and write data in the directory.

Drwxr-xr-x (755)-all users can read this directory, but only the owner can change the contents in the directory.

4. common linux Commands
1. enter the command line
Enter
#/Sbin/telinit 3
2. root password loss solution
GRUB: on the boot loader menu, type [e] to enter the editing mode.
You will face a list of pilot projects. Find the following output sentence lines:
Kernel/vmlinuz-2.4.18-0.4 ro root =/dev/hda2
Press the arrow keys until the line is highlighted and then press [e].
Now you can add a single entry at the end of the text to tell GRUB to guide the Linux mode of a single user. Press the [Enter] key to make the editing result take effect.
You will be taken with the edit mode screen. From Here, Press and GRUB will guide the single-user Linux mode. After loading, you will face a shell prompt similar to the following:
Sh-2.05 #
Now, you can change the root command and type:
Bash # passwd root
You will be asked to retype the password for verification. After the password is changed, you can enter reboot at the prompt to reboot. then, you can log on as the root user as usual.
LILO: when the system starts to display the LILO boot screen, press TAB for the graphic boot mode to enter the text mode, and then at LILO
Enter linux single press enter to enter the password-free console, and then use the passwd command to change the root password
You can.

V. mysql database operations
Connect to the database server./mysql-h host_name-u user_name-p
*-H host_name (-- host = host_name) indicates the host name of the connected Database. it can be omitted if it is on the local host.
*-U user_name (-- user = user_name), database Username. on unix systems, if the system username is the same as the data username, it can be omitted. In windows, you can set the environment variable USER to give the database username, for example, set USER = username.
*-P (-- password) provides the database user password. With this option, mysql will prompt you to enter the password. The entered password is displayed as a star to ensure security. You can also enter the password directly after-p (no space is allowed between-p and the password), but this is not safe and is not recommended.
After the connection is successful, the mysql database server displays some welcome information. Then you can use the mysql> use database_name command to open the specified database. Grant all on egroupware. * to root @ localhost identified by 'oletolet ';
Server startup and shutdown
On Linux and windows platforms, the startup methods of MySQL servers are quite different. here we will introduce them separately:
* Linux: on a Linux platform, each process must be run by one user. it is recommended that MySQL not run as a root user. You can create a mysql user and a mysql group. The MySQL server program directory and data directory are owned by this user and group, and other users do not have any permissions. Run the mysql server as a MySQL User. % Mysqld -- user = mysql
# Even if you run this command as the root user, the MySQL database will still be associated with the mysql User ID. To enable the server to run automatically as a mysql user at system startup, you need to configure the my. cnf configuration file to include user = mysql in the [mysqld] segment.
Disable server availability % mysql. server stop or % mysqladmin-u root-p shutdown
* Windows: run the c: \ mysqld command directly.
As a service method: run the c: \ mysqld-nt -- install Command to install mysqld-nt as a windows service. after that, it runs automatically whenever windows starts. Mysqld-nt is a MySQL server that supports named pipes.
Run c: \ mysqld-nt -- remove to delete the service.
To manually start or close the service, run the c: \ net start mysql and c: \ net stop mysql commands.

On windows:

Log on to the server with an administrator account and disable the MySQL database server.

Use the -- skip-grant-tables parameter to start the server:

C: \ mysql \ bin> mysqld-nt -- skip-grant-tables

Open a new console window and use the mysql command to log on to the server and set the new root password:

C: \ mysql \ bin> mysql
Mysql> use mysql
Mysql> set password for 'root' @ 'localhost' = password ('password ');


Uninstall rpm
Check whether to install
Rpm-qa | grep package name
Uninstall rpm-e package name

Attach the disk mount-t iso9660/dev/hdc/mnt/cdrom

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.