Home > Operation and Maintenance > Linux Operation and Maintenance > How to build a php environment for cloud server linux

How to build a php environment for cloud server linux

WBOY
Release: 2023-05-14 18:43:25
forward
1556 people have browsed it

1. Choose a suitable cloud server

First of all, you need to choose a suitable cloud server. Choose the appropriate configuration and operating system based on your needs. Here we take the CentOS system on Alibaba Cloud as an example.

2. Install the web server

The first step in setting up the environment is to install a web server such as Apache or Nginx. Here we take Apache as an example. Use the following command to install Apache in the terminal:

sudo yum update
sudo yum install httpd
Copy after login

After the installation is complete, start the Apache service and set it to start at boot:

sudo systemctl start httpd.service
sudo systemctl enable httpd.service
Copy after login

At this time, by accessing the public IP address of the cloud server, browse Enter the IP address into the server and you will see the default page of Apache, indicating that Apache has been successfully installed.

3. Install php

Next, install php. Use the following command to install php in the terminal:

sudo yum -y install php php-mysql
Copy after login

After the installation is complete, restart the Apache service:

<code><code>##<div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">sudo systemctl restart httpd.service</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><code>

4. Test the php environment

After the installation is completed, you can verify whether PHP is successfully installed by using the following command:

sudo vim /var/www/html/info.php
Copy after login

Enter in the info.php file The following content:

<?php phpinfo(); ?>
Copy after login

After saving and exiting the file, you can see it by entering the public IP address of the cloud server in the browser and adding /info.php, that is:

http://你的IP地址/info.php
Copy after login

PHP related information, such as PHP version, configuration file path, etc., indicates that the PHP environment has been successfully established.

5. Install php extensions

In php applications, you need to install some php extensions to run properly. Here are some common extension installation methods.

  1. Install curl extension

curl is a tool used to transmit data. Many PHP applications require curl extension. Use the following command to install the curl extension in the terminal:

sudo yum install php-curl
Copy after login

After the installation is complete, restart the Apache service:

<code><code><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">sudo systemctl restart httpd.service</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><code>

  1. Install gd extension

gd is an extension for processing images. Use the following command to install the gd extension in the terminal:

sudo yum install php-gd
Copy after login

After the installation is complete, restart the Apache service:

<code><code><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">sudo systemctl restart httpd.service</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><code>

  1. Install the mbstring extension

mbstring is an extension for handling multi-byte encodings. Install the mbstring extension in the terminal using the following command:

sudo yum install php-mbstring
Copy after login

After the installation is complete, restart the Apache service:

<code><code><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">sudo systemctl restart httpd.service</pre><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><div class="contentsignin">Copy after login</div></div><code>

TIPS: According to different application requirements, you can also install mysqli extension, imagick extension, etc.

6. Configure php.ini

By modifying the php.ini file, you can configure some configurations for the operation of php, such as setting time zone, upload file size limit, etc.

Use the following command to open the php.ini file:

sudo vim /etc/php.ini
Copy after login

Find the following configuration items to modify:

display_errors = On              # 显示错误信息
date.timezone = Asia/Shanghai    # 设置时区
upload_max_filesize = 20M        # 设置上传文件大小限制
Copy after login
After the modification is completed, save and exit.

The above is the detailed content of How to build a php environment for cloud server linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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