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.