


Build a lamp on the server (Linux (CentOS7) + Apache + MySQL + PHP)
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
2.Start the apache service
systemctl start httpd.service
3.Set the apache service to start at boot
systemctl enable httpd.service
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
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
2. Restart apache servicesystemctl 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
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
yum -y install MariaDB-server MariaDB-client
yum install mariadb-embedded mariadb-libs mariadb-bench mariadb mariadb-sever
yum install mariadb*
-
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
3. Set the MySQL service to start at boot
systemctl enable mariadb.service
4. Set the password for the root account
mysql_secure_installation
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
2. Restart the apache service
systemctl restart httpd.service
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!

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
