Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install Apache, PHP and Mysql under ubuntu

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to install Apache, PHP and Mysql under ubuntu". In the daily operation, I believe that many people have doubts about how to install Apache, PHP and Mysql under ubuntu. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to install Apache, PHP and Mysql under ubuntu". Next, please follow the editor to study!

Of course, do not use Gnome, using terminal commands is also very simple:

Direct one command: apt-get install apache2 mysql-server php5 php5-gd php5-mysql libapache2-mod-auth-mysql

Set read and write permissions for Ubuntu files

Sudo chmod 777 / var/www

Install phpmyadmin-Mysql database management

Sudo apt-get install phpmyadmin

Phpmyadmin settings:

During the installation process, you will be asked to select Web server:apache2 or lighttpd, select apache2, press tab, and then confirm. Then you will be asked to enter the set Mysql database password connection password Password of the database's administrative user.

Then connect phpmyadmin to apache2, take mine as an example: the www directory is in / var/www,phpmyadmin / usr/share/phpmyadmin directory, so use the command: sudo ln-s / usr/share/phpmyadmin / var/www to establish a connection.

Phpmyadmin test: open http://localhost/phpmyadmin in the browser address bar.

How to configure Apache for Ubuntu LAMP

1. Enable the mod_rewrite module

Terminal command: sudo a2enmod rewrite

Restart the Apache server: sudo / etc/init.d/apache2 restart

After Apache restarts, we can test it, create a new file test.php in the / var/www directory, write the code: save, and enter http://127.0.0.1/test.php or http://localhost/test.php in the address bar. If the php configuration information appears correctly, it means that LAMP Apache is working properly (remember to restart the Apache server and test again).

two。 Set Apache to support .htm .html .php

Sudo gedit / etc/apache2/apache2.conf

Or sudo gedit / etc/apache2/mods-enabled/php5.conf

Add to the open file

AddType application/x-httpd-php .php .htm .html is fine.

Mysql testing of LAMP configuration

Php,Apache has been tested above, so let's test again whether the Mysql database has been enabled correctly.

Create a new mysql_test.php under the / var/www directory:

Save and exit, type http://127.0.0.1/mysql_test.php in the address bar and show that "Mysql has been configured correctly" means OK. If not, restart the Apache server and try again.

1. Configure php5

Command: sudo vim / etc/php5/apache2/php.ini

Modify the maximum use of memory allowed, find

Memory_limit = 8m

Modify to

Memory_limit = 32m

Modify the maximum allowed upload size, find

Upload_max_filesize = 2m

Modify to

Upload_max_filesize = 8m

Allow mysql and gd modules to check whether the file contains the following code at the end, if not added. (it is added at the end of the configuration file by default, check it just in case)

Extension=mysql.so

Extension=gd.so

Save and close the file.

2. Configure apache

1. The configuration file in ubuntu is under / etc/apache2, apache2.conf is the global configuration or main configuration file, and httpd.conf is the user configuration file. It feels the same as using config.php to overwrite the settings in the config.default.php file when writing programs in php. The user settings are independent and convenient for management and backup. After all, the main configuration document is rarely modified, and occasionally one or two sentences can be written into httpd.conf, so backup is convenient.

Add a line to / etc/apache2/httpd.conf: ServerName 127.0.0.1

Command: sudo gedit / etc/apache2/httpd.conf

2. The following paragraph is found on the official website

Edit the / etc/apache2/apache2.conf file (the newly installed system may be in / etc/apache2/conf.d/charset). Please make a backup of the configuration file before making any changes. So that you can recover if something goes wrong. Set

AddDefaultCharset ISO-8859-1

Change to

AddDefaultCharset GB2312

Of course, if the coding of your website uses UTF-8, you can also change it to

AddDefaultCharset UTF-8

In this way, we won't be garbled every time we open the web page!

3. Add a security module to ensure the normal operation of the Apache service. Now let's install mod-security. (optional)

a. Install the libapache2-mod-security package first (systems after 7.10 no longer have this package, so you can skip this step)

Sudo apt-get install libapache2-mod-security

a. The module is not activated by default, and we can see the mod-security.load file in the / etc/apache2/mods-available directory, but there is no soft link to it in the / etc/apache2/mods-enabled directory. Let's activate it now:

$sudo a2enmod mod-security

$sudo cp / usr/share/doc/libapache2-mod-security/examples/httpd2.conf.example-full / etc/apache2/mods-available/mod-security.conf

$sudo cp / etc/apache2/mods-available/mod-security.conf / etc/apache2/mods-available/mod-security.conf.orig

$sudo vi / etc/apache2/mods-available/mod-security.conf

= = start of mod-security.conf file content =

# check the content length to avoid heap overflow attacks

SecFilterForceByteRange 32 254 = > SecFilterForceByteRange 32 126

# debug Settings

SecFilterDebugLevel 9 = > SecFilterDebugLevel 0

# set the default action

SecFilterDefaultAction "deny,log,status:499" = > SecFilterDefaultAction "deny,log,status:404"

# pass settings to subdirectories

SecFilterInheritance Off

# Redirect user on filter match

# when matching sh, redirect to a special warning page, which is written by yourself. Write some warnings to let the attacker back down in the face of difficulties. This paragraph does not take effect until the relevant configuration is configured. Remember to make it effective after it is ready.

# SecFilter sh redirect: http://localhost/hack/warning.htm

# Prevent OS specific keywords

# filter something sensitive, we use * for attackers to use / etc/./passwd to bypass detection

SecFilter / etc/passwd = > SecFilter / etc/*passwd

SecFilter / bin/*sh

# Very crude filters to prevent SQL injection attacks

# prevent SQL insertion (SQL Injection) attacks

SecFilter "delete [space |] + from"

SecFilter "insert [space |] + into"

SecFilter "select.+from"

SecFilter "select [space |] + from"

SecFilter "union [space |] + from"

= end of mod-security.conf file content =

Sudo ln-s / etc/apache2/mods-available/mod-security.conf / etc/apache2/mods-enabled/mod-security.conf

a. Just restart the Apache2 service.

Sudo / etc/init.d/apache2 restart

Finally, just remember the following four commands

Sudo / etc/init.d/apache2 restart

Sudo vim / etc/php5/apache2/php.ini

Sudo vim / etc/apache2/apache2.conf

/ var/www/ (home directory location)

If apache2: Could not reliably determine the server's fully qualified domain name appears during installation, using 127.0.1.1 for ServerName

Just modify the httpd.conf.

Specific operation: open httpd.conf sudo vim / etc/apache2/httpd.conf first

By default, this is an empty file, add the following sentence

ServerName localhost

Save and restart apache.

At this point, the study on "how to install Apache, PHP and Mysql under ubuntu" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report