Build a lamp on the server (Linux (CentOS7) + Apache + MySQL + PHP)

jacklove
Release: 2023-04-01 10:22:02
Original
1998 people have browsed it

I recently purchased Alibaba Cloud’s ECS cloud server student machine for learning website building. However, I was not very good at building a website environment. I searched a lot of tutorials online but they were too repetitive. Finally, I found a suitable solution. The method is specially summarized and shared.

PS: I am using CentOS 7.3 system. The installation code may be different between different operating systems, so this article is mainly for CentOS system


, Install Apache

1.Install

yum -y install httpd
Copy after login

2.Start the apache service

systemctl start httpd.service
Copy after login

3.Set the apache service to start at boot

systemctl enable httpd.service
Copy after login

4.Verify the apache service Whether the installation is successful

Enter your host's external IP address in the browser. If the installation is successful, an Apache welcome page will appear with the words Testing 123..., which means the apache service has been successfully installed;

Don’t worry if you can’t connect, it’s because you haven’t set up a firewall yet. Solution:

CentOS7 uses Firewall-cmd, and CentOS7 used iptables firewall before; if you want to If you can access the apache home directory from the external network, you need to do the following operations:
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
firewall-cmd –reload

If the above method does not work, you can also try to turn off the firewalld service and replace it with the firewall service iptables before CentOS 6. The details are as follows:

systemctl stop firewalld.service    //关闭firewalldsystemctl start iptables.service    //开启iptablessystemctl enable iptables.service   //自启动iptables
Copy after login

Also It is very important to set up the security group of your Alibaba Cloud server to allow external access, otherwise the website cannot be accessed from the outside


2. Install PHP

1 .Install

yum -y install php
Copy after login

2. Restart apache service
systemctl restart httpd or systemctl restart httpd.service

Then, you can write a Run the php file in the browser

example:

通过下列vim修改创建info.php页面,显示你的系统信息:
vi /var/www/html/info.php
i<?php phpinfo(); ?>Esc
:wq
Copy after login

Then enter your IP (eg: 192.168.1.1)/info.php in your computer browser
Under normal circumstances, your server installation information will be displayed, then PHP installation is successful and the server can carry dynamic web pages!


3. Install MySQL

Of course, dynamic web pages also need a database to store various data, so the next step is to install MySQL;

What I installed here is not Oracle’s MySQL, but chose to install MariaDB

1. Install

yum -y install mariadb-service mariadb
Copy after login
yum -y install MariaDB-server MariaDB-client
Copy after login
yum install mariadb-embedded mariadb-libs mariadb-bench mariadb mariadb-sever
Copy after login
yum install mariadb*
Copy after login

-

PS: The above components It is best to install them all to avoid failure to connect to PHP

-

2. Start the MySQL service

systemctl start mariadb.service
Copy after login

3. Set the MySQL service to start at boot

systemctl enable mariadb.service
Copy after login

4. Set the password for the root account

mysql_secure_installation
Copy after login

Then a series of things will appear, just press Enter, and then continue to ask you to select y/n, just Enter; when everything is over At this time, you can enter mysql -uroot -p to log in to the database and verify whether the setting is successful;


4. Associate PHP with MySQL
First enter yum search php, select the installation you need, and then enter yum -y install php-mysql

5. Install commonly used PHP modules

1. Installation:

A large string of codes, just copy it

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
Copy after login

2. Restart the apache service

systemctl restart httpd.service
Copy after login

Then, run info.php in the browser again, you will see the information about the installed modules ;

At this point, the LAMP environment is set up. Let’s try deploying a dynamic web page!

This article explains how to build a lamp (Linux (CentOS7) Apache MySQL PHP) on the server. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Explanation of simple examples of Android PHP MYSQL development

Detailed explanation of $this usage in PHP

The relationship between Java and PHP

The above is the detailed content of Build a lamp on the server (Linux (CentOS7) + Apache + MySQL + PHP). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template