Old drivers teach Ubuntu Apache + PHP + MySQL environment construction strategy

Source: Internet
Author: User
This article mainly introduces how to build the Apache + PHP + MySQL environment in Ubuntu. the LoadModule loading module is used to connect PHP to the Apache server program. For more information, see 1. first install MySql:
For MySql, the installation process is relatively independent, and MySql has been installed in ubuntu before development. Therefore, only the installation steps are as follows:

1. install MySql services:

sudo apt-get install mysql-server

Note that during the installation process, you will be prompted to set the password for the root account of mysql. there is nothing else to pay attention.

2. install the MySql client:

sudo apt-get install mysql-client 

Enter installation directly

3. install MySql lib dependent libraries:

sudo apt-get install libmysqlclient15-dev

.
Mysql. h cannot be found in the system if it is not installed.

4. some simple MySQL management:

Start the MySQL service:

sudo start mysql

Stop MySQL service:

sudo stop mysql

Modify the MySQL administrator password:

sudo mysqladmin -u root password newpassword

Set remote access (normally, mysql only listens to Port 3306 on IP 127.0.0.1, and denies access from other IP addresses (which can be viewed through netstat ). Cancel local monitoring

Modify the my. cnf file as follows :):

Sudo vi/etc/mysql/my. cnf bind-address = 127.0.0.1 // locate this content and comment


5. directory structure analysis after MySQL installation (this structure is only applicable to online installation using apt-get install ):

Database storage directory:/var/lib/mysql/

Related configuration file storage directory:/usr/share/mysql

Related Command storage directory:/usr/bin (mysqladmin mysqldump and other commands)

Startup step storage directory:/etc/rc. d/init. d/

The above is the basic installation of MySql.

II. install apache2:

1, the official website download http://httpd.apache.org/download.cgi,Unix Source: httpd-2.2.24.tar.gz, my next is 2.2.24 tar.gz, then decompress tar.gz

   tar zxvf httpd-2.2.24.tar.gz

Move the extracted file to/usr/src/apache2.

   sudo mv -r httpd-2.2.24 /usr/src/apache2 

If no apache2 file can be moved, manually create one

sudo mkdri /usr/src/apache2 

Because the root permission is required to modify the file under/usr/, you need to add the sodu command and enter the password.

2. enter/usr/src/apache2/httpd-2.2.24 and compile and install

   cd /usr/src/apache2/httpd-2.2.24   ./configure -prefix=/usr/local/apache -enable-module=so -enable-rewrite=shared -enable-authn-dbm


After compilation is complete
Enter the make command, and then enter make install to start installation.

3. configure httpd. conf after installation:

Vim/usr/local/apache2/conf/httpd. conf # Open httpd. conf in the editor. I use vim to open httpd. conf.

Find # ServerName and remove the annotator # and change the following content to localhost: 80:
ServerName localhost: 80
In this way, the service can be accessed through localhost during startup.
If you want to modify the listening port of the server, you can go to httpd. search for Listen 80 in conf and change the port 80 following it to the port you want. change the port 80 following ServerName localhost: 80 to the port you want.

4. start the service:

Cd/usr/local/apache2/bin # go to the/usr/local/apache2/bin directory sudo./apachectl start # start apache service

Open the browser and enter the access address localhost to check whether It Works is displayed. If yes, the installation is complete.

3. install and configure PHP5

1. first install libxml2 library, used to parse xml lib Library input: sudo apt-get install libxml2-dev for installation

2, the official website to download the php http://www.php.net/downloads.php after the download of the tar.gz package

Tar zxvf php-5.4.15.tar.gz # unzip sudo mv-r php-5.4.15/usr/src/php5 # Move to/usr/src/php5 Directory

3. Compile and install php

Cd/usr/src/php/php-5.4.15 # enter the directory where php is located. /configure-prefix =/usr/local/php5 # php installation directory-with-apxs2 =/usr/local/apache2/bin/apxs # directory of apxs, if there is no sudo find/-name apxs, query the Directory-with-mysql =/usr. h directory, I don't know why my mysql. h is in/usr/include/, but it is useless to write this path./usr/If you do not know mysql. where h is sudo find/-name mysql. h. find the directory in which-with-mysqli =/usr/bin/mysql_config # mysql_config is located. if you do not use this directory, find it. -With-gd # open support for the gd Library. if this error is returned, install the gd library-with-pear # support for opening the pear command-with-libxml-dir # enable the support for libxml2 just installed.

The entire compilation statement is:

The code is as follows:

. /Configure-prefix =/usr/local/php5-with-apxs2 =/usr/local/apache2/bin/apxs-with-mysql =/usr/-with-mysqli =/usr/ bin/mysql_config-with-gd-with-pear-with-libxml-dir


If an error occurs during compilation, it is generally caused by a dependency Library lib problem. check the prompt for missing dependency libraries and install the library.
After the installation is complete, make it and then enter make install.

4. manually specify the php. ini file:
Open/usr/local/apache2/conf/httpd. conf, add PHPIniDir/etc/php under the LoadModule php_module modules/libphp5.so line. ini refers to the php.ini example. Then, enter the php-5.4.15.tar.gz directory you are trying to decompress. ini-development is copied to the path/etc you specified and renamed as php. ini:

Cd/usr/src/php/php-5.4.15 # enter the php directory sudo cp php. ini-development/etc # Copy to/etc sudo mv php. ini-development php. ini # rename it to php. ini

5. modify php support in httpd. conf and default access index. php:
Open/usr/local/apache2/conf/httpd. conf To:

   
 Options FollowSymLinks DirectoryIndex. php index.html # specify to search for index. php by default. if not, search for index.html AllowOverride None Order deny, allow Deny from all

Add the following content to the AddType application/x-gzip. gz. tgz line:

   AddType application/x-httpd-php .php   AddType application/x-httpd-php-source .phps

After saving the file, if you are prompted that the file cannot be saved in read-only mode, sudo must be added when the httpd. conf command is opened.

6. start or restart the apache service and write the php file in the root directory of the server.

Sudo/usr/local/apache2/bin/apachectl stop # stop service sudo/usr/local/apache2/bin/apachectl start # start service sudo/usr/local/apache2/bin/ apachectl rstart # restart the service

Cd/usr/lcoal/apache2/htdocs # enter the default root directory of apache2

Create an index. php file and write it in it <? Php echo phpinfo ();?> Open the browser and enter localhost to check whether php information can be displayed. If yes, the configuration is successful.


4. other configurations:

1. manually configure the default apache root directory
Open the/usr/local/apache2/conf/httpd. conf directory in the editor, find DocumentRoot/usr/lcoal/apache2/htdocs, change the path to the path you want, and find it at the next point. Change the path to the path you want to specify.

2. view the path of php. ini:
Most of the time I don't know where to specify the php. ini path. I just need to compile it. <? Php echo phpinfo ();?> The File is then accessed using the browser. after seeing all the php information, find the path information on the right of the row: Loaded Configuration File, which is the address of the specified php. ini path.

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.