In this tutorial, you must modify the related IP addresses in your environment.
Update apt-get before use, because the server is basically a bare System
Apt-get update;
Apt-get upgrade;
1. We use the root account for installation. First switch to the root account and enter the following command:
Sudo su
2 install MySQL 5
Enter the following command:
Apt-get install mysql-server mysql-client
You need to set the root account password during installation. The system will prompt you as follows:
New password for the MySQL "root" user: Repeat password for theMySQL "root" user:
3. Install Apache2
Enter the following command:
Apt-get install apache2
Enter your server address in the browser and enter http: // 192.168.0.100 to check whether Apache2 works. If it is displayed (Itworks !), It indicates that you have already worked.
In Ubuntu, the default file root directory of Apache is/var/www, And the configuration file/etc/apache2/apache2.conf is used, additional storage subdirectories/etc/apache2 such as/etc/apache2/mod-enabled (Apache module),/etc/apache2/sites-enabled (virtual hosts ), and/etc/apache2/conf. d.
4. Install PHP5
Install the PHP5 and Apache PHP5 modules:
Apt-get install php5 libapache2-mod-php5
(If any installed content cannot be found, update apt-get and execute apt-get update)
Restart apache:
/Etc/init. d/apache2 restart
5. Test PHP5/create a probe page
Vi/var/www/info. php
Enter the following content:
<? Php
Phpinfo ();
?>
Then open the browser to access (http: // 127.0.0.1/info. php ):
You can see some supported modules.
6. Obtain MySQL support for PHP5
We need to install the php5-mysql, first check the php5 Module
Apt-cache search php5-mysql
Php5-mysql-MySQL module for php5
Php5-mysqlnd-MySQL module for php5 (Native Driver)
Then install the required module, for example, the following command:
Apt-get install php5-mysql
Apt-get install php5-mysqlnd
Sudo apt-get install php5 libapache2-mod-php5 php5-cgi php5-cli php5-common php5-curl php5-gd php5-mysql
Sudo a2enmod php5
What is the difference between the php5 module and the php5 module? It is very convenient to install the php5 module in ubuntu.
The following modules are installed by yourself. Some modules are not necessarily correct.
Apt-get install php5-mysql php5-curl php5-gd php5-intlphp-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mingphp5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidyphp5-xmlrpc
Restart Apache2:
/Etc/init. d/apache2 restart
Click http: // 127.0.0.1/info. php to check whether the module support has been added.
7. phpMyAdmin
Install phpmyadmin to manage mysql:
Apt-get install phpmyadmin
Phpmyadmin settings:
During the installation process, You must select Web server: apache2 or lighttpd, select apache2, press the tab key, and click OK. Then, you are required to enter the Mysql database Password of the database's administrative user.
Then, establish a connection between phpmyadmin and apache2. Take my example: the www directory is in the/var/www directory, and the phpmyadmin directory is in the/usr/share/phpmyadmin directory. Therefore, run the following command: connect sudo ln-s/usr/share/phpmyadmin/var/www.
Phpmyadmin test: Open http: // localhost/phpmyadmin in the address bar of the browser.
Phpmyadmin access address: http: // 127.0.0.1/phpmyadmin/
The above LAMP basic components have been installed. Next let's take a look at some other settings:
Set the Ubuntu File Read and Write Permissions
After LAMP is installed, the default root directory of the PHP network server is/var/www. Due to the security principle of Linux, only root users are allowed to change the file read and write permissions under the directory. Therefore, you cannot create or delete PHP files in the www folder, you must first modify the read and write permissions of the/var/www directory. You cannot modify the File Permission by right-clicking the attribute in the interface manager. You must run the root terminal command: sudo chmod 777/var/www. Then you can write html or PHP files. If you are not clear about the file permissions indicated by 777, refer to the chmod command.
Configure Apache
1. Enable mod_rewrite module
Terminal command: sudo a2enmod rewrite
Restart Apache server: sudo/etc/init. d/apache2 restart
After Apache is restarted, we can test whether to create a file test. php under the/var/www directory and write the code: <? Php phpinfo ();?> Save and enter http: // 127.0.0.1/test in the address bar. php or http: // localhost/test. php. If the correct php configuration information appears, it indicates that LAMP Apache is working properly (remember to restart the Apache server before testing ).
2. Set apacheto support .htm. html. php
Sudo gedit/etc/apache2/apache2.conf
Add
AddType application/x-httpd-php. php. htm. html.
Configure Mysql Test
The above php and Apache have been tested. Next we will test whether the Mysql database has been correctly enabled.
Create mysql_test.php in the/var/www directory:
Copy codeThe Code is as follows: <? Php
$ Link = mysql_connect ("localhost", "root", "020511 ″);
If (! $ Link)
{
Die ('could not connect: '. mysql_error ());
}
Else echo "Mysql has been correctly configured ";
Mysql_close ($ link );
?>
Save and exit. in the address bar, enter http: // 127.0.0.1/mysql_test.php. If "Mysql has been correctly configured", it indicates OK. If not, restart the Apache server and try again.
Configure php5
Modify sudo gedit/etc/php5/apache2/php. ini to allow maximum memory usage.
Modify memory_limit = 8 m
Memory_limit = 32 M
Modify the maximum size allowed for upload and search
Upload_max_filesize = 2 MB
Upload_max_filesize = 8 M
Allow the mysql and gd modules to check whether the file finally contains the following code, if not added. (It is added at the end of the configuration file by default. Check it just in case)
Extension = mysql. soextension = gd. so save and close the file.
If garbled characters appear, the solution is as follows:
Configure apache character encoding:
Sudo gedit/etc/apache2/conf. d/charset
Change the content to AddDefaultCharset UTF-8
Configure php character encoding:
Sudo gedit/etc/php5/apache2/php. ini
Find
Code:
Default_charset = iso-8859-1 ″
Change
Code:
Default_charset = UTF-8 ″
Restart apache:
Code:
Sudo/etc/init. d/apache2 restart