انتقل إلى المحتوى

الدروس الخوادم متوسط1 دقائق قراءة

How to Install a LAMP Stack (Linux, Apache, MySQL, PHP) on Ubuntu

Install Apache, MySQL (or MariaDB) and PHP on Ubuntu 24.04, open the firewall, secure the database and test PHP — the classic base for PHP websites.

بواسطة فريق تحرير ZSOLNET آخر تحديث

هذه الصفحة غير متاحة بالعربية بعد، لذا تُعرض بالإنجليزية.

أهم النقاط

  • LAMP runs most PHP applications, including WordPress.
  • Secure MySQL right after installing it.
  • Remove test files like info.php when finished.

These steps assume Ubuntu 24.04 and a user with sudo rights.

1. Apache

sudo apt update
sudo apt install apache2
sudo ufw allow 'Apache Full'

Visit http://your-server-ip — you should see the Apache default page.

2. MySQL

sudo apt install mysql-server
sudo mysql_secure_installation

Answer yes to removing anonymous users, disallowing remote root login and removing the test database.

Create a database and user for your application:

sudo mysql
CREATE DATABASE app;
CREATE USER 'app'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON app.* TO 'app'@'localhost';
FLUSH PRIVILEGES;
EXIT;

3. PHP

sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-zip
sudo systemctl restart apache2

4. Test PHP

echo '<?php phpinfo();' | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php, confirm it shows the PHP version, then delete it: sudo rm /var/www/html/info.php.

Next steps

Create a virtual host for your domain, point DNS at the server, and add a free certificate with Certbot.

الأسئلة الشائعة

Should I choose LAMP or LEMP?

Both work well. Apache supports .htaccess files, which many PHP apps rely on. Nginx (LEMP) uses less memory under heavy load. Pick what your application documents.

MySQL or MariaDB?

Either is fine for most sites. MariaDB is a drop-in replacement for MySQL and is the default on many distributions.

شارك X LinkedIn Facebook

الدخول إلى حسابك

أدِر نطاقاتك واستضافتك وفواتيرك من مكان واحد.

اتصال آمن مباشرة مع منطقة العملاء في ZSOLNET.

افتح لوحة تحكم ZSOLNET

ليس لديك حساب؟