How to auto-start Apache & MySQL on Ubuntu 16.04 on system startup?

9,612

By default, one does not have to initialize or start apache,php and MySQL and related modules every time the system starts. These are started automatically when Ubuntu starts.

Under normal cases the user does not have to interfere and the webserver starts automatically.


In case this is not happening, the probable causes might be :

  • apache might be incorrectly configured (most likely).
  • php configuration has error ( any syntax error will cause php loading to fail), subsequently might affect apache.
  • If MySQL connection is needed for serving a page, and this connection fails (because of MySQL not running), then apache will fail to start. Important is to start apache after MySQL. Question on serverfault

You can try to reinstall LAMP stack and immediately test with a reboot.

Share:
9,612

Related videos on Youtube

Ganesh Aher
Author by

Ganesh Aher

About me, I'm simple and love to code. I made too much mistakes while coding and learned from them. I love to hear music and play chess.

Updated on September 18, 2022

Comments

  • Ganesh Aher
    Ganesh Aher over 1 year

    I'm totally new to Ubuntu (Linux). I'm just installed Ubuntu 16.04 and install XAMPP (lampp, apache, mysql) on it. They are running well, but not started when I'm start/ restart the system.

    To start Apache every time I've to run the command :

    quleiss@quleiss:~$ sudo /opt/lampp/lampp start
    

    My question is, is there any way that it will start automatically when I'm starting my system.

    I'm googled for this but there are many solutions for how to install Apache ?, but not for how to make auto-start Apache ?.

    I referred this question : Start script on system startup (Ubuntu 16.04.1)

    After running sudo systemctl status apache2 command it will give this output :

    apache2.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

    Any kind of help is appreciated, Thanks in advance.

    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
      Was there a requirement for the lampp stack provided by a 3rd party, rather than the standard apt-get install method? Just curious is all. If there was no specific requirement, then the standard is apt-get.
    • Ganesh Aher
      Ganesh Aher about 7 years
      Sorry I didn't get you. Please explain what you are suggesting. I'm totally new to Linux(Ubuntu).
    • George Udosen
      George Udosen about 7 years
      Please run: sudo systemctl status apache2 from the terminal and let me know what response you get, post into your question...
    • Ganesh Aher
      Ganesh Aher about 7 years
      After running sudo systemctl status apache2 command it will give this output : apache2.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
      @ganesh - you've used a non standard method to install Apache/Mysql. LAMP is an acronym for Linux/Apache/MySQL/PHP. Installing applications on Ubuntu, is not as convoluted as Windows. Instead of having to download apps from 3rd party sites like VLC, you install then with apt. Apache can be installed like this apt-get install apache2, etc
    • Ganesh Aher
      Ganesh Aher about 7 years
      @ThatGuy I run apt-get install apache2, and and after that I run sudo systemctl status apache2 this command and it gives me this result : apache2.service - LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: inactive (dead) since Sat 2017-02-25 11:53:22 IST; 6min ago Docs: man:systemd-sysv-generator(8)
    • Ganesh Aher
      Ganesh Aher about 7 years
      After that : Feb 25 11:53:22 quleiss apache2[21979]: (98)Address already in use: AH00072: mak Feb 25 11:53:22 quleiss apache2[21979]: (98)Address already in use: AH00072: mak Feb 25 11:53:22 quleiss apache2[21979]: no listening sockets available, shutting Feb 25 11:53:22 quleiss apache2[21979]: AH00015: Unable to open logs Feb 25 11:53:22 quleiss apache2[21979]: Action 'start' failed. Feb 25 11:53:22 quleiss apache2[21979]: The Apache error log may have
    • Ganesh Aher
      Ganesh Aher about 7 years
      more infor Feb 25 11:53:22 quleiss apache2[21979]: * Feb 25 11:53:22 quleiss apache2[22002]: * Stopping Apache httpd web server apac Feb 25 11:53:22 quleiss apache2[22002]: * Feb 25 11:53:22 quleiss systemd[1]: Started LSB: Apache2 web server.
    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
      Can you please post the output of netstat -ntlp? It sounds like your original installation of LAMPP is still running. If it is, you can run killall apache2, and it should close. Either that, or a reboot should do the trick.
    • Ganesh Aher
      Ganesh Aher about 7 years
      Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1111/dnsmasq tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 835/cupsd tcp6 0 0 :::80 :::* LISTEN 1346/apache2 tcp6 0 0 ::1:631 :::* LISTEN 835/cupsd
    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
      @GaneshAher - :::80 :::* LISTEN 1346/apache2 tells me apache is still running. Have you deleted the original LAMPP folder in /opt?
    • Ganesh Aher
      Ganesh Aher about 7 years
      No, not deleted LAMPP folder. Should I've to delete that ?
    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
    • AnotherKiwiGuy
      AnotherKiwiGuy about 7 years
      Ok, you left the chat. In that case, the official method is to install via tasksel: sudo tasksel install lamp-server, you can find the official cocumentation here
    • Ganesh Aher
      Ganesh Aher about 7 years
      the output for sudo netstat -ntlp is : Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 1254/dnsmasq tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 865/cupsd tcp6 0 0 ::1:631 :::* LISTEN 865/cupsd