Home  >  Article  >  Backend Development  >  How to install PHP7 lamp

How to install PHP7 lamp

王林
王林Original
2023-05-22 21:05:07383browse

When developing web applications, a software stack called LAMP is often used. LAMP stands for Linux, Apache, MySQL and PHP. Among them, PHP is a popular server-side scripting language, and the LAMP environment can provide a complete web development environment. This article will focus on how to install the LAMP environment for PHP7.

Before you begin, make sure you have a Linux operating system and Apache web server installed. At the same time, you also need to have certain basic knowledge of the command line. It is recommended to use Ubuntu operating system for installation as it is one of the most popular Linux distributions using LAMP environment.

Step 1: Install PHP7

First install the pre-dependencies of PHP7. Install using the following command:

sudo apt-get install -y python-software-properties software-properties-common

sudo add-apt-repository ppa:ondrej/php

sudo apt-get update

sudo apt-get install -y php7.0 php7.0-cli php7.0-common libapache2-mod-php7.0 php7.0-mysql php7.0-sqlite3 php7.0-mcrypt php7.0-curl php7.0-json php7.0-gd php7.0-gmp php7.0-mbstring php7.0-zip

This will install PHP7 and its required extensions. If you are using a different operating system, you may need to use different commands to install PHP7.

Step 2: Test PHP7

After the installation is complete, we need to test whether PHP has been installed correctly.

First, create a test file using the following command:

sudo nano /var/www/html/info.php

Then, copy and paste the following code into the file:

<?php phpinfo(); ?>

This will create a test file with PHP information web page. Enter the IP address or domain name of the server in the browser, and then enter "/info.php" in the address bar, for example:

http://your_server_IP_address/info.php

If everything goes well, you should be able to see the PHP information page and confirm PHP7 Installed successfully.

Step 3: Install and configure the MySQL database

MySQL is another required component that is used as the database management system for the LAMP environment. Use the following command to install:

sudo apt-get install -y mysql-server mysql-client

After the installation is complete, we need to run the following command to configure MySQL:

sudo mysql_secure_installation

In this interactive script, you will need to set the password for the MySQL root user and Other security settings. Finally, you need to set a strong password for the root user and disable external access.

Step 4: Test MySQL

After the installation is complete, test whether MySQL is running normally. Enter the following command on the command line:

mysql -u root -p

Enter the password of the MySQL root user to enter the database. If there are no error messages, it means that the MySQL service is up and running.

Step 5: Configure Apache

Apache is the website server in the LAMP environment, and it needs to be used with PHP and MySQL. You can install Apache using the following command:

sudo apt-get install -y apache2

Similarly, we also need to test whether Apache is running properly. Enter the IP address or domain name of the server in the browser. If you can see the "Apache2 Ubuntu Default Page" page, it means that the Apache server has been installed and configured correctly.

Step 6: Enable mod_rewrite

mod_rewrite is an Apache module that can rewrite URLs and perform internal redirects. In most websites, it must be enabled, so you can use the following command to enable it:

sudo a2enmod rewrite

Restart the Apache server to take effect:

sudo systemctl restart apache2

Step 7: Firewall Settings

In order to enhance the security of the server, we need to enable the firewall to control network traffic. You can use the following command to install the firewall:

sudo apt-get install -y ufw

Enable the firewall:

sudo ufw enable

Open http and https traffic:

sudo ufw allow http

sudo ufw allow https

At this point, you have successfully installed PHP7 LAMP environment. LAMP is a very common web development environment that is quick to set up and use on Linux systems. Finally, we recommend that you back up all critical data and perform regular system updates to protect the security of your server.

The above is the detailed content of How to install PHP7 lamp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP array evaluationNext article:PHP array evaluation