How to deploy your website on a Linux server?
To deploy your own website on a Linux server, you can follow these steps:
Choose the appropriate Linux distribution, such as Ubuntu or CentOS, and install it on the server.
2. Setting up the LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP) stack is a common software combination used for building websites. You can install it by running the following commands in the terminal.
- For the LAMP stack:
On Ubuntu: sudo apt-get install lamp-server^
On CentOS: sudo yum install httpd mysql-server php php-mysql - For the LEMP stack:
On Ubuntu: Install nginx, mysql-server, php-fpm, and php-mysql using the command: sudo apt-get install nginx mysql-server php-fpm php-mysql
On CentOS: Install nginx, mysql-server, php-fpm, and php-mysql using the command: sudo yum install nginx mysql-server php-fpm php-mysql
3. Set up a web server (Apache or Nginx).
- For Apache:
On Ubuntu: The configuration file is located in /etc/apache2/
On CentOS: The configuration file is located in /etc/httpd/ - For Nginx:
On Ubuntu: configuration files are located in /etc/nginx/
On CentOS: configuration files are located in /etc/nginx/
Place your website files in the appropriate location on the server. By default, Apache’s website files are located in /var/www/html/, and Nginx’s website files are located in /usr/share/nginx/html/.
5. Set up a MySQL database, create the database and user for website use.
- To log in to the MySQL server, run the following command:
mysql -u root -p
- Create a database with the name ‘your_database_name’.
- Create a user and grant them permissions:
1. Create a user ‘your_username’ with the password ‘your_password’ for access from localhost.
2. Grant all privileges on the database ‘your_database_name’ to ‘your_username’ from localhost.
3. Flush privileges to apply the changes.
6. Place your website configuration file in the configuration folder of the Web server and make the necessary configurations.
- For Apache:
In Ubuntu: the configuration file is located in /etc/apache2/sites-available/
In CentOS: the configuration file is located in /etc/httpd/conf.d/ - For Nginx:
On Ubuntu: Configuration files are located in /etc/nginx/sites-available/
On CentOS: Configuration files are located in /etc/nginx/conf.d/
Restart the web server for the changes to take effect.
- For Apache:
On Ubuntu: use “sudo service apache2 restart”
On CentOS: use “sudo systemctl restart httpd” - For Nginx:
On Ubuntu: restart Nginx by running “sudo service nginx restart”
On CentOS: restart Nginx by running “sudo systemctl restart nginx”
Make sure that the firewall on the server allows access to the ports used by the web server. For example, Apache usually uses port 80 for HTTP, and Nginx typically uses port 80 for HTTP as well.
These are the fundamental steps to deploy your website on a Linux server, but the specific instructions may vary depending on the distribution and software versions.