This post is to save in one place all the commands used to build LAMP stack on a Ubuntu server. I am creating this post so that I can reference this whenever I need to set up a new Ubuntu server for web development which happens quite often.
First, update package manager cache:
$ sudo apt update
Install Apache web server:
$ sudo apt install apache2
At this point, if you go to http://localhost, you should be able to see the Apache2 default page.
You can configure firewall for Apache but I'm usually setting up LAMP stack for local development so I'm going to skip configuring firewall.
Install MySQL server:
sudo apt install mysql-server
Then configure MySQL server using the following command:
sudo mysql_secure_installation
Set mysql root password using following commands:
$ sudo mysql mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; mysql> exit
Install PHP:
sudo apt install php libapache2-mod-php php-mysql
Confirm php is installed:
$ php -v PHP 8.3.6 (cli) (built: Dec 2 2024 12:36:18) (NTS) Copyright (c) The PHP Group Zend Engine v4.3.6, Copyright (c) Zend Technologies with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
Install PHP Extensions:
sudo apt install php8.3-cli php8.3-{bz2,curl,mbstring,intl,xml,mysql,fpm}
Enable php-fpm and apache mod for php:
sudo a2enconf php8.3-fpm sudo a2enmod proxy_fcgi setenvif sudo a2enmod php8.3
Restart apache2:
sudo systemctl restart apache2
If creating a new Laravel website, use the following apache config file to get started with creating a virtual site:
<VirtualHost *:80> ServerAdmin admin@example.com ServerName mysite.test DocumentRoot /home/baese/projects/mysite/public/ <Directory /home/baese/projects/mysite/public/> DirectoryIndex index.php AllowOverride All Require all granted Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Top comments (0)