Home Database Mysql Tutorial How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts

How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts

Sep 28, 2024 pm 06:07 PM

How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts

이 완벽한 Ubuntu 설정 가이드로 웹 개발 환경을 쉽게 배포하고 관리하세요

웹서버의 중요성

웹 서버는 웹사이트의 중추로서 전 세계 사용자에게 콘텐츠를 전달하는 플랫폼 역할을 합니다. 웹 서버의 효율성과 안정성은 온라인 활동의 성공에 매우 중요합니다.

Ubuntu, Apache, MySQL, PHP 및 가상 호스트 개요

이 기사에서는 Apache를 웹 서버로, MySQL을 데이터베이스 서버로, PHP를 스크립팅 언어로 사용하여 Ubuntu에서 완전한 웹 서버 환경을 설정하는 방법을 안내합니다. 또한 단일 서버에서 여러 웹사이트를 실행할 수 있는 가상 호스트의 생성 및 구성에 대해서도 다룰 것입니다.

글의 목적

이 가이드의 목적은 초보자와 고급 사용자 모두를 위해 맞춤화된 Ubuntu에서 강력한 웹 서버를 설정하기 위한 자세한 단계별 프로세스를 제공하는 것입니다.

사전 설정

올바른 하드웨어 선택

소프트웨어 설치를 시작하기 전에 하드웨어가 수행할 작업에 적합한지 확인하는 것이 중요합니다. 예상 부하에 따라 CPU 성능, RAM, 저장 용량 등의 요소를 고려하세요.

Ubuntu 서버 설치

  • 우분투 공식 홈페이지에서 최신 버전의 우분투 서버를 다운로드하세요.
  • 부팅 가능한 USB 드라이브를 만들고 컴퓨터에 Ubuntu Server를 설치하세요.
  • 화면의 지시에 따라 설치를 완료하세요.

Ubuntu 업데이트 및 업그레이드

Ubuntu가 설치되면 시스템을 업데이트하고 업그레이드하여 모든 패키지가 최신 상태인지 확인하는 것이 중요합니다.

sudo apt update
sudo apt upgrade
Copy after login

아파치 설치

Apache 웹 서버 이해

Apache는 견고성, 유연성 및 광범위한 모듈 지원으로 잘 알려진 가장 널리 사용되는 웹 서버 중 하나입니다.
Apache 설치 단계

다음 명령을 사용하여 Apache를 설치합니다.

sudo apt install apache2
Copy after login

Apache 시작 및 활성화

Apache 서비스를 시작하고 부팅 시 시작되도록 활성화합니다.

sudo systemctl start apache2
sudo systemctl enable apache2
Copy after login

Apache 설치 확인

Apache가 실행 중인지 확인하려면 다음 명령을 사용하세요.

sudo systemctl status apache2
Copy after login

MySQL 설치

MySQL 데이터베이스 서버 이해

MySQL은 웹사이트와 애플리케이션의 데이터를 저장하고 관리하는 데 사용되는 강력한 관계형 데이터베이스 관리 시스템입니다.

MySQL 설치 단계

다음 명령을 사용하여 MySQL을 설치합니다.

sudo apt install mysql-server
Copy after login

MySQL 설치 보안

MySQL 설치를 보호하려면 다음 보안 스크립트를 실행하세요.

sudo mysql_secure_installation
Copy after login

프롬프트에 따라 루트 비밀번호를 설정하고, 익명 사용자를 제거하고, 데이터베이스를 보호하세요.

MySQL 기능 테스트

MySQL 셸에 로그인하여 제대로 작동하는지 확인하세요.

sudo mysql -u root -p
Copy after login

PHP 설치

PHP 스크립트 언어 이해

PHP는 웹 개발에 사용되는 널리 사용되는 서버측 스크립트 언어입니다. 특히 동적 콘텐츠를 생성하고 데이터베이스와 상호 작용하는 데 적합합니다.
PHP 설치 단계

다음 명령을 사용하여 PHP를 설치합니다.

항상 안정적인 최신 PHP 버전을 제공하는 Ondrej PHP PPA를 추가하세요.

sudo add-apt-repository ppa:ondrej/php
sudo apt update
Copy after login

최신 PHP 버전 설치:

sudo apt install php libapache2-mod-php
Copy after login

일반 PHP 확장 설치:

sudo apt install php-mbstring php-mysql php-curl php-cli php-dev php-imagick php-soap php-zip php-xml php-imap php-xmlrpc php-gd php-opcache php-intl
Copy after login

아파치 다시 시작

sudo systemctl restart apache2
Copy after login
Copy after login

*Laravel용 Composer 설치 *

패키지 관리자 업데이트

먼저 시스템이 업데이트되었는지 확인하세요.

sudo apt update
Copy after login

필수 종속성 설치

curl과 php-cli가 설치되어 있는지 확인하세요.

sudo apt install curl php-cli unzip
Copy after login

Composer 다운로드 및 설치

Ubuntu에 Composer를 설치하려면 다음 명령을 실행하세요.

curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Copy after login

설치 확인

Composer가 성공적으로 설치되었는지 확인하세요.

composer --version
Copy after login

가상 호스트 구성

가상호스트 설명

가상 호스트를 사용하면 단일 서버에서 여러 도메인을 호스팅할 수 있습니다. 각 도메인은 문서 루트, 로그 파일 등을 포함하여 고유한 별도 구성을 가질 수 있습니다.

사이트 디렉터리 구조 만들기

새 사이트에 대한 디렉토리 만들기:

sudo mkdir /var/www/
Copy after login

적절한 권한 설정

Ensure the correct ownership and permissions :

sudo chown -R $USER:$USER /var/www/
sudo chmod -R 777 /var/www/
Copy after login

Creating a Virtual Host File

Create a configuration file for your site :

sudo nano /etc/apache2/sites-available/000-default.conf
Copy after login

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerAlias *
    UseCanonicalName Off
    VirtualDocumentRoot /var/www/%0

    <Directory "/var/www">
        AllowOverride All
        Require all granted
        Options Indexes FollowSymLinks
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Copy after login

Enabling the New Virtual Host

Enable the new site and test the configuration:

sudo a2ensite 000-default.conf
sudo apache2ctl configtest
Copy after login

Restarting Apache

Restart Apache to apply the changes:

sudo systemctl restart apache2
Copy after login
Copy after login

Editing the Hosts File

Map your domain to the local server by editing the hosts file:

sudo nano /etc/hosts
Copy after login

Add the following line:

127.0.0.1       demo
Copy after login

The above is the detailed content of How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

How does MySQL index cardinality affect query performance? How does MySQL index cardinality affect query performance? Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

See all articles